mirror of
https://github.com/garrytan/gstack.git
synced 2026-09-27 07:01:54 +02:00
Four paths made the pre-push credential scanner exit 0 with the secret going out anyway, and two adjacent defects in the same functions had to land with them. Range resolution: defaultRemoteBranch() asked origin regardless of the push target, so pushing to a second remote while HEAD matched origin/main resolved HEAD..HEAD and scanned nothing; and a well-shaped but absent remote sha let a guessed base's empty diff read as "nothing to scan". The probe is now scoped to the push target and a guess that scanned nothing blocks with a fetch hint. Slicing: the no-overlap argument holds for a pattern's match but not for its proximity requirement, so a label at the end of one slice and its secret at the start of the next never fired; and budgeting in raw bytes let zero-width padding decide the seam using bytes the engine strips before matching. Slices now overlap by 16 KiB and are budgeted in zero-width-stripped bytes. Adjacent: the fallback range's hardcoded SHA-1 empty-tree id does not exist in a SHA-256 repository and hard-blocked every legitimate first push there, which the remote scoping makes reachable more often; and an over-budget single line was handed to the engine whole, blocking without the content ever being read. test/redact-prepush-fail-open.sh is the gate: 26 scenarios against real repositories with synthetic credentials, PASS here and FAIL on the four rows against the scanner this branch forks from. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
28 lines
887 B
TypeScript
28 lines
887 B
TypeScript
import { describe, test, expect } from "bun:test";
|
|
import { spawnSync } from "child_process";
|
|
import * as path from "path";
|
|
|
|
const REPO_ROOT = path.resolve(import.meta.dir, "..");
|
|
const GATE_SCRIPT = path.join(REPO_ROOT, "test", "redact-prepush-fail-open.sh");
|
|
|
|
describe("pre-push fail-open regression gate", () => {
|
|
test.skipIf(!Bun.which("git") || !Bun.which("bun") || !Bun.which("python3"))(
|
|
"executes full prepush fail-open gate cleanly (exit 0)",
|
|
() => {
|
|
const r = spawnSync("bash", [GATE_SCRIPT], {
|
|
cwd: REPO_ROOT,
|
|
encoding: "utf8",
|
|
timeout: 180_000,
|
|
env: { ...process.env },
|
|
});
|
|
if (r.status !== 0) {
|
|
console.error("Gate stdout:\n", r.stdout);
|
|
console.error("Gate stderr:\n", r.stderr);
|
|
}
|
|
expect(r.status).toBe(0);
|
|
expect(r.stdout).toContain("GATE: PASS");
|
|
},
|
|
200_000,
|
|
);
|
|
});
|