unchanged below 100,000 components; above, 413 — an SBOM is a compliance document and is never silently truncated
Zip extraction
trusted the archive
entry-count and total-bytes budget enforced on bytes actually written, partial output removed on failure
Concurrent scans
a bare tokio::spawn per trigger, no limit
SCAN_CONCURRENCY (default 2) across all tenants, for scans and PR reviews
Same target twice
two scans shared one checkout and corrupted each other
coalesced: one runs, at most one follow-up pends, further requests are dropped
Two design choices, and how they were checked
At the two forks I put the options to a structured decision model (TypeSafe Jev, via the session's MCP tool) with a neutral description and no code, as a second opinion rather than an oracle:
Bounding the full graph, which the dashboard renders whole, so pagination would break it: hard cap with a truncated flag now (0.78), community-collapsed view long-term (1.00), streaming alone does not solve it (0.06). Built the cap; the community view is a follow-up.
Per-target policy when a scan is requested while one runs: coalesce — one running, at most one pending (0.96) over queue / reject / cancel-and-restart. This is the standard CI answer: ten pushes during a long scan cost two scans and the latest code is scanned.
Details worth reviewing
Billing: only a scan that actually ran emits scan.completed; coalesced and dropped requests never do.
No stuck targets: a drop guard releases a target whose scan panics or is cancelled, so it cannot stay "running" until the agent restarts. It has its own test.
Archive budget reads at most one byte past what is left, so an entry's declared size (attacker-controlled) plays no part.
Dashboard compatibility: the graph response only gains fields; the dashboard's struct ignores unknown fields.
Uploads: next PR
Uploads are still fully buffered: the dashboard proxies them as a byte array inside a JSON server function (about 4× the file size), and the agent buffers again before writing. The fix is a streaming route through the dashboard, with the agent writing chunks to disk. It touches both services and the UI, so it gets its own review rather than riding along here.
New tests: hostile pagination (page 0, huge limit, negative limit, overflowing skip), the sort allowlist, literal search including the backtracking pattern, three zip-bomb cases (over budget and cleaned up, too many entries, exactly at the limit), and five for the scan gate (burst coalescing, independence of targets and tenants, dead holder released, disarm semantics, slot bound).
First half of #258 (MVP-0.5). Closes #62, #63, #64, #66, #67. Streamed uploads, the remaining item, follow in their own PR (see below).
## What was unbounded
| Where | Before | Now |
|---|---|---|
| `limit` / `page` on every list endpoint | honoured as given; `?limit=10000000` loaded ten million documents | clamped while deserializing (`1..=200`, page ≤ 100k), so no handler can forget |
| `sort_by` on findings (#64) | any field, including unindexed and `$`-prefixed ones | allowlist; unknown values fall back to `created_at` |
| Search `q` on findings and SBOM | sent to Mongo as a regex: `(a+)+$` backtracks catastrophically, `.*` scans everything | escaped to a literal substring, capped at 128 chars |
| CVE monitor (#62) | every SBOM entry of the tenant in one `Vec`, hourly | one repository at a time |
| Full graph (#63) | every node and edge of the repo | ≤ 10,000 edges plus the nodes they touch, with `truncated`, `total_edges`, `total_nodes` |
| Graph nodes (#63) | documented as paginated, returned everything | paginated |
| Communities (#63) | every node loaded, grouped in Rust | grouped in Mongo (`$group` + `$firstN`), exact counts, ≤ 50 names each |
| Attack chain (#66) | unbounded | ≤ 2,000 nodes, `total` is the true count |
| License summary (#67) | every entry with its vulnerability list | one aggregation, exact counts, ≤ 100 names per license |
| SBOM diff (#67) | two full SBOMs | only the three fields compared |
| SBOM export (#67) | built in memory whatever the size | unchanged below 100,000 components; above, **413** — an SBOM is a compliance document and is never silently truncated |
| Zip extraction | trusted the archive | entry-count and total-bytes budget enforced on bytes actually written, partial output removed on failure |
| Concurrent scans | a bare `tokio::spawn` per trigger, no limit | `SCAN_CONCURRENCY` (default 2) across all tenants, for scans and PR reviews |
| Same target twice | two scans shared one checkout and corrupted each other | coalesced: one runs, at most one follow-up pends, further requests are dropped |
## Two design choices, and how they were checked
At the two forks I put the options to a structured decision model (TypeSafe Jev, via the session's MCP tool) with a neutral description and no code, as a second opinion rather than an oracle:
- **Bounding the full graph**, which the dashboard renders whole, so pagination would break it: *hard cap with a truncated flag now* (0.78), *community-collapsed view long-term* (1.00), *streaming alone does not solve it* (0.06). Built the cap; the community view is a follow-up.
- **Per-target policy** when a scan is requested while one runs: *coalesce — one running, at most one pending* (0.96) over queue / reject / cancel-and-restart. This is the standard CI answer: ten pushes during a long scan cost two scans and the latest code is scanned.
## Details worth reviewing
- **Billing:** only a scan that actually ran emits `scan.completed`; coalesced and dropped requests never do.
- **No stuck targets:** a drop guard releases a target whose scan panics or is cancelled, so it cannot stay "running" until the agent restarts. It has its own test.
- **Archive budget** reads at most one byte past what is left, so an entry's declared size (attacker-controlled) plays no part.
- **Dashboard compatibility:** the graph response only gains fields; the dashboard's struct ignores unknown fields.
## Uploads: next PR
Uploads are still fully buffered: the dashboard proxies them as a byte array inside a JSON server function (about 4× the file size), and the agent buffers again before writing. The fix is a streaming route through the dashboard, with the agent writing chunks to disk. It touches both services and the UI, so it gets its own review rather than riding along here.
## Verification
- `cargo fmt --all --check`, and `cargo clippy -p compliance-core -p compliance-agent -p compliance-mcp -p werkbank-exec -p control-map -- -D warnings`, both clean.
- `cargo test --lib` → **356 + 71 + 9 + 28 pass**.
- New tests: hostile pagination (page 0, huge limit, negative limit, overflowing skip), the sort allowlist, literal search including the backtracking pattern, three zip-bomb cases (over budget and cleaned up, too many entries, exactly at the limit), and five for the scan gate (burst coalescing, independence of targets and tenants, dead holder released, disarm semantics, slot bound).
🤖 Generated with [Claude Code](https://claude.com/claude-code)
https://claude.ai/code/session_01EYKjxacrr6K88DruUmP48p
The first half of #258: everything that let a request, an upload or a burst of
work grow agent memory or disk without limit. Streamed uploads follow in a
separate PR.
Queries (#62#63#64#66#67):
- `limit` and `page` are clamped while deserializing (1..=200, page <= 100k), so
no handler can forget; `?limit=10000000` used to be honoured.
- `sort_by` is an allowlist of indexed-ish finding fields; unknown values fall
back to `created_at` instead of sorting on arbitrary or `$`-prefixed fields.
- Search terms are escaped to literals and capped at 128 chars: `(a+)+$` was a
catastrophic-backtracking regex sent straight to Mongo.
- CVE monitor (#62) walks one repository at a time instead of loading every SBOM
entry of the tenant, hourly.
- Graph (#63): the full-graph endpoint returns at most 10,000 edges plus the
nodes they touch, with `truncated`, `total_edges` and `total_nodes` so the UI
can say "showing N of M"; nodes are paginated as documented; communities are
grouped in Mongo with capped member lists and exact counts.
- Attack chain (#66) is capped at 2,000 nodes, with the true total.
- SBOM (#67): license summary is one aggregation; the diff loads only the three
fields it compares; the export stays complete — a repository over 100,000
components gets 413 rather than a silently partial SBOM.
Archives: zip extraction enforces an entry count and a total-bytes budget on
bytes actually written, not on sizes the archive declares, and removes partial
output on failure, since callers fall back to treating the file as one blob.
Scans: `SCAN_CONCURRENCY` (default 2) bounds scans and PR reviews across all
tenants, and a target is never scanned twice in parallel — a request while one
runs becomes the single pending follow-up, further ones are dropped, and only
scans that actually ran emit usage. A drop guard releases a target whose scan
panics or is cancelled, so it cannot stay "running" until the next restart.
Design choices at the two forks (graph bounding, per-target policy) were
checked against a structured second opinion; both matched the call made here.
Part of #253 · MVP-0.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EYKjxacrr6K88DruUmP48p
A second pass over every `limit`/`page`/`$regex` in the handlers found three
the first commit did not cover:
- graph symbol search sent `q` to Mongo as a raw regex and took `limit` as an
unclamped `usize` from the query string;
- the SBOM list used its own `SbomFilter` paging fields without the
deserialize-time clamp, so `?limit=10000000` still worked there;
- notifications capped `limit` at 200 but allowed it to be negative and left
`page` unbounded, so `(page - 1) * limit as u64` could wrap into an enormous
skip.
All three now use the shared clamp and `literal_regex`, and every handler
computes `skip` through one bounded helper. No raw `$regex` on caller input
remains in the agent.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EYKjxacrr6K88DruUmP48p
Follow-up commit c33f98c: a second pass over every limit/page/$regex in the handlers found three list endpoints this PR had missed. Graph symbol search used a raw regex and an unclamped usize limit, SbomFilter paged without the clamp, and notifications allowed a negative limit plus an unbounded page, which could wrap the skip. All three now use the shared clamp, literal_regex and one bounded skip helper; no raw $regex on caller input remains. Tests: 357 + 71 + 9 + 28 pass; clippy and fmt clean.
Follow-up commit c33f98c: a second pass over every limit/page/$regex in the handlers found three list endpoints this PR had missed. Graph symbol search used a raw regex and an unclamped usize limit, SbomFilter paged without the clamp, and notifications allowed a negative limit plus an unbounded page, which could wrap the skip. All three now use the shared clamp, literal_regex and one bounded skip helper; no raw $regex on caller input remains. Tests: 357 + 71 + 9 + 28 pass; clippy and fmt clean.
sharang
merged commit 55da128a3c into main2026-09-21 11:01:55 +00:00
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
First half of #258 (MVP-0.5). Closes #62, #63, #64, #66, #67. Streamed uploads, the remaining item, follow in their own PR (see below).
What was unbounded
limit/pageon every list endpoint?limit=10000000loaded ten million documents1..=200, page ≤ 100k), so no handler can forgetsort_byon findings (#64)$-prefixed onescreated_atqon findings and SBOM(a+)+$backtracks catastrophically,.*scans everythingVec, hourlytruncated,total_edges,total_nodes$group+$firstN), exact counts, ≤ 50 names eachtotalis the true counttokio::spawnper trigger, no limitSCAN_CONCURRENCY(default 2) across all tenants, for scans and PR reviewsTwo design choices, and how they were checked
At the two forks I put the options to a structured decision model (TypeSafe Jev, via the session's MCP tool) with a neutral description and no code, as a second opinion rather than an oracle:
Details worth reviewing
scan.completed; coalesced and dropped requests never do.Uploads: next PR
Uploads are still fully buffered: the dashboard proxies them as a byte array inside a JSON server function (about 4× the file size), and the agent buffers again before writing. The fix is a streaming route through the dashboard, with the agent writing chunks to disk. It touches both services and the UI, so it gets its own review rather than riding along here.
Verification
cargo fmt --all --check, andcargo clippy -p compliance-core -p compliance-agent -p compliance-mcp -p werkbank-exec -p control-map -- -D warnings, both clean.cargo test --lib→ 356 + 71 + 9 + 28 pass.🤖 Generated with Claude Code
https://claude.ai/code/session_01EYKjxacrr6K88DruUmP48p
Follow-up commit
c33f98c: a second pass over every limit/page/$regex in the handlers found three list endpoints this PR had missed. Graph symbol search used a raw regex and an unclamped usize limit, SbomFilter paged without the clamp, and notifications allowed a negative limit plus an unbounded page, which could wrap the skip. All three now use the shared clamp, literal_regex and one bounded skip helper; no raw $regex on caller input remains. Tests: 357 + 71 + 9 + 28 pass; clippy and fmt clean.