Skip to content

feat(rules,engine): leaked-secrets scans comments, framework payloads, same-origin source maps and config endpoints #362 - #2259

Merged
nc9 merged 3 commits into
mainfrom
boat/leaked-secrets-sources-362
Nov 24, 2026
Merged

nc9 merged 3 commits into
mainfrom
boat/leaked-secrets-sources-362

Conversation

@nc9

@nc9 nc9 commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

Summary

security/leaked-secrets now reads the places a repository scanner cannot see. Closes #362.

  • html-comment: each HTML comment is scanned on its own; the HTML pass reads the page with comment text blanked (same length, so no offset moves), so a value in a comment reports once, at html-comment. serializeChildren gained comment replacement for this.
  • framework-payload: an inline script that is Next.js __NEXT_DATA__, Nuxt __NUXT__ / __NUXT_DATA__, Remix __remixContext or SvelteKit __sveltekit_* / data-sveltekit-fetched reports at framework-payload. The item label names the framework and the loader to fix, and meta.framework carries the name. These count as browser-served, so a server-only key there is critical (as it was at inline-script).
  • source-map / config-endpoint: a new engine step (packages/audit-engine/src/secret-sources.ts) runs after the script fetch. A pure planner in the rules package (security/secrets/sources.ts) picks same-origin source maps (the SourceMap / X-SourceMap header, else the sourceMappingURL comment) and same-origin config literals (/config.json, /env.js, *-config.json, /api/config, /.well-known/...). The bodies reach the rule as site.secretSources. A map's sourcesContent is scanned at source-map (<map url>), skipping node_modules sources. A config is scanned at config-endpoint (<url>), unless the response is an HTML shell.
  • Fetch bounds: at most 10 per audit (SECRET_SOURCE_FETCH_LIMITS.MAX_FETCHES), the two kinds taken in turn. Each URL costs exactly one request: the new script-fetcher options maxRetries: 0 and followRedirects: false mean no retry and no redirect followed. The step uses the shared FetchBudget, the own-site egress policy and the script size cap. It only runs while the rule is enabled. Cross-origin URLs are never planned.

Design notes for review:

  • Same-origin means the origin of the script that names the URL, or of a page that loads it. Root-relative config literals resolve against the loading page.
  • Unread sources (404, refused, budget) are not reported and do not block the clean pass: the script that names them was scanned. Targets dropped by the cap are counted by the engine but not surfaced in the report.
  • shared/framework-payload.ts (perf rule) tallies payloads page-wide. This PR uses its own per-element classifier because the scanner labels each script it reads.

Acceptance criteria

  • A key in sourcesContent of a same-origin source map reports at source-map (<map url>): leaked-secrets-sources-362.test.ts (rules) "a key in a source map's sourcesContent reports at source-map ()". The corpus source-map context also passes for every generator.
  • A key in __NEXT_DATA__ or __NUXT__ reports at framework-payload, with the framework named in the message: rules test "framework-payload (security/leaked-secrets: scan the sources a repo scanner cannot see (source maps, config endpoints, framework payloads, comments) #362)" (Next.js, Nuxt x2, Remix, SvelteKit; the label contains "the Next.js NEXT_DATA payload", and meta.framework). The corpus next-data / nuxt-payload contexts moved to framework-payload.
  • A key in a same-origin JSON config fetched by a scanned bundle reports at config-endpoint (<url>): rules test "a key in a same-origin config reports at config-endpoint ()". The engine test "same-origin maps and configs are fetched" covers the fetch side, and the corpus config-endpoint context passes.
  • A key inside an HTML comment reports at html-comment: rules tests "a key inside an HTML comment reports at html-comment, once" and "the HTML pass no longer reads the comment's text". The corpus html-comment context moved to html-comment.
  • Source-map and config fetches respect the site's fetch budget and never exceed 10 extra requests per audit; cross-origin maps are never fetched: engine tests/leaked-secrets-sources-362.test.ts covers four cases with a local server that counts hits. (1) 40 referenced targets produce exactly 10 requests. (2) A spent FetchBudget sends nothing. (3) Cross-origin maps and configs get 0 hits on the other origin. (4) A same-origin 302 to another origin is not followed: 1 request, 0 hits there. Planner unit tests cover the cross-origin, data: and cap-of-10 cases.
  • Corpus harness gains one context per new location: contexts.ts adds source-map and config-endpoint and relabels html-comment, next-data and nuxt-payload. expected.json was regenerated: the diff is only location relabels (204 inline-script to framework-payload, 102 html to html-comment) plus 204 new rows for the two new contexts.

Gates (local; no CI dispatched)

  • packages/rules: format:check, lint, typecheck clean. bun run scripts/test-suites.ts --run rules: 12866 pass, 26 todo, 0 fail (416 files).
  • packages/audit-engine: format:check, lint, typecheck clean. bun run scripts/test-suites.ts --run audit-engine: 2423 pass, 3 skip, 0 fail (256 files).
  • packages/utils: format:check, lint, typecheck clean.
  • docs/: make validate clean (74 script tests pass). bun scripts/changelog.ts check OK.
  • New tests were mutation-checked. Removing followRedirects: false fails the redirect test. Unblanked comments would report at html. Expected values are literals (10, labels), not imported constants.

Agent skill

The squirrelscan agent skill may want to mention the four new locations when it explains leaked-secrets findings. The maintainer can file a skills issue for this.

Hold-list (security, new outbound requests): draft for planning review.

@nc9
nc9 force-pushed the boat/leaked-secrets-sources-362 branch 2 times, most recently from 40adeea to b77b07f Compare November 22, 2026 22:18
@nc9
nc9 marked this pull request as ready for review November 23, 2026 02:14
nc9 added 3 commits November 23, 2026 20:11
…, same-origin source maps and config endpoints #362

Signed-off-by: Nik Cubrilovic <[email protected]>
…es URLs with credentials #362

Signed-off-by: Nik Cubrilovic <[email protected]>
… a token never reaches a label #362

Signed-off-by: Nik Cubrilovic <[email protected]>
@nc9
nc9 force-pushed the boat/leaked-secrets-sources-362 branch from b77b07f to ec0589a Compare November 23, 2026 20:32
@nc9
nc9 merged commit b6fce17 into main Nov 24, 2026
10 checks passed
@nc9
nc9 deleted the boat/leaked-secrets-sources-362 branch November 24, 2026 02:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

security/leaked-secrets: scan the sources a repo scanner cannot see (source maps, config endpoints, framework payloads, comments)

2 participants