v1.87.7.0 fix(redact-prepush): four paths where the hook exits 0 on a real credential

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>
This commit is contained in:
Lubos Buracinsky
2026-09-22 16:14:14 +02:00
co-authored by Claude Opus 5
parent 35dd014c58
commit 11734707df
6 changed files with 715 additions and 49 deletions
+27
View File
@@ -0,0 +1,27 @@
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,
);
});