Stop leaking real GitHub tool paths to dispatch turns

This commit is contained in:
Meta Vens 2026-06-17 08:08:49 +01:00
commit 45dd81f968
6 changed files with 64 additions and 54 deletions

View file

@ -1,8 +1,11 @@
#!/usr/bin/env node
import { spawnSync } from "node:child_process";
import { dirname, resolve } from "node:path";
import { fileURLToPath } from "node:url";
const args = process.argv.slice(2);
const realGh = process.env.BIFROST_REAL_GH;
const wrapperDir = dirname(fileURLToPath(import.meta.url));
const realGh = process.env.BIFROST_REAL_GH || resolveExecutable("gh", wrapperDir);
const realGhArgs = splitCommandArgs(process.env.BIFROST_REAL_GH_ARGS ?? "");
const mutatingCommands = new Set([
"gist create",
@ -73,6 +76,34 @@ if (result.error) {
process.exit(result.status ?? 1);
function resolveExecutable(command, excludedDir) {
const locator = process.platform === "win32" ? "where.exe" : "which";
const result = spawnSync(locator, [command], {
cwd: excludedDir,
encoding: "utf8",
stdio: ["ignore", "pipe", "pipe"],
windowsHide: true,
});
if (result.status !== 0) {
return "";
}
const matches = `${result.stdout ?? ""}`
.split(/\r?\n/)
.map((line) => line.trim())
.filter(Boolean)
.filter((line) => !isWithinExcludedDir(line, excludedDir));
return matches[0] ?? "";
}
function isWithinExcludedDir(candidate, excludedDir) {
const normalizedCandidate = resolve(candidate).toLowerCase();
const normalizedExcludedDir = `${resolve(excludedDir).toLowerCase()}\\`;
return normalizedCandidate.startsWith(normalizedExcludedDir);
}
function isWindowsCommandScript(command) {
return /\.cmd$/i.test(command) || /\.bat$/i.test(command);
}

View file

@ -1,12 +1,6 @@
@echo off
setlocal
set "REAL_GH=%BIFROST_REAL_GH%"
if not defined REAL_GH (
echo Bifrost GitHub gate has no real GitHub CLI executable configured.>&2
exit /b 1
)
set "NODE_EXE=%BIFROST_NODE_EXECUTABLE%"
if not defined NODE_EXE (
echo Bifrost GitHub gate has no Node executable configured.>&2

View file

@ -1,8 +1,11 @@
#!/usr/bin/env node
import { spawnSync } from "node:child_process";
import { dirname, resolve } from "node:path";
import { fileURLToPath } from "node:url";
const args = process.argv.slice(2);
const realGit = process.env.BIFROST_REAL_GIT;
const wrapperDir = dirname(fileURLToPath(import.meta.url));
const realGit = process.env.BIFROST_REAL_GIT || resolveExecutable("git", wrapperDir);
if (!realGit) {
process.stderr.write("Bifrost Git gate has no real git executable configured.\n");
@ -33,6 +36,34 @@ if (result.error) {
process.exit(result.status ?? 1);
function resolveExecutable(command, excludedDir) {
const locator = process.platform === "win32" ? "where.exe" : "which";
const result = spawnSync(locator, [command], {
cwd: excludedDir,
encoding: "utf8",
stdio: ["ignore", "pipe", "pipe"],
windowsHide: true,
});
if (result.status !== 0) {
return "";
}
const matches = `${result.stdout ?? ""}`
.split(/\r?\n/)
.map((line) => line.trim())
.filter(Boolean)
.filter((line) => !isWithinExcludedDir(line, excludedDir));
return matches[0] ?? "";
}
function isWithinExcludedDir(candidate, excludedDir) {
const normalizedCandidate = resolve(candidate).toLowerCase();
const normalizedExcludedDir = `${resolve(excludedDir).toLowerCase()}\\`;
return normalizedCandidate.startsWith(normalizedExcludedDir);
}
function findGitSubcommand(input) {
const optionsWithSeparateValues = new Set([
"-C",

View file

@ -1,12 +1,6 @@
@echo off
setlocal
set "REAL_GIT=%BIFROST_REAL_GIT%"
if not defined REAL_GIT (
echo Bifrost Git gate has no real git executable configured.>&2
exit /b 1
)
set "NODE_EXE=%BIFROST_NODE_EXECUTABLE%"
if not defined NODE_EXE (
echo Bifrost Git gate has no Node executable configured.>&2