Skip to content

leaked-secrets: the streaming collector keeps about 3x each page's HTML size in memory per page, not just its findings #1552

Closed

Description

@nc9

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.run with site.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

  1. added
    bug
    size: M
    rules
    performance
    on Nov 2, 2026
  2. added theissue type on Nov 2, 2026
  3. nc9 commented on Nov 4, 2026

    @nc9
    ContributorAuthor

    Acceptance check against main 7c31d5b. The copy fix shipped in v0.0.160 (64c91a2) and the caps in v0.0.161 (91c75cb, 2440260, 276df65).

    # Criterion Result Evidence
    1 Per-page retention no longer grows with page size: 30 pages of about 4 MB, heap growth under 1 MB a page across 3 passes PASS 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. With detachSecret made 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.
    2 Findings byte-identical on the leaked-secrets fixtures PASS 64c91a2 adds a test file and edits no existing test. Main: 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.
    3 An engine-level test or benchmark exercises the streaming collector path and fails if retention returns FAIL (gap) The retention test calls buildCollectedPageSignal directly, which is what the streaming loop calls (adapter.ts around line 3705), and it does fail without the copy. But nothing in packages/audit-engine/tests drives runStreamingRules (or the loop's detachFromPage and site-budget wrapping) over secret-bearing pages and measures retention; detach-production-boundaries.test.ts checks detach counters and parsed-page retention only.
    4 The issue or PR records the caps that bound the per-page records in the cloud engine and the worst-case retained bytes on Free and paid after the fix FAIL (gap) 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.
    5 Per-site scan time within 5% on the same fixture PASS 8 pages of about 1.5 MB with nine secret-shaped values each, through 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 runStreamingRules that measures retention over a few large secret-bearing pages, or amend criterion 3 to accept the collector-entry test.

    nik

  4. nc9 commented on Nov 4, 2026

    @nc9
    ContributorAuthor

    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:

    # Criterion Result Evidence
    3 Engine-level test or benchmark of the streaming collector path that fails if retention returns FAIL (gap) Only packages/rules/tests/security/leaked-secrets-retention-1552.test.ts measures retention, and it calls buildCollectedPageSignal directly. In packages/audit-engine/tests the files that touch the collector (streaming-collector-rules-golden.test.ts, rule-timeouts-row-971-e2e.test.ts and others) check findings or timeouts, none measures heap through runStreamingRules over secret-bearing pages.
    4 Caps and worst-case retained bytes on Free and paid recorded FAIL (gap) 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 in CHANGELOG.md adds 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 runStreamingRules that measures retention over a few large secret-bearing pages, or amend criterion 3 to accept the collector-entry test.

    nik

  5. nc9 commented on Nov 4, 2026

    @nc9
    ContributorAuthor

    Acceptance check against main 26432b6 (docs e6339ec and 8a4e260, first released in v0.0.166; the copy fix 64c91a2 in v0.0.160):

    # Criterion Result Evidence
    1 Per-page retention does not grow with page size PASS (already ticked) packages/rules/tests/security/leaked-secrets-retention-1552.test.ts, 4 pass, 0 fail on main
    2 Findings byte-identical PASS (already ticked) unchanged since the earlier check; the two commits since are docs only
    3 An engine-level test or benchmark exercises the streaming collector path and fails if retention returns NOT TICKED Still no test in packages/audit-engine/tests that measures heap through runStreamingRules over 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 test
    4 Caps and worst-case retained bytes on Free and paid recorded PASS docs/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 and SITE_FINDINGS_CAP = 10_000 a 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 repo
    5 Scan time within 5% PASS (already ticked) unchanged since the earlier check

    Ran on main: leaked-secrets-retention-1552.test.ts, 4 pass, 0 fail (local bun 1.4.3).

    Left open for box 3 only.

    nik

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugperformancerulessize: M

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions