/cso reports every security finding the code supports instead of dropping most of them (GST-3588) (#4739)

/cso now reports every security finding the code supports, with a
confidence level, and keeps low-confidence ones as labeled hypotheses
instead of dropping them.

Why: on 52 real GitHub security advisories, Opus 5.5 with /cso named the
published flaw in 3 of 51 audits, against 12 of 51 for a plain audit
request (gstack-evals#443).

Nothing to do: the next `/cso` run uses it; the before-and-after rerun
on the same 52 advisories is planned separately.

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
Review-Finding: p1/specialist-batched#1 reader=red-team
Review-Finding: p1/specialist-batched#2 reader=testing
This commit is contained in:
Garry Tanandcapy-ai[bot] authored and GitHub committed 2026-11-23 12:04:59 +00:00
1 parent 8143a91809
commit af6deb996e
5 files changed
+186 -52

No files matched your search

+128
View File
@@ -0,0 +1,128 @@
// Recall regressions for /cso, from the gstack-evals#443 real-advisory run (52 GitHub
// security advisories, Opus 5.5): with /cso the audit named 3 of 51 advisories against 12
// for a plain audit, reported 0.75 findings per session against 14.8, and in 5 of 10 misses
// never opened a file the fix changed. Pinned here against the real helper: a refused start
// the skill told the model never to retry, a file list the model could not see past a cut-off
// shell result, and a report rule (enforced by the helper) that dropped every finding short of proof.
import { afterAll, beforeAll, describe, expect, test } from 'bun:test';
import * as fs from 'node:fs';
import * as os from 'node:os';
import * as path from 'node:path';
import { spawnSync } from 'node:child_process';
const ROOT = path.resolve(import.meta.dir, '..');
const launcher = path.join(ROOT, 'bin', process.platform === 'win32' ? 'gstack-cso-launcher.exe' : 'gstack-cso-launcher');
const MIB = 1024 * 1024;
const skill = () => fs.readFileSync(path.join(ROOT, 'cso/SKILL.md'), 'utf8');
let root = '';
let state = '';
beforeAll(() => {
root = fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(), 'cso-recall-')));
state = path.join(root, 'state');
fs.mkdirSync(state);
});
afterAll(() => fs.rmSync(root, { recursive: true, force: true }));
function git(repo: string, ...args: string[]): void {
const result = spawnSync('git', ['-C', repo, ...args], { encoding: 'utf8', env: { HOME: root, PATH: process.env.PATH ?? '' }, timeout: 60_000 });
if (result.status) throw new Error(result.stderr);
}
function cso(repo: string, args: string[]) {
return spawnSync(launcher, args, { cwd: repo, encoding: 'utf8', env: { HOME: root, GSTACK_HOME: state, PATH: process.env.PATH ?? '' }, timeout: 120_000, maxBuffer: 64 * MIB });
}
function findReport(dir: string, run: string, name: string): string {
for (const entry of fs.readdirSync(dir, { recursive: true }) as string[])
if (entry.endsWith(path.join(run, name))) return path.join(dir, entry);
throw new Error('no ' + name + ' for ' + run);
}
function json(stdout: string): any {
return JSON.parse(stdout.slice(stdout.indexOf('{')));
}
/** A library shaped like the eval's units: many ordinary modules, with the vulnerable parser late in the inventory. */
function library(name: string): { repo: string; files: string[] } {
const repo = path.join(root, name);
const files: Record<string, string> = { 'package.json': '{"name":"fixture-lib","version":"1.0.0","main":"src/index.js"}\n' };
for (let i = 0; i < 320; i++) files[`src/modules/m${String(i).padStart(3, '0')}.js`] = `module.exports = (x) => x + ${i};\n`;
files['src/zz-format/parse.js'] = 'module.exports = (input) => { const o = {}; for (const [k, v] of input) o[k] = v; return o; };\n';
files['src/index.js'] = "module.exports = { parse: require('./zz-format/parse') };\n";
for (const [file, body] of Object.entries(files)) {
fs.mkdirSync(path.dirname(path.join(repo, file)), { recursive: true });
fs.writeFileSync(path.join(repo, file), body);
}
git(repo, 'init', '-q');
git(repo, 'add', '-A');
git(repo, '-c', 'user.name=Fixture', '-c', 'user.email=fixture@example.test', 'commit', '-qm', 'fixture');
return { repo, files: Object.keys(files).sort() };
}
describe('/cso recall (gstack-evals#443)', () => {
test('a refused start is corrected and retried, and the source-cap correction is --paths', () => {
const text = skill();
const invariant = text.slice(text.indexOf('**One-run invariant.**'), text.indexOf('**Audited-source access invariant.**'));
expect(invariant).toContain('A refused `start` (`"ok":false`) holds no run');
expect(invariant).toContain('start again');
expect(invariant).toContain('64 MiB');
expect(invariant).toContain('--paths');
expect(invariant).toMatch(/Once a `start` returns a run ID, never call `start` again/);
expect(invariant).not.toMatch(/On failure, make one correction, then finish partial/);
});
test('the skill names a command that lists the whole inventory from real inspect output', () => {
const { repo, files } = library('inventory');
const start = cso(repo, ['start', '--repo', repo, '--offline']);
expect(start.status).toBe(0);
const run = json(start.stdout).runId as string;
const inspect = cso(repo, ['inspect', run]);
expect(inspect.status).toBe(0);
const filter = skill().match(/jq -r '([^']+)'/)?.[1];
expect(filter).toBe('.manifest.entries[].path');
const listed = (json(inspect.stdout).manifest.entries as Array<{ path: string }>).map((entry) => entry.path).sort();
expect(listed).toEqual(files);
const read = cso(repo, ['read', run, 'src/zz-format/parse.js']);
expect(read.status).toBe(0);
expect(read.stdout).toContain('o[k] = v');
expect(cso(repo, ['finish', run]).status).toBe(0);
});
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);
});
test('a daily run saves supported findings and low-confidence hypotheses, and report.md shows only the supported ones', () => {
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) => ({
title, rootCause,
location: { path: 'src/zz-format/parse.js', line: 1, symbol: 'parse' }, advisoryIds: [], severity: 'high', confidence,
confidenceRationale: 'the loop assigns every key without a guard', evidence,
attackerControl: 'entries passed to the public parse API', impact: 'a __proto__ entry sets the returned object\'s prototype, so properties the caller reads but never set come from the attacker',
scenario: 'a caller parses untrusted entries including __proto__', trace: ['index.js parse', 'parse.js loop'],
references: ['src/zz-format/parse.js:1'], recommendation: 'reject __proto__, constructor and prototype keys',
challenge: { reviewer: 'sequential challenge; independent agent unavailable', independent: false, mode: 'sequential_fallback', callers: 'public API', controls: 'none found', counterevidence: 'none', conclusion: 'holds' },
});
const submit = (evidence: string, confidence: string, title: string, rootCause: string) => {
const dir = fs.mkdtempSync(path.join(root, 'submission-'));
const file = path.join(dir, 'submission.json');
fs.writeFileSync(file, JSON.stringify({ findings: [finding(evidence, confidence, title, rootCause)] }));
return cso(repo, ['submit', run, file]);
};
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');
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'],
]);
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');
});
});