Skip to content

feat(rules): escalate server-only secrets shipped in browser scripts to critical - #575

Merged
nc9 merged 6 commits into
mainfrom
claude/leaked-secrets-severity-j2calx
Oct 9, 2026
Merged

nc9 merged 6 commits into
mainfrom
claude/leaked-secrets-severity-j2calx

Conversation

@nc9

@nc9 nc9 commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor

Summary

security/leaked-secrets now reports a server-only secret that is read from a browser-served script (external-script or inline-script, including a base64 blob decoded from one) in a new leaked-secrets-critical check. The message says "critical" and that the secret is shipped to every visitor. The hit moves out of leaked-secrets-high or leaked-secrets-medium; it is not reported twice.

Server-only classes (by pattern name): PostgreSQL, MySQL, MongoDB and Redis connection strings, Supabase service-role and secret keys (including the service-role JWT), Stripe sk_live_, Clerk secret keys, AWS secret access keys, Azure storage keys, DigitalOcean tokens. Publishable and anon keys are publicByDesign and never escalate.

Not escalated (they keep their own tier, so nothing is hidden): DigitalOcean Spaces access key ids (the public half of the pair, matched by shape alone; public vendor ids share it, #574), values containing EXAMPLE (AWS's documented example credentials), an Azure connection string whose AccountKey is not a 64-byte base64 key, a connection string the confidence pass marks as a placeholder host or database (#589), and a database URL whose every host is loopback. A Next.js docs page inlines every code sample into a script payload, so these would otherwise read as critical.

Limits of the class model:

  • The check model has no severity tier beyond pass, warn, fail and info, so "critical" is a dedicated failing check. The severity is carried by the check name and the message text, because no reporter renders check.details. Rule-level severity stays error, and scoring treats the check like the high check.
  • NEXT_PUBLIC_ style inlined values are not a class. Patterns match on value shape, not on the variable name, so such a value escalates only when its value is one of the classes above. Expressing it would need a new key-name pass, which I left out rather than invent a larger refactor.
  • The rule has no "non-browser response" location. The html location (page markup) keeps its current severity.
  • Cloudflare tokens are left out: they are medium-confidence keyword plus bare 40-character matches.
  • AWS secret keys are medium-confidence keyed matches and now escalate in scripts, as requested.
  • When one value is seen in several places, a script hit is kept over a plain HTML hit so the escalation is not lost.

The squirrelscan agent skill does not need a change as far as I can tell: no skill file in this repo mentions this rule's check names. If the skill lists check names, the maintainer will file that change.

Acceptance criteria

All tests are in packages/rules/tests/security/leaked-secrets-critical.test.ts.

  • A server-only secret found in a browser-served script is reported as critical with "shipped to every visitor" copy: server-only secret in an external script is critical with shipped-to-every-visitor copy, server-only secret in an inline script is critical
  • The same class found only in a server response (page HTML, not browser-served) keeps its current severity: a server-only secret outside a script keeps its current severity
  • Publishable and anon keys (pk_live, Supabase anon) are not escalated: publishable keys are not escalated (Supabase anon is covered by the existing corpus case in leaked-secrets.test.ts, which still expects public)
  • No new duplicate finding, severity and message adjusted on the existing hit: no duplicate finding: one hit appears once, in the critical check only, a script hit is kept over a plain HTML hit of the same value, in either page order, a non-server-only class in a script stays high
  • Docs page docs/rules/security/leaked-secrets.mdx describes the escalation, and make validate passes in docs

Verification

  • bun test on each of: tests/security/leaked-secrets-critical.test.ts, tests/security/leaked-secrets.test.ts, tests/leaked-secrets.test.ts, tests/security/secrets-confidence.test.ts, tests/literal-prefilter.test.ts (packages/rules), and tests/streaming-collector-rules-golden.test.ts (packages/audit-engine): all pass.
  • Existing corpus expectations for server-only classes in scripts were updated from high or medium to critical.
  • tsgo --noEmit in packages/rules, root format:check, docs make validate and the detect-secrets hook: all clean.

Checklist

  • I added or updated tests for behavioral changes.
  • I did not include secrets, customer data, or incompatible third-party material.
  • Every commit includes a DCO Signed-off-by line (git commit -s).

…to critical

security/leaked-secrets now reports a server-only secret read from an external or inline script in a new leaked-secrets-critical check with shipped-to-every-visitor copy. The same class in page HTML and publishable keys keep their current severity, and the hit is moved, not duplicated.

Signed-off-by: Nik Cubrilovic <[email protected]>
@claude

claude Bot commented Oct 8, 2026

Copy link
Copy Markdown

Reviewed the diff. The escalation logic is small and the dedup handling looks right. I checked that all 13 SERVER_ONLY_TYPES names match real pattern names. I did not run the tests.

  • (medium) leaked-secrets.ts (leaked-secrets-critical check): the check sets status: "fail" and puts the severity only in details.severity. Rule-level severity stays error, as the PR says. The scoring and reporters treat it like the high check, so a critical finding does not lower the score any more than a high one. I found no other consumer of the check names. Please confirm that details.severity is actually surfaced in the CLI, JSON and LLM output, or it will be invisible to users.
  • (low) leaked-secrets-critical.test.ts: there is no test for the new dedup branch. That is the case where a script hit is kept over a later plain-HTML hit of the same value, in either order. The no-duplicate test uses an inline script plus an external script, which both count as script hits. Add a case with the same secret in page HTML and in a script.
  • (low) cases.ts: the SERVER_ONLY list is duplicated on purpose, but the two lists can drift apart. Both are plain string sets, so a rename in the rule would fail the corpus rather than go unnoticed. That is acceptable, so I'm only noting it.
  • (nit) isBrowserServed uses startsWith to cope with the (base64) suffix. Matching on a parsed location would be sturdier, but it works as written.
  • (nit) The CHANGELOG entry is long for a single line. The docs cover the same detail.

No reporter renders check details, so the severity is now in the message text. Adds a test for a script hit kept over a plain HTML hit in either page order.

Signed-off-by: Nik Cubrilovic <[email protected]>

nc9 commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor Author

Status after review round 1 (pushed 7093de0):

  • Medium, details.severity visibility: confirmed no reporter renders check.details, so the severity was invisible. The check message now says "critical" and "shipped to every visitor", and the docs and PR body no longer claim details.severity.
  • Low, dedup test: added a test with the same secret in page HTML and in a script, in both orders.
  • Nits (startsWith, long changelog entry): left startsWith as is, shortened the changelog entry.

Waiting on CI and any further review.

@claude

claude Bot commented Oct 8, 2026

Copy link
Copy Markdown

Review of the leaked-secrets-critical escalation. The logic is sound and I found no blocking issues.

  • (low) packages/rules/src/security/leaked-secrets.ts:2623 — details: { severity: "critical" } has no obvious consumer. The rule's meta.severity is still "error" and RuleSeverity has no critical. If the engine or reporters ignore details.severity, the check will render like the high check and the "critical" label is only in the message. Please confirm it is read somewhere (merge-core, report output). If not, say so in the changelog or wire it up.
  • (low) leaked-secrets.ts:~1440 — SERVER_ONLY_TYPES matches on pattern name strings. Renaming a pattern, or adding a new server-only one, silently drops it from escalation. The test harness duplicates the list on purpose, which catches renames. A cheap guard would be a test that every name in the set exists in the pattern tables.
  • (nit) leaked-secrets.ts:2571 — the dedup guard is correct and well tested in both page orders. Consider noting that byValue keeps the last non-escalated hit for non-server-only values, so only the escalation case is protected.
  • (nit) The tests call parsePage and cast ctx with as unknown as RuleContext. That is fine, but any on checks loosens the assertions slightly.
  • (nit) Case names like rs256-supabase-service-role-jwt-is-high now expect critical. Rename them to avoid confusion.

Security: no concerns. Fixtures are synthetic and allowlisted, and the masked values are unchanged.

Test coverage is good: inline and external scripts, HTML-only, publishable keys, a non-server-only class, no-duplicate, and page order. The existing case harness is updated for the new tier.

nc9 commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor Author

Status: second review has no critical, high or medium findings, so no further push. The details.severity point is covered in my previous comment: no reporter reads it, and the "critical" label is carried by the check name and message, which the PR body now states. The pattern-name guard, case renames and test typing nits stay as is. Waiting on CI and human review; not merging.

Nik Cubrilovic added 3 commits October 9, 2026 22:48
…al tier

Merging main brought in #589 (placeholder connection strings drop to medium)
and #584 (vendor public ids in script URLs). Escalating every medium
server-only hit in a script turned those back into critical fails, so:

- DigitalOcean Spaces Key leaves the server-only set: it matches the access
  key id by shape alone, the public half of the pair, and public vendor ids
  share that shape (#574).
- A value containing EXAMPLE (AWS's documented example credentials), a
  connection string the confidence pass marked as a placeholder host or
  database, and a database URL to localhost/127.x/[::1] keep their tier
  instead of escalating. A Next.js docs page inlines every code sample into
  a script payload, so these would otherwise read as critical.
- Two tests from main read only the high and medium checks; they now see
  the critical check too, and the precision positive control expects
  critical for a script hit.

Signed-off-by: Nik Cubrilovic <[email protected]>
Codex pass on the critical tier: an Azure connection string escalates only
when its AccountKey is a 64-byte base64 key (`<account-key>` and
YOUR_ACCOUNT_KEY stay high), and a database URL skips escalation only when
every host is localhost, a 127.x.x.x address or [::1], so 127.evil.test and
a mixed mongo host list still escalate.

Signed-off-by: Nik Cubrilovic <[email protected]>
@nc9

nc9 commented Oct 9, 2026

Copy link
Copy Markdown
Contributor Author

Landing pass (pushed fad0553): merged main, which conflicted on CHANGELOG.md and .secrets.baseline and also broke three tests in ways the old CI run could not see. Then I narrowed the critical tier so it only fires on real server-only secrets.

  • Merge fallout: fix(rules): skip vendor public identifiers in script URL queries in leaked-secrets #584's findings() helper in tests/leaked-secrets.test.ts read only the high and medium checks, and fix(rules): leaked-secrets precision for generic matches and Statsig key classification #589's Stripe positive control expected high for a script hit. Both now include critical.
  • FP fixes, all escalation-only, so a value that does not escalate still reports at its own tier and nothing is hidden:
  • Gates: 5 leaked-secrets test files (2407 pass), secrets-decode, redos-recheck, literal-prefilter, the engine golden test, tsgo in packages/rules, detect-secrets-hook, and docs make validate. All clean. rule-time-budget.test.ts fails the same way on main under load, so this branch did not cause it.
  • Codex found these older issues, which I left out of this PR: a #?password= fragment counts as a credential (confidence.ts), percent-escaped placeholders, and one AWS secret written under two assignment syntaxes dedupes as two findings.

@claude

claude Bot commented Oct 9, 2026

Copy link
Copy Markdown

Review of #575 (leaked-secrets-critical escalation)

I read the rule change in leaked-secrets.ts, the dedup change and the test updates. The design is sound: a hit moves out of high/medium into critical rather than being reported twice, and the tutorial and placeholder exclusions are sensible. I couldn't run the test suite here.

  • (low) leaked-secrets.ts isTutorialValue: s.value.includes("EXAMPLE") is case-sensitive and matches anywhere in the value. A real connection string whose password contains EXAMPLE (e.g. a company named Example) would silently stay at high. This fails safe, but it is a hole in the new critical check. Consider limiting it to AWS-shaped types.
  • (low) isTutorialValue: the LOOPBACK_HOST_RE check misses a bare IPv6 host with a port, e.g. [::1]:5432. The :\d*$ strip leaves [::1] and this works, but ::1 without brackets does not match. That is probably fine because it is invalid in a URL. A unit test for [::1]:5432 would pin the behaviour.
  • (low) Dedup change: the new continue keeps the first critical hit by value. If the same value shows up in both an inline-script and an external-script, the reported location depends on page order. This is harmless but non-deterministic across crawl order.
  • (nit) details: { severity: "critical" } is noted as unrendered by reporters. Worth a follow-up issue so the tier isn't carried only by the check name and message text.
  • (nit) isShippedServerSecret is exported. Confirm that something outside this file (the tests) needs it, otherwise keep it module-private.

No blocking issues found.

@claude

claude Bot commented Oct 9, 2026

Copy link
Copy Markdown

Reviewed the diff for leaked-secrets-critical. No blocking problems found. Notes below; I did not run the test suite.

  • (low) leaked-secrets.ts isTutorialValue: the value.includes("EXAMPLE") check is case-sensitive and applies to every server-only class. A real secret that happens to contain the substring EXAMPLE (for instance a Postgres password or a hostname like db.EXAMPLE.com) would be demoted from critical to high. This is a low-probability false negative, but it could be narrowed to the AWS secret type or to a suffix match.
  • (low) isTutorialValue: the loopback test only inspects the authority. A URL like postgres://u:p@localhost/db?host=prod.internal is treated as loopback-only, and JDBC-style URLs that carry the host in the query are skipped. This is an edge case and it fails safe, because the hit stays at high.
  • (low) isShippedServerSecret is exported, but the test harness (cases.ts) deliberately re-declares the class list. That is fine for independence, but the two lists can drift when a new server-only pattern is added. A short comment in the rule next to SERVER_ONLY_TYPES pointing at the harness list would help.
  • (nit) The details: { severity: "critical" } field is not rendered by any reporter, as the PR notes. Consider a follow-up so JSON consumers can use it, or a test that pins the scoring behaviour ("scored like high") rather than only the check name.
  • (nit) The CHANGELOG entry is cut off mid-sentence in the diff view. Please check it ends properly.

The dedup change (a script hit is kept over a later plain-HTML hit of the same value) is correct. It is covered by the order-independence test in both directions. Test coverage for the new behaviour is good.

@nc9

nc9 commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor Author

Triage of the 12:08 review (all low or nit, nothing blocking), plus a re-merge of main for #606 (CHANGELOG only), pushed as 27d6915:

  • EXAMPLE matches any type, case-sensitively: kept on purpose. A miss stays at high and is never hidden, and the same value can only escalate through one rule. An uppercase EXAMPLE inside a real random key or password is rare enough that the extra type check isn't worth it.
  • [::1]:5432: already pinned in a database URL to this machine in a script keeps its current severity.
  • Location order when one value is in an inline and an external script: either one is a correct critical hit. This PR leaves the existing first-wins behaviour in place.
  • details.severity has no consumer: the PR body and docs say so. Left as a follow-up for the maintainer.
  • isShippedServerSecret export: nothing imports it today, so it could be module-private. That's harmless, so I'm leaving it rather than spend another CI run.

@nc9
nc9 merged commit 564595d into main Oct 9, 2026
15 checks passed
@nc9
nc9 deleted the claude/leaked-secrets-severity-j2calx branch October 9, 2026 12:34
nc9 pushed a commit that referenced this pull request Oct 9, 2026
* origin/main:
  feat(rules): escalate server-only secrets shipped in browser scripts to critical (#575)
  fix(rules): cap bad-caching validators at warn and note a Cloudflare-stripped ETag (#606)
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.

1 participant