Repository navigation
Description
What happens
When the streaming engine scans a page for leaked secrets, it keeps most of that page in memory until the site rule runs. This happens in the page-time collector (scanPageForSecrets, #1021). Parsing alone keeps nothing. The page's findings are tiny, but they keep the page's text alive.
That means memory grows with the size of every crawled HTML page, not with the number of findings. A large audit of heavy pages can run out of memory on the cloud worker.
Evidence
Measured offline on Boat, against crawl data already stored from an earlier corpus run (nothing was fetched). Each run was one process on one engine, comparing v0.0.157 with v0.0.159. A full GC ran after each pass.
Site A: 30 HTML pages, 112 MB in total. Pages have a median of 4.4 MB (largest 4.8 MB), and 26 of the 30 are over 1 MB. There are no stored scripts. Each pass reads all 30 pages:
| Mode | after pass 1 | pass 2 | pass 3 |
|---|---|---|---|
| parse only | heap 26 MB | 26 MB | 26 MB |
parse + scanPageForSecrets, results kept as the collector keeps them |
heap ~417 MB | ~820 MB | ~1,177 MB |
- Per-page cost: about 13 MB of heap is kept per page of about 4.4 MB, and v0.0.157 and v0.0.159 are identical. This is not a recent regression.
- What is kept: those 30 pages produce 262 raw secret records (4 findings after dedupe). All of their string fields together come to about 40 K characters. The kept memory is several hundred times larger than the findings themselves.
- Hypothesis to check: the record strings (
value,extra, and so on) are slices of the full serialized page or inline-script text, and in JSC a slice can keep its whole parent string alive. Unconfirmed. - One pass, the way the engine runs it: peak RSS is about 0.8 to 0.9 GB for site A. Site B (30 pages of about 1.5 MB, plus 102 small scripts) peaks at about 0.3 GB.
Why it matters
Cloud worker memory is 4 GiB on Free (AgentSandbox, standard-1) and 12 GiB on paid (AgentSandboxPaid, standard-4). The plan ceilings are 500 pages on Free and 2,000 on Pro. The crawler accepts pages up to 10 MB. At about 13 MB kept per 4.4 MB page:
- 250 pages like site A would keep about 3.2 GB for this rule alone, close to the Free worker's limit.
- 2,000 such pages would need about 26 GB, far over the paid worker's limit.
Before changing anything
Check the caps first. Confirm which limits actually bound the collected per-page records in the cloud engine: pages per audit, bytes per page, and any cap on collected signals. Then measure retention through the real engine path, not just the rule function in isolation.
Acceptance Criteria
- The memory the collector keeps per page for leaked-secrets no longer grows with page size. On a fixture of 30 pages of about 4 MB each, the heap after a full GC grows by under 1 MB per page across 3 passes. Today the growth is about 13 MB per page.
- Findings are byte-identical before and after on the leaked-secrets fixtures and the existing tests: same ids, masked values, locations and counts.
- An engine-level test or benchmark exercises the streaming collector path, not only
leakedSecretsRule.runwithsite.pages, and fails if the per-page retention returns. - The issue or PR records which caps bound the collected per-page records in the cloud engine (pages per audit, bytes per page, any signal cap) and the worst-case retained bytes on Free and paid after the fix.
- Per-site scan time for leaked-secrets changes by no more than 5% on the same fixture.
Activity
fix(rules): leaked-secrets findings hold copies of their strings, not…
nc9 commentedon Nov 4, 2026
Acceptance check against main 7c31d5b. The copy fix shipped in v0.0.160 (64c91a2) and the caps in v0.0.161 (91c75cb, 2440260, 276df65).
packages/rules/tests/security/leaked-secrets-retention-1552.test.ts(4 pass) uses 12 pages of 2 MB, so I re-ran its fixture and bound at 30 pages of 4 MB: it passes. WithdetachSecretmade a no-op the committed test fails (growth 45.5 MB and 52.0 MB against a 12 MB bound), so it does pin the copy.leaked-secrets.test.ts(root and security, 0 fail), critical, precision, providers, samples, sample-data, location, public-tier, public-clients, bearer-header and cap-1554 files all pass. "the same values, locations, offsets and extras as before" pins repeat-scan equality.buildCollectedPageSignaldirectly, which is what the streaming loop calls (adapter.tsaround line 3705), and it does fail without the copy. But nothing inpackages/audit-engine/testsdrivesrunStreamingRules(or the loop'sdetachFromPageand site-budget wrapping) over secret-bearing pages and measures retention;detach-production-boundaries.test.tschecks detach counters and parsed-page retention only.docs/rules/security/leaked-secrets.mdx"Memory kept for a crawl" and the page-cap section now give the caps (1,000 findings a page or script, 10,000 distinct findings a site) and 300 to 850 bytes a finding, but no worst-case retained total, and nothing ties it to the plan ceilings (500 pages Free, 2,000 paid) or the 10 MB page cap. The PR text for the copy fix gave a pre-cap worst case ("about 60 MB for one page, not bounded by this change"), which later changes superseded.buildCollectedPageSignal, medians of 9 runs, three alternating runs each: tree before 64c91a2 166, 156, 159 ms; main 164, 165, 172 ms (about +4 to 5%, so near the limit). The docs already say a page holding one huge value can add up to about 27%.Ticked 1, 2 and 5; left open for 3 and 4. To close: state the worst-case retained bytes after the caps (for example 10,000 findings at up to 850 bytes, plus the other collected signal fields) for Free and paid in the docs or the changelog, and add an audit-engine test through
runStreamingRulesthat measures retention over a few large secret-bearing pages, or amend criterion 3 to accept the collector-entry test.nik
nc9 commentedon Nov 4, 2026
Re-check against main 8d22fa2 (the earlier check was at 7c31d5b). Criteria 1, 2 and 5 stay ticked. Criteria 3 and 4 are still open:
packages/rules/tests/security/leaked-secrets-retention-1552.test.tsmeasures retention, and it callsbuildCollectedPageSignaldirectly. Inpackages/audit-engine/teststhe files that touch the collector (streaming-collector-rules-golden.test.ts,rule-timeouts-row-971-e2e.test.tsand others) check findings or timeouts, none measures heap throughrunStreamingRulesover secret-bearing pages.docs/rules/security/leaked-secrets.mdx"Memory kept for a crawl" and the page-cap section give the caps (1,000 findings a page, 10,000 a site) and 300 to 850 bytes a finding, but no worst-case retained total for the Free and paid workers, and no link to the plan page ceilings or the 10 MB page limit. Nothing inCHANGELOG.mdadds it.Nothing touching these gaps landed between the two checks. To close: add the worst-case retained bytes after the caps (for example 10,000 findings at up to 850 bytes, plus the other collected signal fields) per plan to the docs, and add an audit-engine test through
runStreamingRulesthat measures retention over a few large secret-bearing pages, or amend criterion 3 to accept the collector-entry test.nik
docs(leaked-secrets): worst-case retained bytes of the collector's re…
docs(leaked-secrets): the retained-memory figures are estimates for o…
docs(leaked-secrets): worst-case retained bytes of the collector's re…
docs(leaked-secrets): the retained-memory figures are estimates for o…
nc9 commentedon Nov 4, 2026
Acceptance check against main 26432b6 (docs e6339ec and 8a4e260, first released in v0.0.166; the copy fix 64c91a2 in v0.0.160):
packages/rules/tests/security/leaked-secrets-retention-1552.test.ts, 4 pass, 0 fail on mainpackages/audit-engine/teststhat measures heap throughrunStreamingRulesover secret-bearing pages. The files that measure retention (memory-harness.test.ts,helpers/retention.ts,helpers/residency-probe.ts,detach-production-boundaries.test.ts) never mention the leaked-secrets collector, and the files that do touch it (streaming-collector-rules-golden.test.ts,rule-timeouts-row-971-e2e.test.ts) check findings or timeouts. The collector-entry test (buildCollectedPageSignal) does fail when the copy is removed, but it is not the engine path. A test through the engine that can fail for this reason has not been written (an attempt passed even with the fix removed, so it was dropped rather than kept as a test that cannot fail). Left unticked; the options are a harness that makes the engine path sensitive to the retention, or amending the item to accept the collector-entry testdocs/rules/security/leaked-secrets.mdx, "A page that is full of findings..." and "Memory kept for a crawl": caps are 1,000 findings a page or script andSITE_FINDINGS_CAP = 10_000a site (packages/rules/src/security/leaked-secrets.ts), about 300 to 850 bytes a finding, and the derived retained totals are about 36 MB at 500 pages (Free, 4 GiB worker) and about 52 MB at 2,000 pages (paid, 12 GiB worker), from the site cap plus about 11 KB a page; the arithmetic checks out. The text labels them as estimates, not measured on a cloud worker, valid for ordinary value lengths, and says the stored value text is not length-capped, so a page of huge values can exceed them (tracked in #1592). The plan ceilings (500 and 2,000 pages) are quoted from the issue and could not be checked from this repoRan on main:
leaked-secrets-retention-1552.test.ts, 4 pass, 0 fail (local bun 1.4.3).Left open for box 3 only.
nik
test(rules): engine-path residency probe for the leaked-secrets colle…