Repository navigation
feat(rules): escalate server-only secrets shipped in browser scripts to critical - #575
Conversation
…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]>
|
Reviewed the diff. The escalation logic is small and the dedup handling looks right. I checked that all 13
|
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]>
|
Status after review round 1 (pushed 7093de0):
Waiting on CI and any further review. |
|
Review of the
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. |
|
Status: second review has no critical, high or medium findings, so no further push. The |
Signed-off-by: Nik Cubrilovic <[email protected]>
…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]>
|
Landing pass (pushed fad0553): merged main, which conflicted on
|
|
Review of #575 (leaked-secrets-critical escalation) I read the rule change in
No blocking issues found. |
Signed-off-by: Nik Cubrilovic <[email protected]>
|
Reviewed the diff for
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. |
|
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:
|
Summary
security/leaked-secretsnow reports a server-only secret that is read from a browser-served script (external-scriptorinline-script, including a base64 blob decoded from one) in a newleaked-secrets-criticalcheck. The message says "critical" and that the secret is shipped to every visitor. The hit moves out ofleaked-secrets-highorleaked-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 arepublicByDesignand 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 whoseAccountKeyis 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:
check.details. Rule-level severity stayserror, 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.htmllocation (page markup) keeps its current severity.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.server-only secret in an external script is critical with shipped-to-every-visitor copy,server-only secret in an inline script is criticala server-only secret outside a script keeps its current severitypk_live, Supabase anon) are not escalated:publishable keys are not escalated(Supabase anon is covered by the existing corpus case inleaked-secrets.test.ts, which still expectspublic)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 highdocs/rules/security/leaked-secrets.mdxdescribes the escalation, andmake validatepasses indocsVerification
bun teston 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), andtests/streaming-collector-rules-golden.test.ts(packages/audit-engine): all pass.tsgo --noEmitinpackages/rules, rootformat:check, docsmake validateand thedetect-secretshook: all clean.Checklist
Signed-off-byline (git commit -s).