Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions docs/guide/platform/administration/security-audits.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
Expand Down
4 changes: 2 additions & 2 deletions docs/reference/cli/platform-security.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,15 @@ The `never` rule skips deploy scans, rescans, sweeps, backfill, and local checks
```sh
void platform security models [--default <id>] [--block <id,...>] [--unblock <id,...>] [--accept-provider-notice] [--plan] [--yes]
void platform security models --provider <openai|anthropic> (--key-stdin | --remove-key) [--plan] [--yes]
void platform security limits [--concurrency <n>] [--scan-timeout <minutes>] [--scan-input-tokens <n>] [--scan-usd <usd|auto>] [--plan] [--yes]
void platform security limits [--concurrency <n>] [--scan-timeout <minutes>] [--scan-input-tokens <n>] [--scan-calls <n>] [--scan-usd <usd|auto>] [--plan] [--yes]
void platform security budget [--platform-usd <n> | --platform-off] [--project-default-usd <n> | --project-caps <on|off>] [--plan] [--yes]
void platform security budget --project <project-id> (--usd <n> | --clear) [--plan] [--yes]
void platform security model <project-id> <model-id|--default> [--accept-provider-notice] [--plan] [--yes]
```

**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 <name> --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`.

Expand Down
10 changes: 7 additions & 3 deletions packages/platform/src/security-policy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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. */
Expand Down
16 changes: 15 additions & 1 deletion packages/platform/test/unit/security-policy.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down
8 changes: 6 additions & 2 deletions packages/void/src/cli/operator-security-args.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,14 @@ const commands: Array<Omit<OperatorCommand, 'group'>> = [
{
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',
},
Expand Down Expand Up @@ -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:
Expand All @@ -529,7 +533,7 @@ export function applySecurityArgs(
};
if (Object.keys(limits).length === 0) {
throw new Error(
'platform: Usage: void platform security limits [--concurrency <n>] [--scan-timeout <minutes>] [--scan-input-tokens <n>] [--scan-usd <usd|auto>].',
'platform: Usage: void platform security limits [--concurrency <n>] [--scan-timeout <minutes>] [--scan-input-tokens <n>] [--scan-calls <n>] [--scan-usd <usd|auto>].',
);
}
parsed.body = { limits };
Expand Down
15 changes: 12 additions & 3 deletions packages/void/test/unit/operator-cli.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2140,18 +2140,27 @@ 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 },
{ ok: true },
{ 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(
Expand Down
9 changes: 9 additions & 0 deletions platform/meta/design-docs/0095-security-audits.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion platform/packages/api/test/smoke-security-flow.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'],
];
Expand Down
3 changes: 2 additions & 1 deletion platform/packages/security-scanner/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`).
Expand Down
21 changes: 13 additions & 8 deletions platform/packages/security-scanner/src/runner/phases.ts
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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 & {
Expand Down Expand Up @@ -95,15 +96,19 @@ export async function runPhases(options: PhasesOptions): Promise<PhasesResult> {
? 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
Expand Down
8 changes: 7 additions & 1 deletion platform/packages/security-scanner/src/runner/task.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,16 @@ export const TASK_ENGINES = [
'codex_sdk',
] as const satisfies ReadonlyArray<EngineId>;

/** 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;
Expand Down
24 changes: 24 additions & 0 deletions platform/packages/security-scanner/test/unit/phases.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down
2 changes: 1 addition & 1 deletion platform/scripts/security-smoke-flow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ export async function runSecuritySmoke(d: SmokeDeps): Promise<number> {
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(
Expand Down
4 changes: 2 additions & 2 deletions platform/scripts/security-smoke-test.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down