mirror of
https://github.com/garrytan/gstack.git
synced 2026-12-01 04:13:55 +01:00
/cso searches the whole repository in one call with a hard time limit (GST-3588) (#4742)
/cso can now search every file in a repository with one helper call, which stops at a hard time limit, and a daily report.md lists its low-confidence hypotheses. Why: audits that started never reached the vulnerable file because each file took its own helper call inside a 10-minute budget (gstack-evals#443). Nothing to do: the next `/cso` run uses it. Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
This commit is contained in:
1 parent
45b48f17d9
commit
a3ecfd530d
9 files changed
+254
-18
No files matched your search
@@ -64,7 +64,7 @@ describe('CSO v3 always-loaded policy', () => {
|
||||
test('sensitive helper control files stay out of the audited working tree', () => {
|
||||
const text = controller();
|
||||
for (const proof of ['Private control files', 'umask 077', 'mode-`0700`', 'mode-`0600`', 'outside the audited repository', 'remove each control file immediately']) expect(text).toContain(proof);
|
||||
for (const proof of ['Audited-source access invariant', "only with that run's `inspect`, `read`, and `history`", 'exact `path` from `inspect`', '`displayPath` is only a redacted label', 'Never use host `Read`/`Glob`/`Grep`', 'direct reads bypass']) expect(text).toContain(proof);
|
||||
for (const proof of ['Audited-source access invariant', "only with that run's `inspect`, `read`, `search`, and `history`", 'exact `path` from `inspect`', '`displayPath` is only a redacted label', 'Never use host `Read`/`Glob`/`Grep`', 'direct reads bypass']) expect(text).toContain(proof);
|
||||
for (const proof of ["copy every record's `domain` and `scope` exactly", 'a new scope leaves the planned scope unassessed', 'Only helper commands may update helper-owned records']) expect(text).toContain(proof);
|
||||
});
|
||||
|
||||
|
||||
+73
-7
@@ -84,13 +84,73 @@ describe('/cso recall (gstack-evals#443)', () => {
|
||||
expect(cso(repo, ['finish', run]).status).toBe(0);
|
||||
});
|
||||
|
||||
test('search reads every file in one call, never runs a file name, and lists what it could not search', () => {
|
||||
const repo = path.join(root, 'hostile');
|
||||
fs.mkdirSync(path.join(repo, 'src'), { recursive: true });
|
||||
const hostile = 'src/a$(touch PWNED).js';
|
||||
fs.writeFileSync(path.join(repo, hostile), 'eval(input)\n');
|
||||
fs.writeFileSync(path.join(repo, 'src/parse.js'), 'const x = 1;\neval(input)\n');
|
||||
fs.writeFileSync(path.join(repo, 'src/big.js'), 'eval(input)\n' + 'x'.repeat(MIB + 16));
|
||||
fs.writeFileSync(path.join(repo, 'src/min.js'), 'a(b,c);'.repeat(140_000) + 'eval(late)');
|
||||
fs.mkdirSync(path.join(repo, '.gstack'));
|
||||
fs.writeFileSync(path.join(repo, '.gstack/state.js'), 'eval(input)\n');
|
||||
git(repo, 'init', '-q');
|
||||
git(repo, 'add', '-A');
|
||||
git(repo, '-c', 'user.name=Fixture', '-c', 'user.email=fixture@example.test', 'commit', '-qm', 'fixture');
|
||||
const run = json(cso(repo, ['start', '--repo', repo, '--offline']).stdout).runId as string;
|
||||
expect(skill()).toContain("gstack-cso search <run> '<regex>'");
|
||||
const found = cso(repo, ['search', run, 'eval\\(']);
|
||||
expect(found.status).toBe(0);
|
||||
expect(found.stdout).toContain('src/parse.js:2:eval(input)');
|
||||
expect(found.stdout).toContain(hostile + ':1:eval(input)');
|
||||
expect(found.stdout).toMatch(/src\/min\.js:1:[a-c(),;]{100}eval\(late\)/);
|
||||
expect(found.stdout).toMatch(/1 unsearched paths .*coverage gap: src\/big\.js\]/);
|
||||
expect(found.stdout).not.toContain('.gstack/state.js');
|
||||
expect(found.stdout).toContain('1 paths the snapshot excluded or withheld have no readable copy');
|
||||
expect(found.stdout).toMatch(/1 paths have lines over 4096 characters.*: src\/min\.js\]/);
|
||||
expect(fs.existsSync(path.join(root, 'PWNED'))).toBe(false);
|
||||
expect(fs.existsSync(path.join(repo, 'PWNED'))).toBe(false);
|
||||
const none = cso(repo, ['search', run, 'zzz-no-such-text']).stdout;
|
||||
expect(none).toContain('[gstack-cso search: no matches]');
|
||||
expect(none).toMatch(/1 unsearched paths .*src\/big\.js/);
|
||||
const bad = cso(repo, ['search', run, '(']);
|
||||
expect(bad.status).not.toBe(0);
|
||||
expect(bad.stderr).toContain('not a valid regular expression');
|
||||
expect(cso(repo, ['search', run, 'x', '--seconds', '61']).stderr).toContain('--seconds must be a whole number from 1 to 60');
|
||||
expect(cso(repo, ['finish', run]).status).toBe(0);
|
||||
});
|
||||
|
||||
test('search stays fast on a one-line 1 MiB file and stops a runaway pattern at its time limit with the hits found so far', () => {
|
||||
const repo = path.join(root, 'minified');
|
||||
fs.mkdirSync(path.join(repo, 'src'), { recursive: true });
|
||||
fs.writeFileSync(path.join(repo, 'src/a.js'), 'eval(first)\n');
|
||||
fs.writeFileSync(path.join(repo, 'src/b.min.js'), 'eval(second)\n' + 'x'.repeat(MIB - 64));
|
||||
git(repo, 'init', '-q');
|
||||
git(repo, 'add', '-A');
|
||||
git(repo, '-c', 'user.name=Fixture', '-c', 'user.email=fixture@example.test', 'commit', '-qm', 'fixture');
|
||||
const run = json(cso(repo, ['start', '--repo', repo, '--offline']).stdout).runId as string;
|
||||
let started = Date.now();
|
||||
const quadratic = cso(repo, ['search', run, '.*password']);
|
||||
expect(quadratic.status).toBe(0);
|
||||
expect(quadratic.stdout).toContain('[gstack-cso search: no matches]');
|
||||
expect(Date.now() - started).toBeLessThan(30_000);
|
||||
started = Date.now();
|
||||
const runaway = cso(repo, ['search', run, '(x+x+)+y|eval\\((first|second)', '--seconds', '2']);
|
||||
expect(runaway.status).toBe(0);
|
||||
expect(runaway.stdout).toContain('src/a.js:1:eval(first)');
|
||||
expect(runaway.stdout).toContain('src/b.min.js:1:eval(second)');
|
||||
expect(runaway.stdout).toMatch(/stopped at the 2-second limit; 1 paths not searched, a coverage gap: src\/b\.min\.js/);
|
||||
expect(Date.now() - started).toBeLessThan(20_000);
|
||||
expect(cso(repo, ['finish', run]).status).toBe(0);
|
||||
}, 90_000);
|
||||
|
||||
test('the report rule keeps every supported finding and lists hypotheses instead of dropping them', () => {
|
||||
const text = skill();
|
||||
for (const dropped of ['Daily reports hold only', 'Omit daily candidates', 'Prioritize unresolved high impact', 'demonstrated in-scope impact']) expect(text).not.toContain(dropped);
|
||||
for (const kept of ['jq -r .runId', 'Report every finding the code supports', 'never omission', 'Hypotheses (unconfirmed)', 'even with callers outside the snapshot', 'Drop one only when code you read disproves it', 'Never narrow by file name']) expect(text).toContain(kept);
|
||||
for (const kept of ['jq -r .runId', "sed -n '1,500p'", 'gstack-cso search', 'Report every finding the code supports', 'never omission', 'Hypotheses (unconfirmed)', 'even with callers outside the snapshot', 'Drop one only when code you read disproves it', 'Never narrow by file name']) expect(text).toContain(kept);
|
||||
});
|
||||
|
||||
test('a daily run saves supported findings and low-confidence hypotheses, and report.md shows only the supported ones', () => {
|
||||
test('a daily run saves supported findings and low-confidence hypotheses, and report.md lists them in separate sections', () => {
|
||||
const { repo } = library('report');
|
||||
const run = json(cso(repo, ['start', '--repo', repo, '--offline']).stdout).runId as string;
|
||||
const finding = (evidence: string, confidence: string, title: string, rootCause: string) => ({
|
||||
@@ -111,18 +171,24 @@ describe('/cso recall (gstack-evals#443)', () => {
|
||||
const supported = submit('supported', 'medium', 'Prototype injection in parse', 'parse copies attacker keys onto a plain object');
|
||||
expect(supported.status).toBe(0);
|
||||
expect(json(supported.stdout).findings).toBe(1);
|
||||
const hypothesis = submit('hypothesis', 'low', 'Prototype injection through caller-named keys', 'parse copies keys named by the caller');
|
||||
const hypothesis = submit('hypothesis', 'low', "Prototype injection through caller-named keys $' and $&", 'parse copies keys named by the caller');
|
||||
expect(hypothesis.status).toBe(0);
|
||||
expect(json(hypothesis.stdout).findings).toBe(2);
|
||||
expect(cso(repo, ['finish', run]).status).toBe(0);
|
||||
const saved = json(fs.readFileSync(findReport(state, run, 'report.json'), 'utf8')).findings as Array<{ title: string; evidence: string; confidence: string }>;
|
||||
expect(saved.map((f) => [f.title, f.evidence, f.confidence]).sort()).toEqual([
|
||||
['Prototype injection in parse', 'supported', 'medium'],
|
||||
['Prototype injection through caller-named keys', 'hypothesis', 'low'],
|
||||
["Prototype injection through caller-named keys $' and $&", 'hypothesis', 'low'],
|
||||
]);
|
||||
const report = fs.readFileSync(findReport(state, run, 'report.md'), 'utf8');
|
||||
expect(report).toContain('Supported findings:');
|
||||
expect(report).toContain('Prototype injection in parse');
|
||||
expect(report).not.toContain('caller-named keys');
|
||||
const supportedSection = report.slice(report.indexOf('Supported findings:'), report.indexOf('Hypotheses (unconfirmed):'));
|
||||
const hypotheses = report.slice(report.indexOf('Hypotheses (unconfirmed):'), report.indexOf('Snapshot transformations:'));
|
||||
expect(report.indexOf('Hypotheses (unconfirmed):')).toBeGreaterThan(report.indexOf('Supported findings:'));
|
||||
expect(supportedSection).toContain('Prototype injection in parse');
|
||||
expect(supportedSection).not.toContain('caller-named keys');
|
||||
expect(hypotheses).toContain('Prototype injection through caller-named keys');
|
||||
expect(hypotheses).not.toContain('Prototype injection in parse');
|
||||
expect(hypotheses).toContain('$&');
|
||||
expect(report.split('Snapshot transformations:').length).toBe(2);
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user