Skip to content

fix(rules): redact secrets in the URLs leaked-secrets findings name #2270 - #2274

Merged
nc9 merged 2 commits into
mainfrom
boat/redact-secret-urls-2270
Nov 23, 2026
Merged

nc9 merged 2 commits into
mainfrom
boat/redact-secret-urls-2270

Conversation

@nc9

@nc9 nc9 commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Summary

security/leaked-secrets named page and script URLs verbatim, so a secret in the URL itself (/config.json?key=sk_live_..., /api/<token>/data.js) was printed in plain text next to the finding that warns about it.

Every URL the rule's result shows now goes through redactSecretsInUrl (in packages/rules/src/security/leaked-secrets.ts). This covers the item label, sourcePages, meta.occurrences (page and script), and the item ids of leaked-secrets-omitted, -unscanned and -unfetched (including held-back scripts).

How it decides what to mask:

  • Path segments, username, and each query and fragment value are percent-decoded and run through the rule's own scanContent. Each query and fragment pair is also scanned as key="value", so the generic api_key / access_token assignment patterns apply.
  • Every matched value is replaced in its raw and percent-encoded forms with prefix…suffix. The mask is first six and last four characters (first four at most for 12 or fewer), so it shows no more than the item id's existing maskSecret does.
  • A user:password@ password is always masked, and only where it sits, so a short password cannot mask matching text in the host or path.
  • URLs with no finding come back unchanged, byte for byte. Results are cached per distinct URL within a run.

Closes #2270

Acceptance criteria

  • Every URL shown in a label, message or item of the leaked-secrets checks has detected secrets masked as a short prefix and suffix, decided by the rule's own detector patterns. Evidence: leaked-secrets-url-redaction-2270.test.ts, tests "a script URL with a detected key in its query string is shown masked" (label ...config.js?key=sk_liv…5tU7&v=2), "...path segment is shown masked, in the label and the occurrences" (label and sourcePages), and "a script that could not be read is listed with the secret in its URL masked". Messages contain no URLs.
  • Tests cover a script URL with a detected key in its query string and one with a detected token in its path, and the report text contains neither secret. Evidence: the same tests assert JSON.stringify(checks) contains neither secret. They fail (3 of 5) with the redaction stubbed to identity.
  • URLs without a secret are shown unchanged. Evidence: test "a URL with no secret in it is shown unchanged" (a hashed asset with v=1.2.3 and utm_*, a numeric ?variant=, %20 path, q=hello+world).
  • Redaction applies in llm, markdown, json and html. Evidence: packages/audit-engine/tests/leaked-secrets-url-redaction-formats-2270.test.ts renders the real rule's result through renderLlm, renderMarkdown, renderJson and renderHtml (4 pass; 4 fail with the redaction stubbed).

Gates

  • packages/rules: format:check, lint, typecheck all exit 0. bun run scripts/test-suites.ts --run rules: 12720 pass, 24 todo, 0 fail.
  • packages/audit-engine: format:check, lint, typecheck all exit 0. bun run scripts/test-suites.ts --run audit-engine: 2437 pass, 3 skip, 0 fail.
  • docs/: make validate exit 0. bun scripts/changelog.ts check: OK.

Notes and residual risk

  • Public-by-design keys in a vendor script URL (for example a Maps ?key=AIza...) are masked too, since their ids are already masked.
  • A redacted sourcePages entry no longer equals the crawled page URL, so canonical folding and page-level ignore matching do not apply to that page for this item. This only affects pages whose own URL holds a detected secret.
  • Hostnames are not scanned.
  • Agent skill: no change needed (rule output shape is unchanged, only URL text is masked).
  • Docs: docs/rules/security/leaked-secrets.mdx describes the URL masking. Changelog: changelog.d/2270-leaked-secrets-url-redaction.security.md.

@nc9
nc9 marked this pull request as ready for review November 23, 2026 06:47
@nc9
nc9 merged commit a41d27f into main Nov 23, 2026
10 checks passed
@nc9
nc9 deleted the boat/redact-secret-urls-2270 branch November 23, 2026 20:03
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.

fix(rules): redact secrets that appear in the URLs named by leaked-secrets findings

1 participant