/cso finish no longer closes an audit after a refused submit (GST-3504) (#4692)

When the /cso helper refuses a submission, `finish` now keeps the audit
open and asks for a corrected submit, instead of closing it and losing
the evidence.

Why: an eval session hit `exclusions must be an array`, ran `finish` in
the same command, and its corrected resubmit was then refused because
the audit had closed.

Nothing to do for users; `finish` still closes the audit once the audit
deadline passes.

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
This commit is contained in:
Garry Tanandcapy-ai[bot] authored and GitHub committed 2026-11-22 11:13:13 +00:00
1 parent 296b252a34
commit 5b88fa8a00
3 files changed
+49 -1

No files matched your search

@@ -0,0 +1 @@
**/cso keeps an audit open after a refused submit.** If the helper refused a submission (for example `exclusions must be an array`), `finish` used to close the audit anyway, and the corrected resubmit was then refused because the audit was no longer running, so the evidence was lost. Now `finish` says the last submit was refused and asks for a corrected one; it closes without that evidence only once the audit deadline has passed, and records the refused submission as a gap.
+36 -1
View File
@@ -1388,10 +1388,34 @@ function requireReportingTime(report: RunReportV3): void {
if (Date.now() >= Date.parse(report.deadline))
throw new CsoError('DEADLINE', 'Audit deadline reached; no further evidence can be accepted');
}
const REFUSED_SUBMISSION = 'submission-refused.json';
function submit(args: string[]) {
const { dir } = run(args);
if (args.length !== 1) throw new CsoError('INVALID_ARGUMENT', 'submit requires one JSON file');
const rawInput = object(readInput(args[0]), 'submission');
try {
return acceptSubmission(dir, args[0]);
} catch (error) {
if (error instanceof CsoError) recordRefusedSubmission(dir, error);
throw error;
}
}
function recordRefusedSubmission(dir: string, error: CsoError): void {
try {
withLock(dir, () => {
const report = loadReport(dir);
if (report.status === 'running' && Date.now() < Date.parse(report.deadline))
writeHelperJson(join(dir, REFUSED_SUBMISSION), {
at: new Date().toISOString(),
code: error.code,
message: error.message,
});
});
} catch {
return;
}
}
function acceptSubmission(dir: string, file: string) {
const rawInput = object(readInput(file), 'submission');
rejectUnexpected(
rawInput,
['application', 'findings', 'coverage', 'gaps', 'modelUsage', 'recheck'],
@@ -1503,6 +1527,7 @@ function submit(args: string[]) {
// leaves closure evidence behind.
saveReport(dir, report);
if (recheckClaim) writeHelperJson(join(dir, 'recheck-claim.json'), recheckClaim);
fs.rmSync(join(dir, REFUSED_SUBMISSION), { force: true });
return { runId: report.runId, findings: report.findings.length, completeness: report.completeness };
});
}
@@ -1513,6 +1538,16 @@ function finish(args: string[]) {
const report = loadReport(dir),
manifest = readSnapshotManifest(dir);
assertSnapshot(dir, manifest);
const refused = join(dir, REFUSED_SUBMISSION);
if (report.status === 'running' && fs.existsSync(refused)) {
const { message } = readJson(refused);
if (Date.now() < Date.parse(report.deadline))
throw new CsoError(
'PREREQUISITE',
`The last submit was refused (${message}); correct it and submit again. finish closes the audit without that evidence only after the audit deadline (${report.deadline}).`,
);
report.gaps.push(`A refused submission was never resubmitted: ${message}`);
}
reclaimDeadAttemptScratch(dir);
for (const c of report.coverage)
if (
+12
View File
@@ -81,6 +81,18 @@ describe('compiled CSO command workflow',()=>{
report.deadline=new Date(Date.now()-1_000).toISOString();fs.writeFileSync(reportPath,JSON.stringify({...JSON.parse(fs.readFileSync(reportPath,'utf8')),deadline:report.deadline},null,2)+'\n');
const refused=command(['submit',run.runId,input]);expect(refused.status).not.toBe(0);expect(refused.stderr).toContain('DEADLINE');expect(refused.stdout).toBe('');
});
test('a refused submit keeps the audit open: finish refuses until a corrected submit lands, and closes over it only after the audit deadline',()=>{
const reportOf=(run:any)=>path.join(state,'security','cso',run.repoId,run.runId,'report.json'),coverage={domain:'auth',scope:'src/users.ts',status:'not_assessed',method:'source review',gaps:['tenant checks not traced'],evidence:[]},bad=path.join(root,'refused-submit.json'),good=path.join(root,'corrected-submit.json');
fs.writeFileSync(bad,JSON.stringify({coverage:[{...coverage,exclusions:'none'}]}));fs.writeFileSync(good,JSON.stringify({coverage:[{...coverage,exclusions:[]}]}));
const started=command(['start','--repo',repo,'--scope','auth','--offline','--budget','600']);expect(started.status).toBe(0);const run=JSON.parse(started.stdout);
const refused=command(['submit',run.runId,bad]);expect(refused.status).not.toBe(0);expect(refused.stderr).toContain('exclusions must be an array');
const blocked=command(['finish',run.runId]);expect(blocked.status).not.toBe(0);expect(blocked.stderr).toContain('last submit was refused');expect(blocked.stderr).toContain('exclusions must be an array');expect(JSON.parse(fs.readFileSync(reportOf(run),'utf8')).status).toBe('running');
const inspected=command(['inspect',run.runId]);expect(inspected.status).toBe(0);const remaining=JSON.parse(inspected.stdout).remainingSeconds;expect(Number.isSafeInteger(remaining)).toBe(true);expect(remaining).toBeGreaterThan(0);expect(remaining).toBeLessThanOrEqual(run.remainingSeconds);
const corrected=command(['submit',run.runId,good]);expect(corrected.status).toBe(0);const finished=command(['finish',run.runId]);expect(finished.status).toBe(0);expect(JSON.parse(finished.stdout).status).toBe('finished');
const late=JSON.parse(command(['start','--repo',repo,'--scope','auth','--offline','--budget','600']).stdout);expect(command(['submit',late.runId,bad]).status).not.toBe(0);
fs.writeFileSync(reportOf(late),JSON.stringify({...JSON.parse(fs.readFileSync(reportOf(late),'utf8')),deadline:new Date(Date.now()-1_000).toISOString()},null,2)+'\n');
const closed=command(['finish',late.runId]);expect(closed.status).toBe(0);expect(JSON.parse(closed.stdout).status).toBe('finished');expect(JSON.parse(fs.readFileSync(reportOf(late),'utf8')).gaps).toContain('A refused submission was never resubmitted: exclusions must be an array');
});
test('wallet-shaped helper finding IDs survive submit, review, and verification admission',()=>{const started=command(['start','--repo',repo,'--comprehensive','--offline']);expect(started.status).toBe(0);const run=JSON.parse(started.stdout),base:any={title:'Wallet-shaped helper ID',rootCause:'Tenant query omits caller tenant predicate 0',location:{path:'src/users.ts',line:1,symbol:'tenantQuery'},advisoryIds:[],severity:'high',confidence:'high',confidenceRationale:'Caller-to-sink trace directly establishes the missing predicate',evidence:'supported',attackerControl:'Tenant chooses the record ID',impact:'Cross-tenant record disclosure',scenario:'A tenant requests another tenant record by ID',trace:['route','tenantQuery','database'],references:['src/users.ts:1'],recommendation:'Bind the query to the authenticated tenant',challenge:{reviewer:'reviewer-session',independent:true,mode:'independent_agent',callers:'route caller checked',controls:'authentication lacks authorization',counterevidence:'none found',conclusion:'tenant predicate is absent'}};let helperId='';for(let i=0;i<10_000;i++){base.rootCause=`Tenant query omits caller tenant predicate ${i}`;helperId=fingerprint(base);if(redact(helperId)!==helperId)break;}expect(redact(helperId)).not.toBe(helperId);const input=path.join(root,`wallet-id-${run.runId}.json`);fs.writeFileSync(input,JSON.stringify({findings:[base]}));expect(command(['submit',run.runId,input]).status).toBe(0);const reportPath=path.join(state,'security','cso',run.repoId,run.runId,'report.json'),stored=JSON.parse(fs.readFileSync(reportPath,'utf8'));expect(stored.findings[0].id).toBe(helperId);const before=fs.readFileSync(path.join(repo,'src','users.ts'),'utf8'),request:any={findingId:helperId,runtimeProfile:'node-v1',port:3456,start:{executable:'/usr/local/bin/node',args:['src/users.ts']},legitimate:[{name:'control',path:'/health',method:'GET',expected:{status:200}}],security:{name:'tenant boundary',path:'/users/other',method:'GET',expected:{status:403},vulnerable:{status:200}},existingTests:[{executable:'/usr/local/bin/node',args:['--test']}],testFiles:['src/control.test.ts'],fixtures:{},boundaryFiles:['src/users.ts'],changes:[{path:'src/users.ts',beforeSha256:sha256(before),after:before+'// tenant predicate\n',effect:'source'}],review:{reviewer:'reviewer-session',independent:true,rootCauseRepaired:true,featurePreserved:true,boundaryMocks:false,rationale:'The tenant predicate is added while the control remains intact',reviewedPatchHash:''}};request.review.reviewedPatchHash=patchHash(request);fs.writeFileSync(input,JSON.stringify(request));const reviewed=command(['record-review',run.runId,input,'--producer','producer-session']);expect(reviewed.status).toBe(0);request.review.artifactId=JSON.parse(reviewed.stdout).reviewArtifactId;fs.writeFileSync(input,JSON.stringify(request));const verified=command(['verify',run.runId,input]);expect(verified.status).not.toBe(0);expect(verified.stderr).toContain('PREREQUISITE');expect(verified.stderr).not.toContain('REDACTION_FAILED');const review=JSON.parse(fs.readFileSync(path.join(path.dirname(reportPath),'reviews',`${request.review.artifactId}.json`),'utf8'));expect(review.findingId).toBe(helperId);});
test('daily find, early submit, and finish persist a truthful report without changing source',()=>{const before=git('status','--porcelain=v1','-z'),started=command(['start','--repo',repo,'--scope','auth','--offline']);expect(started.status).toBe(0);const run=JSON.parse(started.stdout),runId=run.runId;expect(run.completeness).toBe('not assessed');const reportPath=path.join(state,'security','cso',run.repoId,runId,'report.json');expect(fs.existsSync(reportPath)).toBe(true);const current=JSON.parse(fs.readFileSync(reportPath,'utf8'));
const wallet='0x1234567890abcdef1234567890abcdef12345678',submission={application:{actors:['authenticated tenant user'],assets:['tenant records'],entrypoints:['GET /users/:id'],tenantBoundaries:['record.tenant_id equals session.tenant_id'],sensitiveOperations:['read tenant record'],invariants:['a tenant cannot read another tenant record']},findings:[{title:'Cross-tenant user read',rootCause:`Tenant query ${wallet} omits caller tenant predicate`,location:{path:'src/users.ts',line:1,symbol:'tenantQuery'},advisoryIds:[],severity:'high',confidence:'high',confidenceRationale:'The captured caller-to-sink trace and control review directly support the finding',evidence:'supported',attackerControl:'Authenticated caller chooses the record ID',impact:'Another tenant record is returned',scenario:'A tenant supplies a known record ID owned by another tenant and receives that record',trace:['GET /users/:id','tenantQuery','findUnique by id'],references:['src/users.ts:1','OWASP API1:2023'],recommendation:'Bind the lookup predicate to the authenticated tenant identifier before returning the record',challenge:{reviewer:'independent-2',independent:true,mode:'independent_agent',callers:'Authenticated route forwards path ID',controls:'Authentication exists; authorization predicate does not',counterevidence:'Opaque IDs reduce guessing but do not authorize',conclusion:'The caller can provide a known cross-tenant ID'}}],coverage:current.coverage.filter((c:any)=>!['snapshot-inputs','history-inputs'].includes(c.domain)).map((c:any)=>({...c,status:'assessed',method:'caller and middleware trace',gaps:[],evidence:[`${c.domain} inspected against captured source`]})),gaps:[]};const file=path.join(root,'submission.json');fs.writeFileSync(file,JSON.stringify(submission));const submitted=command(['submit',runId,file]);expect(submitted.status).toBe(0);expect(JSON.parse(fs.readFileSync(reportPath,'utf8')).findings).toHaveLength(1);const finished=command(['finish',runId]);expect(finished.status).toBe(0);const final=JSON.parse(fs.readFileSync(reportPath,'utf8'));expect(final.completeness).toBe('complete');expect(final.findings[0]).toMatchObject({reproduction:'not_attempted',repair:'not_attempted',closure:'open'});expect(final.findings[0].id).toBe(fingerprint(final.findings[0]));expect(JSON.stringify(final)).not.toContain(wallet);const markdown=fs.readFileSync(path.join(path.dirname(reportPath),'report.md'),'utf8');expect(markdown.startsWith('complete — domain:auth')).toBe(true);expect(markdown).toContain('.env: excluded: credential or execution configuration');expect(markdown).not.toContain('ghp_');expect(git('status','--porcelain=v1','-z')).toBe(before);});