Skip to content

Commit c71c87e

Browse files
committed
fix(boundary): close the fail-open hole — nonexistent root and zero-file scans exit 2 (empty scans certify nothing), proven by battery + 2 new tests (1002/1002)
1 parent c2a8d0a commit c71c87e

3 files changed

Lines changed: 31 additions & 2 deletions

File tree

‎docs/boundary-enforcement-2026-09.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ redacted SHA-256 prefix only.
4444
a private key, `deployed: true`, `networkCall: PERFORMED`, a filled
4545
`awardSlot` — are refused, that the exclusions hold, that `git` never tracks
4646
a local env secret, and that the report is byte-deterministic.
47+
- A root that does not exist, or a scan that yields **zero in-scope files**,
48+
exits `2` — an empty scan certifies nothing and is never reported as PASS.
4749

4850
## The honest boundary of this boundary
4951

‎scripts/boundary-audit.mjs‎

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,15 @@
2424
* Usage:
2525
* node scripts/boundary-audit.mjs [--root <dir>] [--out <report.json>]
2626
*
27-
* Exit: 0 = clean, 1 = violations found (fail-closed), 2 = scanner error.
27+
* Exit: 0 = clean, 1 = violations found (fail-closed), 2 = scanner error —
28+
* a root that does not exist, or a scan that yields zero in-scope files,
29+
* exits 2: an empty scan certifies nothing and must never report PASS.
2830
* Matched content is never echoed — only paths, check ids, and a redacted
2931
* SHA-256 prefix.
3032
*/
3133

3234
import { createHash } from "node:crypto";
33-
import { readFileSync, readdirSync, statSync, writeFileSync } from "node:fs";
35+
import { existsSync, readFileSync, readdirSync, statSync, writeFileSync } from "node:fs";
3436
import { dirname, join, relative, resolve } from "node:path";
3537
import { fileURLToPath } from "node:url";
3638

@@ -129,7 +131,16 @@ function main() {
129131
const root = resolve(rootIdx >= 0 ? args[rootIdx + 1] : REPO);
130132
const outPath = outIdx >= 0 ? args[outIdx + 1] : null;
131133

134+
if (!existsSync(root) || !statSync(root).isDirectory()) {
135+
console.error(`BOUNDARY-AUDIT: ERROR root does not exist or is not a directory: ${root}`);
136+
process.exit(2);
137+
}
138+
132139
const files = walk(root);
140+
if (files.length === 0) {
141+
console.error(`BOUNDARY-AUDIT: ERROR 0 files in scan scope under ${root} — refusing to certify an empty scan (fail-closed)`);
142+
process.exit(2);
143+
}
133144
const findings = [];
134145
let scannedText = 0;
135146
let scannedJson = 0;

‎test/ci/boundary-enforcement.test.js‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,11 +82,27 @@ test("boundary: legacy-quarantine is excluded by design and reported", () => {
8282
const q = join(d, "legacy-quarantine");
8383
mkdirSync(q);
8484
writeFileSync(join(q, "legacy-broadcast.txt"), PEM);
85+
writeFileSync(join(d, "README.txt"), "in-scope clean file so the scan certifies something\n");
8586
const out = join(d, "rep.json");
8687
const r = runAudit(d, [], out);
8788
assert.equal(r.status, 0, `quarantined private-key material must be out of scan scope: ${r.stdout}${r.stderr}`);
8889
const report = JSON.parse(readFileSync(out, "utf8"));
8990
assert.ok(report.excludedDirs.includes("legacy-quarantine"));
91+
assert.ok(!r.stdout.includes("legacy-broadcast.txt"));
92+
});
93+
});
94+
95+
test("boundary: a nonexistent root is a scanner error, never a pass", () => {
96+
const r = runAudit(join(REPO, "no-such-dir-" + Date.now()));
97+
assert.equal(r.status, 2);
98+
assert.match(r.stderr + r.stdout, /does not exist or is not a directory/);
99+
});
100+
101+
test("boundary: an empty scan certifies nothing (exit 2, not PASS)", () => {
102+
withTmp((d) => {
103+
const r = runAudit(d);
104+
assert.equal(r.status, 2);
105+
assert.match(r.stderr + r.stdout, /0 files in scan scope/);
90106
});
91107
});
92108

0 commit comments

Comments
 (0)