Skip to content

Commit c22dd1e

Browse files
fix(local-review): scrub GITHUB_ENTERPRISE_TOKEN alias
gh honors both GH_ENTERPRISE_TOKEN and GITHUB_ENTERPRISE_TOKEN; the offline scrub list omitted the latter, so an Enterprise credential could reach the spawned reviewer. Extracts the scrub list to an exported const, adds the alias, and adds a regression test. Addresses the P1 finding on #298.
1 parent 9236497 commit c22dd1e

2 files changed

Lines changed: 31 additions & 8 deletions

File tree

‎src/commit-sweeper.ts‎

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,19 @@ function reviewCommand(args: Args): void {
387387
console.log(outputPath);
388388
}
389389

390+
// GitHub credential env vars scrubbed before the offline local-review engine runs.
391+
// Covers both gh enterprise aliases (GH_ENTERPRISE_TOKEN and GITHUB_ENTERPRISE_TOKEN),
392+
// since gh honors either; this is belt-and-suspenders with the empty GH_CONFIG_DIR set
393+
// per run.
394+
export const LOCAL_REVIEW_SCRUBBED_TOKEN_ENV: readonly string[] = [
395+
"GH_TOKEN",
396+
"GITHUB_TOKEN",
397+
"GH_ENTERPRISE_TOKEN",
398+
"GITHUB_ENTERPRISE_TOKEN",
399+
"COMMIT_SWEEPER_TARGET_GH_TOKEN",
400+
"CLAWSWEEPER_PROOF_INSPECTION_TOKEN",
401+
];
402+
390403
// Local, offline pre-PR review of a whole branch: reviews the committed range
391404
// merge-base(base, HEAD)..HEAD as a single unit, reusing the Commit Sweeper engine.
392405
// Conforms to the #253 replacement spec: clean checkout, unique run dir, no GitHub
@@ -399,13 +412,7 @@ function localReviewCommand(args: Args): void {
399412
);
400413

401414
// Spec: genuinely offline — withhold every GitHub credential from the review engine.
402-
for (const tokenVar of [
403-
"GH_TOKEN",
404-
"GITHUB_TOKEN",
405-
"GH_ENTERPRISE_TOKEN",
406-
"COMMIT_SWEEPER_TARGET_GH_TOKEN",
407-
"CLAWSWEEPER_PROOF_INSPECTION_TOKEN",
408-
]) {
415+
for (const tokenVar of LOCAL_REVIEW_SCRUBBED_TOKEN_ENV) {
409416
delete process.env[tokenVar];
410417
}
411418

‎test/local-review.test.ts‎

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { tmpdir } from "node:os";
66
import { join } from "node:path";
77
import { fileURLToPath } from "node:url";
88

9-
import { commitMetadata } from "../dist/commit-sweeper.js";
9+
import { commitMetadata, LOCAL_REVIEW_SCRUBBED_TOKEN_ENV } from "../dist/commit-sweeper.js";
1010

1111
const GIT = process.env.GIT_BIN ?? "git";
1212
const CLI = fileURLToPath(new URL("../dist/commit-sweeper.js", import.meta.url));
@@ -105,3 +105,19 @@ test("local-review reports nothing to review when HEAD has no commits beyond bas
105105
rmSync(dir, { recursive: true, force: true });
106106
}
107107
});
108+
109+
test("local-review scrubs both GitHub and GitHub Enterprise token aliases", () => {
110+
for (const v of [
111+
"GH_TOKEN",
112+
"GITHUB_TOKEN",
113+
"GH_ENTERPRISE_TOKEN",
114+
"GITHUB_ENTERPRISE_TOKEN",
115+
"COMMIT_SWEEPER_TARGET_GH_TOKEN",
116+
"CLAWSWEEPER_PROOF_INSPECTION_TOKEN",
117+
]) {
118+
assert.ok(
119+
LOCAL_REVIEW_SCRUBBED_TOKEN_ENV.includes(v),
120+
`${v} must be in the offline scrub list`,
121+
);
122+
}
123+
});

0 commit comments

Comments
 (0)