diff --git a/docs/guide/platform/administration/security-audits.md b/docs/guide/platform/administration/security-audits.md index 74eba69bb..64da50e22 100644 --- a/docs/guide/platform/administration/security-audits.md +++ b/docs/guide/platform/administration/security-audits.md @@ -200,6 +200,12 @@ void platform security limits --scan-input-tokens 10000000 A saved input-token limit above 1.2 million no longer raises the default spend limit. For example, a DeepSeek policy with 2 million input tokens and the default output limit goes from $0.744 to $0.504. Set `--scan-usd` to keep a higher limit. +The same applies to the model-call limit and the scan timeout. An installation that turned scans on when the defaults were 80 calls and 20 minutes keeps them, so a first scan of a whole app can end as incomplete (call limit reached) or time out. Raise both to the current defaults: + +```sh +void platform security limits --scan-calls 500 --scan-timeout 60 +``` + ## Emails | Email | Sent to | diff --git a/docs/reference/cli/platform-security.md b/docs/reference/cli/platform-security.md index b1912b717..3b3ed1d11 100644 --- a/docs/reference/cli/platform-security.md +++ b/docs/reference/cli/platform-security.md @@ -43,7 +43,7 @@ The `never` rule skips deploy scans, rescans, sweeps, backfill, and local checks ```sh void platform security models [--default ] [--block ] [--unblock ] [--accept-provider-notice] [--plan] [--yes] void platform security models --provider (--key-stdin | --remove-key) [--plan] [--yes] -void platform security limits [--concurrency ] [--scan-timeout ] [--scan-input-tokens ] [--scan-usd ] [--plan] [--yes] +void platform security limits [--concurrency ] [--scan-timeout ] [--scan-input-tokens ] [--scan-calls ] [--scan-usd ] [--plan] [--yes] void platform security budget [--platform-usd | --platform-off] [--project-default-usd | --project-caps ] [--plan] [--yes] void platform security budget --project (--usd | --clear) [--plan] [--yes] void platform security model [--accept-provider-notice] [--plan] [--yes] @@ -51,7 +51,7 @@ void platform security model [--accept-provide **Models.** Accept the provider notice with `--accept-provider-notice` when choosing a third-party model. To bill your own OpenAI or Anthropic account, pipe the key from your password manager to `models --provider --key-stdin --yes`. Void saves it after a successful test call. Use `--remove-key` to switch back. See [Use your own provider key](/guide/platform/administration/security-audits#own-provider-key). -**Scan limits.** Set `--concurrency` to the number of scans the platform can run at once. Each Cloudflare model runs one scan at a time, so additional slots can serve different models. Set `--scan-timeout` in minutes. `--scan-input-tokens` caps the input tokens one scan may send, cached ones included. `--scan-usd` sets the [spend limit](/guide/platform/administration/security-audits#scan-spend-limit) of every scan; `auto` prices it from the token limits. +**Scan limits.** Set `--concurrency` to the number of scans the platform can run at once. Each Cloudflare model runs one scan at a time, so additional slots can serve different models. Set `--scan-timeout` in minutes (5 to 60, default 60). `--scan-input-tokens` caps the input tokens one scan may send, cached ones included. `--scan-calls` caps the model calls of one scan (10 to 500, default 500). `--scan-usd` sets the [spend limit](/guide/platform/administration/security-audits#scan-spend-limit) of every scan; `auto` prices it from the token limits. **Budget.** Run `void platform security budget` to see this month’s spend and caps. Use `--platform-usd` to enable a platform cap or `--project-default-usd` to enable default project caps. Turn off the default with `--project-caps off`. diff --git a/packages/platform/src/security-policy.ts b/packages/platform/src/security-policy.ts index 33e5fa956..bce21d90b 100644 --- a/packages/platform/src/security-policy.ts +++ b/packages/platform/src/security-policy.ts @@ -36,11 +36,15 @@ export type SecurityLimitRange = Readonly<{ min: number; max: number; default: n export const SECURITY_LIMIT_RANGES = { /** Running scans per installation. */ concurrency: { min: 1, max: 10, default: 2 }, - /** Wall clock per scan, the only timeout setting. */ - timeoutMinutes: { min: 5, max: 60, default: 20 }, + /** Wall clock per scan, the only timeout setting. 340 calls at about 9 s each fit in 60. */ + timeoutMinutes: { min: 5, max: 60, default: 60 }, maxInputTokens: { min: 50_000, max: 20_000_000, default: 10_000_000 }, maxOutputTokens: { min: 5000, max: 200_000, default: 120_000 }, - modelCallsPerScan: { min: 10, max: 200, default: 80 }, + /** + * Model calls per scan. Above the runner's planned worst case (40 + 10 verify x 30 = 340; + * 360 for a `standard` sweep). A retried call uses a call but not a turn. + */ + modelCallsPerScan: { min: 10, max: 500, default: 500 }, } as const; /** Allowed per-scan spend limit (`maxScanUsd`) in USD, whole cents. */ diff --git a/packages/platform/test/unit/security-policy.test.ts b/packages/platform/test/unit/security-policy.test.ts index 6d1644f66..b3656ffc8 100644 --- a/packages/platform/test/unit/security-policy.test.ts +++ b/packages/platform/test/unit/security-policy.test.ts @@ -31,7 +31,21 @@ describe('security policy', () => { budgets: { platformCapOn: false, projectCapsOn: false }, }); expect(parseSecurityPolicy(stored())).toEqual(policy); - expect(policy.limits).toMatchObject({ maxInputTokens: 10_000_000, maxScanUsd: null }); + expect(policy.limits).toMatchObject({ + timeoutMinutes: 60, + maxInputTokens: 10_000_000, + modelCallsPerScan: 500, + maxScanUsd: null, + }); + }); + + it('keeps a saved 80-call limit until an admin raises it', () => { + const row = stored({ limits: { ...defaultSecurityPolicy().limits, modelCallsPerScan: 80 } }); + expect(readSecurityPolicy(row).limits.modelCallsPerScan).toBe(80); + expect(parseSecurityLimitsPatch({ modelCallsPerScan: 500 })).toEqual({ + modelCallsPerScan: 500, + }); + expect(() => parseSecurityLimitsPatch({ modelCallsPerScan: 501 })).toThrow('modelCallsPerScan'); }); it.each([1_200_000, 2_000_000])('keeps a saved %s input-token limit', (maxInputTokens) => { diff --git a/packages/void/src/cli/operator-security-args.ts b/packages/void/src/cli/operator-security-args.ts index db4e02ded..6e0afbfb5 100644 --- a/packages/void/src/cli/operator-security-args.ts +++ b/packages/void/src/cli/operator-security-args.ts @@ -59,13 +59,14 @@ const commands: Array> = [ { action: 'limits', description: - 'Set scan limits: concurrent scans, the time one scan may run, its input tokens and its spend limit', + 'Set scan limits: concurrent scans, the time one scan may run, its input tokens, its model calls and its spend limit', path: '/security/policy', values: { concurrency: 'Scans that run at once (1 to 10)', 'scan-timeout': 'Minutes one scan may run (5 to 60)', 'scan-input-tokens': 'Input tokens one scan may send, cached ones included (50000 to 20000000)', + 'scan-calls': 'Model calls one scan may make (10 to 500)', 'scan-usd': 'Spend limit of one scan in USD (0.01 to 12), or auto to price it from the token limits', }, @@ -520,6 +521,9 @@ export function applySecurityArgs( ...(values['scan-input-tokens'] ? { maxInputTokens: wholeNumber(values['scan-input-tokens'], 'scan-input-tokens') } : {}), + ...(values['scan-calls'] + ? { modelCallsPerScan: wholeNumber(values['scan-calls'], 'scan-calls') } + : {}), ...(values['scan-usd'] ? { maxScanUsd: @@ -529,7 +533,7 @@ export function applySecurityArgs( }; if (Object.keys(limits).length === 0) { throw new Error( - 'platform: Usage: void platform security limits [--concurrency ] [--scan-timeout ] [--scan-input-tokens ] [--scan-usd ].', + 'platform: Usage: void platform security limits [--concurrency ] [--scan-timeout ] [--scan-input-tokens ] [--scan-calls ] [--scan-usd ].', ); } parsed.body = { limits }; diff --git a/packages/void/test/unit/operator-cli.test.ts b/packages/void/test/unit/operator-cli.test.ts index eb82e2f3f..6f2f8b3bd 100644 --- a/packages/void/test/unit/operator-cli.test.ts +++ b/packages/void/test/unit/operator-cli.test.ts @@ -2140,7 +2140,7 @@ describe('platform security commands', () => { ); }); - it('sets the scan input-token and spend limits, with auto for the automatic spend limit', async () => { + it('sets the scan input-token, call and spend limits, with auto for the automatic spend limit', async () => { quiet(); const calls = serve([ { dryRun: true, action: 'security.policy', target: 'platform', expectedRevision: 3 }, @@ -2148,10 +2148,19 @@ describe('platform security commands', () => { { dryRun: true, action: 'security.policy', target: 'platform', expectedRevision: 4 }, { ok: true }, ]); - await run('limits', '--scan-input-tokens', '10000000', '--scan-usd', 'auto', '--yes'); + await run( + 'limits', + '--scan-input-tokens', + '10000000', + '--scan-calls', + '500', + '--scan-usd', + 'auto', + '--yes', + ); await run('limits', '--scan-usd', '2.50', '--yes'); expect(calls.filter((call) => call.body?.dryRun).map((call) => call.body?.limits)).toEqual([ - { maxInputTokens: 10_000_000, maxScanUsd: null }, + { maxInputTokens: 10_000_000, modelCallsPerScan: 500, maxScanUsd: null }, { maxScanUsd: 2.5 }, ]); expect(() => parseOperatorArgs(['security', 'limits', '--scan-usd', 'lots'])).toThrow( diff --git a/platform/meta/design-docs/0095-security-audits.md b/platform/meta/design-docs/0095-security-audits.md index ea55d5735..7759e2c19 100644 --- a/platform/meta/design-docs/0095-security-audits.md +++ b/platform/meta/design-docs/0095-security-audits.md @@ -566,6 +566,15 @@ T2 input, 5 seeded and 3 clean apps, 8 scans per model, runner at the final code | Cost per scan at list price | median $0.74, max $1.34 | median $0.18, max $0.29 | | Wall time (bar p95 < 20 min) | p95 19.2 min | p95 15.7 min | +- Live on staging (2026-11-30), a T3 first scan of the security smoke fixture (several real + unauthenticated routes, runtime copy on) ended `call_cap` at 80 calls twice, after + confirming the planted bug. The runner plans 1 hunt + 10 verify sessions, and nothing told + it about the proxy cap. The cap is now 500 (range 10 to 500) and each verify session has + at most 30 turns, so the planned worst case (40 + 10 x 30 = 340; 360 for `standard`) fits. + Engine C does not read the turn limit, so the proxy's 40-call session limit bounds it. + Staging ran about 9.3 s per call, so the default timeout is now 60 minutes: at 20 minutes + a scan would stop near 130 calls as `timed_out`, which keeps no findings. Saved policies + keep 80 calls and 20 minutes until `limits --scan-calls 500 --scan-timeout 60` raises them. - One unreadable verify session keeps that candidate as a lead and ends the scan `incomplete`; Engine B repairs harmless output slips (`coerce.ts`) and gets one retry for a bad report. diff --git a/platform/packages/api/test/smoke-security-flow.test.ts b/platform/packages/api/test/smoke-security-flow.test.ts index 1a086410d..de589e292 100644 --- a/platform/packages/api/test/smoke-security-flow.test.ts +++ b/platform/packages/api/test/smoke-security-flow.test.ts @@ -174,7 +174,7 @@ describe('security smoke flow', () => { routes: { 'GET /projects/p1/security/scans?limit=10': () => ({ scans: [scan('running')] }) }, }); expect(await run()).toBe(1); - expect(state.now).toBe(55 * 60_000); + expect(state.now).toBe(135 * 60_000); expect(log.join('\n')).toContain('No finished deploy scan before the deadline (ss_1 running)'); expect(state.mode).toBe('disabled'); }); diff --git a/platform/packages/api/test/unit/security-model-proxy.test.ts b/platform/packages/api/test/unit/security-model-proxy.test.ts index 56eef7c7e..0509841b2 100644 --- a/platform/packages/api/test/unit/security-model-proxy.test.ts +++ b/platform/packages/api/test/unit/security-model-proxy.test.ts @@ -504,7 +504,7 @@ describe('refusals and caps before a call is sent', () => { it('stops the scan at the call, token and session caps', async () => { const cases: Array<[SecurityModelScan, string]> = [ - [scanRow({ modelCalls: 80 }), 'scan_calls'], + [scanRow({ modelCalls: 500 }), 'scan_calls'], [scanRow({ tokensIn: 10_000_000 }), 'tokens'], [scanRow({ tokensOut: 120_000 }), 'tokens'], ]; diff --git a/platform/packages/security-scanner/README.md b/platform/packages/security-scanner/README.md index 0e50023f7..0bbf0547e 100644 --- a/platform/packages/security-scanner/README.md +++ b/platform/packages/security-scanner/README.md @@ -24,7 +24,8 @@ controller ──stdin tar──► node runner.mjs --stdin-tar [--root /scan] (`void_loop` | `agent_sdk` | `codex_sdk`), `model`, `tier` (`source_diff` | `built_diff` | `full`), `changed_files` (relative to `/scan/input`), optional `limits.max_turns` (≤ 40) and `limits.max_verify` - (≤ 10). Unknown fields are ignored. + (≤ 10). A verify session gets at most 30 turns, or `max_turns` if lower. Unknown + fields are ignored. - The tar may hold only `task.json`, `input/…` and `memory/…`. Symlinks, links, devices, `..`, absolute paths and duplicates refuse the whole input (`failed`, `error_class: input_invalid`). diff --git a/platform/packages/security-scanner/src/runner/phases.ts b/platform/packages/security-scanner/src/runner/phases.ts index 642ebe1bc..59999db19 100644 --- a/platform/packages/security-scanner/src/runner/phases.ts +++ b/platform/packages/security-scanner/src/runner/phases.ts @@ -1,6 +1,6 @@ // Two profiles, the same for every engine (spec §8.1): // deploy_diff one hunt session, then one fresh verify session per candidate -// (at most `maxVerify`). +// (at most `maxVerify`, each at most `maxVerifyTurns` turns). // standard scheduled sweeps (M25): one hunt session per focus area over the // whole app, candidates merged by fingerprint, then the same verify step. // "confirmed (static)" needs both the hunt trace and a separate verify session. @@ -15,6 +15,7 @@ import { withoutRuntimeFields, withVerdictSource } from './runtime/copy.ts'; import type { CopyClient } from './runtime/copy.ts'; import { outcomeStatus } from './status.ts'; import type { StatusFields, StatusFile } from './status.ts'; +import { TASK_LIMITS } from './task.ts'; import type { ScanTask } from './task.ts'; export type PhasesResult = StatusFields & { @@ -95,15 +96,19 @@ export async function runPhases(options: PhasesOptions): Promise { ? options.copy : null; + const verifyTurns = Math.min(task.maxTurns, TASK_LIMITS.maxVerifyTurns); for (const [position, candidate] of toVerify.entries()) { const session = copy?.sessionTool() ?? null; - const outcome = await run({ - phase: 'verify', - index: firstVerifyIndex + position, - prompt: verifyPrompt(candidate, { runtime: session !== null }), - check: oneRecordAtMost, - ...(session ? { tools: [session.tool] } : {}), - }); + const outcome = await run( + { + phase: 'verify', + index: firstVerifyIndex + position, + prompt: verifyPrompt(candidate, { runtime: session !== null }), + check: oneRecordAtMost, + ...(session ? { tools: [session.tool] } : {}), + }, + verifyTurns, + ); if (outcome.kind === 'bad_output') { // One unreadable check must not cost the findings already confirmed. The candidate // stays a lead, the other candidates still get their session, and the scan ends diff --git a/platform/packages/security-scanner/src/runner/task.ts b/platform/packages/security-scanner/src/runner/task.ts index 04f391eb9..41b5fc236 100644 --- a/platform/packages/security-scanner/src/runner/task.ts +++ b/platform/packages/security-scanner/src/runner/task.ts @@ -23,10 +23,16 @@ export const TASK_ENGINES = [ 'codex_sdk', ] as const satisfies ReadonlyArray; -/** Spec §6.3: 40 turns per session, at most 10 verify sessions. */ +/** + * Spec §6.3: 40 turns per session, at most 10 verify sessions of at most 30 turns each. + * The planned worst case (40 + 10 x 30 = 340 calls; 360 for `standard`) stays under the + * default per-scan call limit (`modelCallsPerScan`, 500). Engine C does not read the turn + * limit; the proxy's 40-call session limit bounds it instead. + */ export const TASK_LIMITS = { maxTurns: 40, maxVerify: 10, + maxVerifyTurns: 30, maxTaskBytes: 1024 * 1024, maxChangedFiles: 5000, } as const; diff --git a/platform/packages/security-scanner/test/unit/phases.test.ts b/platform/packages/security-scanner/test/unit/phases.test.ts index 7277bef50..3b6ee7af0 100644 --- a/platform/packages/security-scanner/test/unit/phases.test.ts +++ b/platform/packages/security-scanner/test/unit/phases.test.ts @@ -31,6 +31,30 @@ describe('runPhases', () => { ); }); + test('a verify session gets at most 30 turns, the hunt the full session limit', async () => { + const run = async (task: ScanTask) => { + const engine = scriptedEngine([ + submitted([confirmed({ fingerprint: 'a' }), lead()]), + submitted([confirmed({ fingerprint: 'a' })]), + submitted([lead()]), + ]); + await runPhases({ engine, task, hasMemory: false }); + return engine.specs.map((spec) => [spec.phase, spec.maxTurns]); + }; + expect(await run(TASK)).toEqual([ + ['hunt', 40], + ['verify', 30], + ['verify', 30], + ]); + // A lower session limit from the task also bounds verify. + const low = parseTask({ ...BASE, tier: 'full', limits: { max_turns: 12 } }); + expect(await run(low)).toEqual([ + ['hunt', 12], + ['verify', 12], + ['verify', 12], + ]); + }); + test('a session that read no code cannot clear the scan (spike S9 B5)', async () => { for (const raws of [[], [rejected()]]) { const result = await runPhases({ diff --git a/platform/scripts/security-smoke-flow.ts b/platform/scripts/security-smoke-flow.ts index 87443e31b..eae3c7a22 100644 --- a/platform/scripts/security-smoke-flow.ts +++ b/platform/scripts/security-smoke-flow.ts @@ -280,7 +280,7 @@ export async function runSecuritySmoke(d: SmokeDeps): Promise { if (code !== 0) { throw new SmokeError(`void deploy exited with code ${code}.`); } - const waitMinutes = (before.limits?.timeoutMinutes ?? 20) * 2 + 15; + const waitMinutes = (before.limits?.timeoutMinutes ?? 60) * 2 + 15; const scan = await waitForScan(d, projectId, d.now() + waitMinutes * 60_000); if (scan.status !== 'succeeded') { throw new SmokeError( diff --git a/platform/scripts/security-smoke-test.md b/platform/scripts/security-smoke-test.md index af9adf078..6a6a13934 100644 --- a/platform/scripts/security-smoke-test.md +++ b/platform/scripts/security-smoke-test.md @@ -71,8 +71,8 @@ The public gate (`SECURITY_SMOKE_GATE`) is not covered yet. Check the gate by ha ## Time and cost The deploy takes a few minutes. Turning the mode on runs the entitlement probe, which can -take several minutes. The scan wait ends at `2 × timeoutMinutes + 15` minutes (55 minutes with -the default 20). One scan of the small fixture usually costs well under the `$5` project +take several minutes. The scan wait ends at `2 × timeoutMinutes + 15` minutes (135 minutes with +the default 60). One scan of the small fixture usually costs well under the `$5` project ceiling. ## Manual cleanup