Repository navigation
fix(rules): leaked-secrets precision for generic matches and Statsig key classification - #589
Conversation
Generic password matches spanned compiled JSX after a label ending in the
credential word (`children:"Password:"`), and reported translated labels
and template expressions as secrets. The label's own closing quote is no
longer read as a value's opening quote, and the scan resumes after the
label's key so a real assignment behind it is still found. A single
foreign-language word with no digits or symbols, a known translation of
"password", and a template or JSX expression are not credential values.
A connection string whose password is a documentation placeholder
(`username:password@`, `<password>`, `${DB_PASSWORD}`, `****`) is dropped,
and a real-looking password under a placeholder host or database is kept
at medium with a `placeholder` meta field.
A provider pattern now needs the whole token on the right as well as the
left: a shape that continues into more token characters is a substring of
a longer value, not that provider's token. `sk_live_` and `sk_test_` are
prefixes other vendors copy, so such a key that continues past Stripe's
format is reported at medium as `Secret Key (sk_live_ prefix, provider
unknown)` instead of as Stripe's.
The existing corpus, snapshot and unit tests pass unchanged. A new
offline suite pairs each negative with the positive controls it must not
silence.
Signed-off-by: Nik Cubrilovic <[email protected]>
Statsig documents server secret keys as confidential and client SDK keys as meant for public applications, but a `serverSideApiKey` and a `clientSideApiKey` both reported as the same medium generic API key. A table of providers that write the key kind into the prefix, `PROVIDER_KEY_PREFIXES`, now classifies a generic assignment's value when the provider is named in the key or up to 120 characters before it. A Statsig `secret-` key reports high as `Statsig Server Secret Key`; a `client-` key reports in the public tier as `Statsig Client SDK Key`. A `secret-` value with no provider named reports at medium as `Secret Key (secret- prefix, provider unknown)`, and a bare `client-` value is left to the generic assignment as before. Each of these findings carries `exposure`, `validity: not tested` and `scope: not tested` in its meta, so the report separates what the page shows from what the key can do. The rule still never contacts a provider. The existing corpus, snapshot and unit tests pass unchanged. Signed-off-by: Nik Cubrilovic <[email protected]>
Auto-review did not completeThe
Permission denials (1)Partial findings recovered from the session (incomplete, unverified, and NOT a merge signal): Show partial reviewI read the diff but didn't run the tests. CI was still pending when I looked. Format, lint and typecheck had passed. I found nothing blocking.
Test coverage looks good for the new behavior: the PR adds |
Review follow-up. A provider shape that runs on into more letters or digits is still dropped as a slice of a longer value, but one glued to a `_` or `-` suffix (`AKIA..._PROD`) is now reported at medium as `Secret Key (provider unknown)` with the pattern it resembles, instead of being dropped silently. A label must open on a word: a quote followed by a space closes an earlier string (`name: "bob" password: "..."`), so that assignment reports. A connection string password counts as a mask only when it is a run of `*`, `•` or `.`; other symbol-only passwords are kept. Translations shorter than the generic pattern's eight-character floor are removed from the label list, and the provider keyword length is computed once. Signed-off-by: Nik Cubrilovic <[email protected]>
…statsig-9mbio1' into claude/leaked-secrets-precision-statsig-9mbio1 Signed-off-by: Nik Cubrilovic <[email protected]>
|
Round 1, on the partial findings recovered from the auto-review. All changes are in
Existing corpus (2251), snapshot and unit tests still pass unchanged, and the new suite now has 20 tests. |
|
Reviewed the diff (leaked-secrets precision + Statsig prefixes). The design is careful and the tests pair negatives with positive controls. I did not run the test suite, so these findings come from reading the code only.
Test coverage is good overall: the new |
|
Round 2: no code change. Point by point:
|
|
Status: ready for a maintainer.
There is no issue to tick. The checklist in the PR body maps each criterion to its test. |
…eaked-secrets A provider match followed by more letters or digits was dropped. Fixed- length formats grow, and text with its markup stripped can run a real token into the next word, so a real leak was lost with no fallback. Such a match is now reported, as the whole token, at medium as `Secret Key (provider unknown)` with the pattern it resembles, the same as one glued to a `_` or `-` suffix. It is dropped only when the provider's own decoder rules out the matched part (a GitHub token whose checksum fails), which keeps a `ghp_` run inside a long random value silent as it is on main. Tests pin a real-format AWS id and GitHub token followed directly by a word and by digits as positive controls, beside the negatives that such a token never carries the provider's name. The existing corpus and its snapshot are unchanged, and the bench corpus reports 135 findings, the same as main. Signed-off-by: Nik Cubrilovic <[email protected]>
|
Round 3: the lead's medium finding is fixed in Change. A provider match followed by more letters or digits is no longer dropped silently. The whole token is reported at medium as One deliberate exception. The match is still dropped when the provider's own decoder rules out the matched part, for example a Tests (
False-positive effect.
Main had nothing new to merge, since the branch already contains |
|
Review of the leaked-secrets precision changes. I read the diff only and did not run the tests or check CI.
Overall the change is well structured and the test coverage is extensive: negatives are paired with positive controls, and the test values are synthetic. I found no blocking issues. |
|
This review needs no code change. Both items it asks for are already on the head:
That is the last review round for this PR. CI and the maintainer decide from here. Not merging. |
|
Review of #589. I read the diff but did not run the tests or the build.
I found no security problems: the rule still never calls providers, and the new regex-free scanning has bounded loops. Test coverage was added in 🤖 Generated with Claude Code |
|
This review needs no code change. Evidence for each point:
The review-round limit is reached, so this goes to the maintainer. |
|
Reviewed the diff (leaked-secrets.ts, secrets/confidence.ts, docs, new precision tests). I didn't run the test suite, and CI was still pending when I looked. I found no blocking issues. The new behaviour is well documented and each negative case has a positive control.
|
|
This review has no blocking findings, and the review-round limit is reached, so I have not pushed. One low is real and is the maintainer's call:
|
…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]>
…to critical (#575) security/leaked-secrets reports a server-only secret read from a browser-served script (inline or external, including a decoded base64 blob) in a new leaked-secrets-critical check, "shipped to every visitor". The hit moves out of the high or medium check and is never reported twice. A script hit is kept over a plain HTML hit of the same value, whichever page comes first. Server-only classes: 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 and DigitalOcean tokens. These never escalate and keep their own tier: publishable and anon keys, DigitalOcean Spaces access key ids, values containing EXAMPLE (AWS's documented examples), Azure connection strings without a 64-byte AccountKey, connection strings with a placeholder host or database (#589), and database URLs whose every host is loopback. Docs: docs/rules/security/leaked-secrets.mdx. Refs squirrelscan/repo#1954. Signed-off-by: Nik Cubrilovic <[email protected]> Signed-off-by: Nik Cubrilovic <[email protected]>
Summary
Two precision fixes to
security/leaked-secrets, one commit each, plus two review follow-up commits. No GitHub issue exists for these, so the criteria below come from the task brief and there is noRefsline. Builds on thePUBLIC_URL_IDENTIFIERStable from #584 without duplicating it.Commit 1, generic match precision (
29369a5)children:"Password:") is no longer read as a key whose value spans the compiled JSX after it. The scan resumes after the label's key, so a real assignment behind it is still found.{form.password}) are not credential values.placeholdermeta.sk_live_orsk_test_key that runs past Stripe's format is reported at medium asSecret Key (sk_live_ prefix, provider unknown), not as Stripe's.Commit 2, Statsig key classification (
62c6648)PROVIDER_KEY_PREFIXEStable. A Statsigsecret-key reports high asStatsig Server Secret Key, and aclient-key reports as publicStatsig Client SDK Key. This applies whenstatsigis in the key or up to 120 characters before it.secret-value with no provider named reports at medium asSecret Key (secret- prefix, provider unknown). A bareclient-value is unchanged.exposure,validity: not testedandscope: not testedin meta.Review follow-ups (
ed9b902,7f3fb88)_or-suffix (AKIA..._PROD), more letters or digits, and a token run into the next word. The whole token is reported at medium asSecret Key (provider unknown), withresembles: <pattern>in meta. It is dropped only when the provider's own decoder rules out the matched part, such as a failing GitHub checksum.name: "bob" password: "..."reports. Only a run of*,•or.counts as a masked connection-string password. Translations under the 8-character generic floor are removed from the label list.Acceptance criteria
Part 1, precision of generic matches
a JSX label ending in the credential word ...anda translated password label is not a secret, plusa template expression ...inpackages/rules/tests/security/leaked-secrets-precision.test.ts.postgresql://username:password@host:5432/dbnameproduce no high-confidence finding. Tests:a placeholder password reports nothinganda real-looking password under a placeholder host or database is kept, at medium.negatives: a provider shape that runs on past its token is never reported under the provider's nameandnegative: a continued shape its provider's own structure rules out is dropped.sk_live_prefix alone. Tests:a widget key that continues past Stripe's format keeps a qualified, unknown-provider label(metaprovider: unknown,resembles: Stripe Live Key) and thesk_test_variant.sampleRateor documentation text still report. Tests:positive controls: real-shaped assignments beside labels, sampleRate and docs text still report.positive controls: the whole continued token stays reviewable at medium, provider unknown. This covers a real-format AWS id and GitHub token directly followed by a word and by digits.Part 2, Statsig key classification
secret-value in Statsig server config is a server-secret exposure candidate. Tests:server and client configuration side by side ...(leaked-secrets-high) andan env-style server secret names its provider in the variable.client-value is distinguished and does not get secret-leak severity. Tests: the side-by-side test (leaked-secrets-public) andthe client key alone does not fail the rule.secret-strings without provider context keep qualified attribution. Test:a secret- prefix without Statsig named in front of the key keeps a qualified, unknown-provider label(no keyword, keyword too far, keyword after).output separates exposure from untested validity and scope, checked on the raw finding and on the rule item'smeta.secret-/client-bodies.Docs
docs/rules/security/leaked-secrets.mdxhas three new sections: labels, templates and documentation placeholders; whole-token provider attribution, including the unknown-provider fallback; and server or client key prefixes, with the Statsig table and the exposure versus validity note.make validatepasses.False-positive effect on the existing corpus
tests/security/leaked-secrets.test.ts, 2251 pass) and its raw-output snapshotexpected.jsonare byte-identical on the current head. No existing case gained, lost or changed a finding.bench:secrets(seed 1, 200 pages, 66.67 MB) reported 135 findings on main and after every commit on this branch. Scan time stayed between 22.25 and 23.78 ms/MB, one iteration each, which is noise.Verification
Run one file at a time from
packages/rules, all passing:tests/security/leaked-secrets.test.ts(2251),tests/leaked-secrets.test.ts(92),tests/security/secrets-confidence.test.ts(29),tests/security/secrets-decode.test.ts(29),tests/security/leaked-secrets-precision.test.ts(21 new)tests/literal-prefilter.test.ts(28),tests/redos-recheck.test.ts(7),tests/rule-time-budget.test.ts(20),packages/audit-engine/tests/streaming-collector-rules-golden.test.ts(1)bun run typecheckinpackages/rules, rootbun run format:check, andmake validateindocsall pass.detect-secrets-hook --baseline .secrets.baselineovergit ls-filesexits 0. Every fixture line has an inline pragma comment, and the baseline diff only moves line numbers.b9d58f5.Notes:
docs.statsig.comcould not be reached from the build sandbox. The prefixes and their confidentiality come from the page cited in the brief.Statsig.initialize("secret-...")) is still not classified. Call arguments are existing known gap 9 in the corpus README, and the new docs section says so.Agent skill
No change needed. The new check items reuse the existing check names, and the new
metafields are additive. The maintainer can file a follow-up if the skill should explainvalidity: not testedor theprovider unknowntypes.Checklist
Signed-off-byline (git commit -s).