Skip to content

fix(rules): leaked-secrets precision for generic matches and Statsig key classification - #589

Merged
nc9 merged 8 commits into
mainfrom
claude/leaked-secrets-precision-statsig-9mbio1
Oct 8, 2026
Merged

nc9 merged 8 commits into
mainfrom
claude/leaked-secrets-precision-statsig-9mbio1

Conversation

@nc9

@nc9 nc9 commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor

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 no Refs line. Builds on the PUBLIC_URL_IDENTIFIERS table from #584 without duplicating it.

Commit 1, generic match precision (29369a5)

  • A label ending in the credential word (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.
  • Translated password labels and template or JSX expressions ({form.password}) are not credential values.
  • Connection strings with a placeholder password are dropped. A real-looking password under a placeholder host or database drops to medium with placeholder meta.
  • Provider patterns need the whole token on the right as well as the left before the provider's name is given. An sk_live_ or sk_test_ key that runs past Stripe's format is reported at medium as Secret Key (sk_live_ prefix, provider unknown), not as Stripe's.

Commit 2, Statsig key classification (62c6648)

  • New PROVIDER_KEY_PREFIXES table. A Statsig secret- key reports high as Statsig Server Secret Key, and a client- key reports as public Statsig Client SDK Key. This applies when statsig is in the key or up to 120 characters before it.
  • A secret- value with no provider named reports at medium as Secret Key (secret- prefix, provider unknown). A bare client- value is unchanged.
  • These findings carry exposure, validity: not tested and scope: not tested in meta.

Review follow-ups (ed9b902, 7f3fb88)

  • A provider shape that runs on past its token is never dropped silently. This covers a _ or - suffix (AKIA..._PROD), more letters or digits, and a token run into the next word. The whole token is reported at medium as Secret Key (provider unknown), with resembles: <pattern> in meta. It is dropped only when the provider's own decoder rules out the matched part, such as a failing GitHub checksum.
  • A label must open on a word, so 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) Translated password labels and JSX label text produce no secret finding. Tests: a JSX label ending in the credential word ... and a translated password label is not a secret, plus a template expression ... in packages/rules/tests/security/leaked-secrets-precision.test.ts.
  • (b) Placeholders such as postgresql://username:password@host:5432/dbname produce no high-confidence finding. Tests: a placeholder password reports nothing and a real-looking password under a placeholder host or database is kept, at medium.
  • (c) A credential-like substring inside a longer value is not reported as a delimited provider token. Tests: negatives: a provider shape that runs on past its token is never reported under the provider's name and negative: a continued shape its provider's own structure rules out is dropped.
  • (d) A custom widget key is not attributed to Stripe on its sk_live_ prefix alone. Tests: a widget key that continues past Stripe's format keeps a qualified, unknown-provider label (meta provider: unknown, resembles: Stripe Live Key) and the sk_test_ variant.
  • (e) Real-secret-shaped synthetic assignments next to sampleRate or 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.
    • The positive control in each other block: deployed and symbol-only-password connection strings at high, and delimited shapes keep their provider's name.
  • (f) Negatives and positive controls run together in one offline, seeded suite of 21 tests. It uses seeded generators and inline synthetic values with pragma comments, and makes no network calls. On main, 9 of the original 12 Part 1 tests fail and the 3 positive-control-only tests pass.

Part 2, Statsig key classification

  • (a) A synthetic secret- value in Statsig server config is a server-secret exposure candidate. Tests: server and client configuration side by side ... (leaked-secrets-high) and an env-style server secret names its provider in the variable.
  • (b) A client- value is distinguished and does not get secret-leak severity. Tests: the side-by-side test (leaked-secrets-public) and the client key alone does not fail the rule.
  • (c) Unknown 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).
  • (d) Output separates exposure from untested validity and scope. Test: output separates exposure from untested validity and scope, checked on the raw finding and on the rule item's meta.
  • (e) Fixtures include server and client config side by side, with no production values. Same side-by-side test, using seeded secret-/client- bodies.

Docs

  • docs/rules/security/leaked-secrets.mdx has 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 validate passes.

False-positive effect on the existing corpus

  • The leaked-secrets corpus (tests/security/leaked-secrets.test.ts, 2251 pass) and its raw-output snapshot expected.json are 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.
  • The changes only affect value shapes the existing corpus does not contain. Their effect is measured by the new suite.

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 typecheck in packages/rules, root bun run format:check, and make validate in docs all pass.
  • detect-secrets-hook --baseline .secrets.baseline over git ls-files exits 0. Every fixture line has an inline pragma comment, and the baseline diff only moves line numbers.
  • CI is green on b9d58f5.

Notes:

  • docs.statsig.com could not be reached from the build sandbox. The prefixes and their confidentiality come from the page cited in the brief.
  • A Statsig key passed straight to a call (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 meta fields are additive. The maintainer can file a follow-up if the skill should explain validity: not tested or the provider unknown types.

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).

nc9 added 2 commits October 8, 2026 15:16
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]>
@github-actions

github-actions Bot commented Oct 8, 2026

Copy link
Copy Markdown
Contributor

Auto-review did not complete

The claude-review session ended without posting a review. This PR has not been auto-reviewed. Run a review manually (/review) before merging.

  • Result: success / is_error=false after 7 turns, 1 permission denial(s), $0.14
  • Job log
Permission denials (1)
Bash {"command":"cd /tmp; gh pr diff 589 --name-only; gh pr diff 589 -- packages/rules/src 2>/dev/null | head -0; gh pr diff 589 | awk '/^diff --git/{p=($3 ~ /src\\/.*leaked-secrets/ )} p' | head -c 30000;… [truncated]

Partial findings recovered from the session (incomplete, unverified, and NOT a merge signal):

Show partial review

I 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.

  • (medium) packages/rules/src/security/leaked-secrets.ts (continuedTokenEnd and the new right-boundary check): any provider match that is followed by more word characters, or by - plus a word character, is now dropped. Only sharedPrefix patterns survive as "provider unknown". This is a deliberate precision trade, but it makes every non-shared-prefix provider pattern (AKIA, ghp_, and so on) a silent false negative when the token is glued to a suffix. Examples are AKIA…_PROD in an env-style string, or a token with a trailing -suffix in a bundle. Please add a test for each such shape, and consider falling back to a medium "provider unknown" finding instead of continue for high-value patterns. The docs should also say that a token is dropped when it runs on past its format.
  • (low) leaked-secrets.ts, keyInsideStringLiteral: the left walk accepts spaces. A single-line config such as name: "bob" password: "hunter2abc9" therefore looks like a label (the walk reaches the " that closes "bob") and the real assignment is skipped. The a="b" password=… case in the comment is handled because = fails the ^\s*: check. The : form isn't, so please add a test that pins whichever behavior you want.
  • (low) confidence.ts, isPlaceholderSecret: folded === "" treats any password made only of symbols (!!!!, -----) as a placeholder, and the connection string is dropped entirely. That is probably intended for ****, but it also hides real symbol-only passwords. Consider limiting it to runs of *, x, . or •.
  • (low) leaked-secrets.ts, PASSWORD_TRANSLATIONS: senha, parola, heslo and haslo are plausible real passwords. They are skipped only when they are a whole bare word, and isTranslatedLabel has no check on the key, so password: "parola" is dropped. Consider requiring a key that names a label or locale, or accept the trade-off and note it in the docs.
  • (low) providerKeyOf: the 120-character context window can attribute a secret-… value to Statsig when Statsig only appears nearby, for example a bundle with several SDK configs. The result is high confidence under the Statsig name. A test with another provider between the statsig mention and the key would show whether this is acceptable.
  • (nit) .secrets.baseline only changes line numbers and the timestamp. The // pragma: allowlist secret comments added inside the source add noise, so check that the baseline stays stable.
  • (nit) providerKeyOf calls Math.max(...rows.map(...)) on every call. This is trivial now, but the maximum could be precomputed as a constant.

Test coverage looks good for the new behavior: the PR adds leaked-secrets-precision.test.ts cases for labels, templates, placeholders and Statsig. The gaps are the negative and regression cases listed above.

nc9 added 3 commits October 9, 2026 02:28
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]>

nc9 commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor Author

Round 1, on the partial findings recovered from the auto-review. All changes are in ed9b902, plus a merge of the branch's own main merge.

  • (medium) Right boundary drops suffixed provider shapes silently. Fixed. A shape that runs on into more letters or digits is still dropped as a slice of a longer random value. One glued to a _ or - suffix (AKIA..._PROD, key-..._active) is now reported at medium as Secret Key (provider unknown), with resembles: <pattern> in meta. Test: a provider shape glued to a _ or - suffix stays reviewable, unattributed, at medium. The docs section now describes both cases.
  • (low) name: "bob" password: "..." reads as a label. Fixed. A label must open on a word, so a quote followed by a space is read as closing an earlier string. Pinned as a positive control.
  • (low) A symbol-only password is treated as a mask. Fixed. Only a run of *, • or . counts as a mask now. Pinned with !!!!----, which stays high.
  • (low) senha, parola, heslo and haslo in the translation list. Removed. The generic pattern needs a value of at least 8 characters, so these never matched anyway. Every entry under 8 characters is gone, so the list no longer reads as a blind spot.
  • (low) The 120-character Statsig window inside a multi-SDK bundle. Kept as is. The value must already have Statsig's exact secret- plus 32 to 64 alphanumerics shape, and statsig must appear in the key or within 120 characters before it. Another vendor's object between the two would need a secret--shaped value of its own to be misattributed. Narrowing further would lose statsig: {serverSideApiKey: ..., clientSideApiKey: ...}. The docs state the window.
  • (nit) Recomputing the max on every call. Fixed: PROVIDER_KEYWORD_MAX is now a constant.
  • (nit) Baseline stability. The .secrets.baseline diff still only moves line numbers. detect-secrets-hook over git ls-files exits 0.

Existing corpus (2251), snapshot and unit tests still pass unchanged, and the new suite now has 20 tests.

@claude

claude Bot commented Oct 8, 2026

Copy link
Copy Markdown

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.

  • (medium) packages/rules/src/security/leaked-secrets.ts (continuedTokenEnd / the unattributed branch): when a provider match is followed by more letters or digits, the code does continue and drops the finding silently. Fixed-length formats do grow, and text that has been stripped of tags can run a token straight into the next word. A real leak is then lost with no medium fallback. Consider keeping those matches at medium with provider: unknown instead of dropping them. At minimum, add a test for a real-format token directly followed by a word character. This is a recall trade-off, so please confirm it is intended.
  • (low) isTranslatedLabel: any single letters-only word with at least one non-ASCII letter is suppressed (for example a 12-letter passphrase like Pässwörtlang). This is documented, but it is a blind spot for human-chosen passwords. A short note in the rule docs about the limitation would help.
  • (low) providerKeyOf: the 120-character name window can attribute a secret- key to Statsig when the word statsig appears in an unrelated nearby identifier (such as an import or a comment). The result is high confidence on a value with the exact secret- plus 32-64 shape, so the risk is small. Worth knowing as a possible severity over-attribution.
  • (nit) PLACEHOLDER_DB_RE accepts name and PLACEHOLDER_SECRET_RE accepts pass and pw. A real database called name, or a password literally pass, would be dropped or downgraded. This is acceptable for docs examples, but the doc could say so.
  • (nit) The # pragma: allowlist secret comments inside the new source comments are noisy. Consider consolidating the examples.

Test coverage is good overall: the new leaked-secrets-precision.test.ts covers labels, placeholders, shared prefixes and Statsig, with synthetic values. No security concerns: the scan is offline and never calls providers. No performance concerns, because the extra scanning is bounded (256 characters for the token, 64 for the label, 120 for the provider name).

nc9 commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor Author

Round 2: no code change. Point by point:

  • (medium) Dropping a provider match that runs on into more letters or digits. This is intended. It is acceptance criterion (c): a credential-like substring inside a longer value must not be reported as that provider's token.
    • Recall is kept where a fallback means something. Since ed9b902, a shape glued to a _ or - suffix is reported at medium as Secret Key (provider unknown).
    • Only a direct letter or digit continuation is dropped. In that case the match is a slice that breaks the provider's fixed length: AKIA + 16 has become 22+ characters, and key- + 32 has become 44. For GitHub, a longer run would also fail the checksum decoder anyway.
    • The "tag-stripped text" path does not arise. The rule scans serialized HTML, inline script text and external script bodies, never text content with tags removed, so <b>token</b>word keeps its < boundary.
    • The test the review asks for already exists: a provider shape continued by more token characters is not reported pins a real-format AWS id followed directly by QRSTUV, plus Mailgun and Twilio shapes.
    • The existing corpus and its snapshot are unchanged, so no existing positive lost recall.
  • (low) A letters-only word with a non-ASCII letter is read as a label. This trade-off is accepted and already documented: "A single word with an accented letter and no digits or symbols counts as a label." A passphrase with any digit or symbol still reports, and a positive control pins that (Kä8#mZ2!qX).
  • (low) statsig in an unrelated nearby identifier. Covered in round 1. The value must already have the exact secret- plus 32 to 64 alphanumerics shape, and the docs state the window.
  • (nit) The name, pass and pw placeholders. These only apply inside a connection string's host/database or password position. The docs list them as placeholders. A database literally named name is only downgraded to medium, not dropped.
  • (nit) The pragma comments. These are required. The repo's detect-secrets CI gate flags those lines otherwise, and the baseline only tracks line numbers.

nc9 commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor Author

Status: ready for a maintainer.

  • CI is green on 9a751c3: all 15 checks pass, including claude-review, and the PR merges cleanly.
  • I ran two bot review rounds. Round 1 was fixed in ed9b902. Round 2 needed no code change (see the comment above).
  • The existing leaked-secrets corpus and snapshot are unchanged, and the bench corpus has the same finding count as main.
  • No agent skill change is needed.

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]>

nc9 commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor Author

Round 3: the lead's medium finding is fixed in 7f3fb88.

Change. A provider match followed by more letters or digits is no longer dropped silently. The whole token is reported at medium as Secret Key (provider unknown), with resembles: <pattern> in meta. This is the same treatment the _ and - suffix case already had. Criterion (c) still holds: such a token never carries the provider's name.

One deliberate exception. The match is still dropped when the provider's own decoder rules out the matched part, for example a ghp_ run whose CRC32 checksum fails. Without this, any ghp_ sequence inside a long random value would become a new medium finding that main does not report. A real GitHub token run into the next word passes its checksum and is reported.

Tests (leaked-secrets-precision.test.ts, now 21):

  • Positive controls: a real-format AWS id followed by Welcome and by 2024, and a valid GitHub token followed by Dashboard and by 42, each report medium and unknown-provider. The same holds for longer Mailgun and Twilio shapes, and for _PROD and -active suffixes.
  • Negatives: none of those is reported under the provider's name, and a checksum-failing ghp_ run stays silent.
  • The delimited forms of each shape keep their provider's name at high.

False-positive effect.

  • The existing corpus (2251 tests) and its expected.json snapshot are unchanged.
  • bench:secrets reports 135 findings, the same as main. The scan measured 23.78 ms/MB against main's 22.59 in a single run, which is within noise.
  • The other leaked-secrets unit tests, typecheck, format check, docs make validate and the secret scan all pass.

Main had nothing new to merge, since the branch already contains 8adeb43. Not merging.

@claude

claude Bot commented Oct 8, 2026

Copy link
Copy Markdown

Review of the leaked-secrets precision changes. I read the diff only and did not run the tests or check CI.

  • (medium) leaked-secrets.ts continuedTokenEnd: a real provider token followed directly by word characters or -word is now downgraded from its provider type to Secret Key (provider unknown) at medium. That is a deliberate trade-off, but a live AWS or GitHub key that sits next to other text, for example in stripped markup or a concatenated string, no longer reaches high. If the gate or reports treat high as the actionable tier, these leaks could be missed. Consider a test that pins the intended behavior for a real-format key with a short trailing suffix (_PROD), and mention the downgrade in the docs.
  • (low) isTranslatedLabel: any letters-only value with at least one non-ASCII letter is treated as a translated label and suppressed. A real passphrase made of letters with one accented character would be suppressed under password:. This is probably rare enough to accept. Please document it as a known blind spot.
  • (low) PLACEHOLDER_SECRET_RE and isPlaceholderSecret: a literal password of secret, pass or pw in a connection string is now dropped entirely rather than reported. That is reasonable for docs examples, but those values are also weak real credentials on dev hosts.
  • (low) providerKeyOf: the provider keyword is matched by substring in a 120-character window. Any text containing statsig near a secret-… value is classified as a Statsig key at high. The shape check limits this to secret- plus 32–64 alphanumerics, so the risk is small.
  • (nit) The // pragma: allowlist secret markers are appended inside comment blocks, which splits the sentences oddly. Consider rewording the comments so the markers sit on their own lines.
  • (nit) .secrets.baseline line numbers shift with every edit to leaked-secrets.ts. That is expected, but it is fragile to maintain.

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.

nc9 commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor Author

This review needs no code change. Both items it asks for are already on the head:

  • (medium) A continued token is downgraded to medium, provider unknown. This is deliberate. Acceptance criterion (c) says such a token must not be reported as a delimited provider token, and the lead asked for exactly this medium fallback in round 3.
    • It still fails the rule: leaked-secrets-medium is a counted leak, not an info tier.
    • The _PROD case is pinned in positive controls: the whole continued token stays reviewable at medium, provider unknown, along with word and digit continuations.
    • The docs section "A provider name needs the whole token" states the medium report and its meta.
  • (low) Translated labels, placeholder passwords and the Statsig window. These were answered in rounds 1 and 2. The label rule and the placeholder words are documented trade-offs, and a symbol or digit in a password keeps it reported.
  • (nit) Pragma markers and baseline line numbers. The repo's detect-secrets gate requires the inline markers, and the baseline only tracks line numbers.

That is the last review round for this PR. CI and the maintainer decide from here. Not merging.

@claude

claude Bot commented Oct 8, 2026

Copy link
Copy Markdown

Review of #589. I read the diff but did not run the tests or the build.

  • (medium) leaked-secrets.ts continuedTokenEnd / scanContent: a provider match that is followed by more word characters (or - plus a word character) is now re-reported as 'provider unknown' at medium, where before it was dropped or reported under the provider's name. That is a deliberate recall gain, but it will probably add findings on long identifiers, hashes and slugs that happen to start with ghp_, AKIA or sk_live_. Please check the new behaviour against the precision corpus and add a negative test for a hyphenated slug that starts with a prefix.
  • (low) The 256-character cap on the continued token (CONTINUED_TOKEN_MAX) cuts long tokens silently, so the reported value and the dedup key are truncated. Consider noting that in the finding's meta. After this edit pattern.lastIndex = tokenEnd is correct and the scan stays linear.
  • (low) PROVIDER_KEY_PREFIXES classifies a key as high-severity from a provider keyword that appears within PROVIDER_CONTEXT_GAP characters before it. A nearby unrelated mention of the provider could mislabel a key. Having tests for the negative case (provider name in prose near a non-key value) would pin this down.
  • (nit) .secrets.baseline only has line numbers and a timestamp changed. That is expected, but it will conflict again whenever the file is touched. Also, the inline // pragma: allowlist secret sits in the middle of a comment block, so check that detect-secrets still honours it there.
  • (nit) The docs mention the 'not tested' meta fields. A short note on the new 'provider unknown' types in docs/rules/security/leaked-secrets.mdx would help users who filter on type names.

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 leaked-secrets-precision.test.ts, which is good.

🤖 Generated with Claude Code

nc9 commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor Author

This review needs no code change. Evidence for each point:

  • (medium) Continued tokens could add findings on long identifiers, hashes or slugs. The corpus check it asks for was run on 7f3fb88:
    • The existing corpus (2251 cases, including the 776-site real-world negatives) and its raw-output snapshot expected.json are unchanged.
    • bench:secrets reports 135 findings, the same as main.
    • A hyphenated slug cannot reach this path. The left guard needs a non-word character before the prefix. The provider shape then needs its full fixed run (ghp_ + 36, AKIA + 16, sk_live_ + 24 or more alphanumerics) before any continuation, and a slug's words are hyphen-separated and far shorter than that.
    • The run that does exist (ghp_ + 36 random characters inside a longer string) is dropped by the checksum, and a test pins that.
  • (low) The 256-character cap. A token longer than that is reported up to the cap. The masked value shows its head and tail, and dedup still works by containment. No credential format comes near 256 characters.
  • (low) Provider name in prose. A row applies only to a value with the exact secret- or client- plus 32 to 64 alphanumerics shape. Prose near a non-key value never matches the shape. The keyword-too-far and keyword-after cases are pinned in a secret- prefix without Statsig named ....
  • (nit) Where the pragma sits. The CI secret scan honours the inline pragma: it passed on the previous head and runs detect-secrets-hook over git ls-files.
  • (nit) Provider-unknown types in the docs. The docs already name Secret Key (provider unknown) and Secret Key (<prefix> prefix, provider unknown), with their meta, in "A provider name needs the whole token" and in the Statsig table.

The review-round limit is reached, so this goes to the maintainer.

@claude

claude Bot commented Oct 8, 2026

Copy link
Copy Markdown

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.

  • (low) leaked-secrets.ts (continuedTokenEnd block): the continuation path rewrites reportType and known, but reportPublic keeps the original pattern's publicByDesign. A public-by-design pattern whose match runs on past its token would then get the 'provider unknown' type with publicByDesign: true. Please set reportPublic = false when unattributed !== undefined, or add a test showing the combination can't happen.
  • (low) isTemplateExpression: a bare name with no digits in braces, such as {abcdefghijkl}, is treated as a template and dropped. That is rare and probably acceptable, but worth a doc note.
  • (low) refineConnectionString: isPlaceholderSecret drops passwords that fold to pass, pw or secret. A deployed app:password@prod-db is now silently ignored. That's defensible, but the docs should say it's intentional. A real host named db could also be demoted to medium, and the tests only cover host and dbname.
  • (nit) .secrets.baseline line numbers shift with every edit to leaked-secrets.ts. Consider allowlist pragmas on those lines to reduce churn.
  • (nit) Add a test for sk_live_ continuation through the second 40+ char Stripe-like pattern, since both patterns now carry sharedPrefix.

nc9 commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor Author

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:

  • (low) reportPublic on a continued public pattern. Confirmed. A public-by-design pattern whose class cannot absorb the continuation, such as AIza + 35 followed by more letters or digits, gets the type Secret Key (provider unknown) but stays publicByDesign: true. It then lands in leaked-secrets-public with a secret-sounding name. The fix is one line, reportPublic = false inside the unattributed branch, plus one test. I can push it as a follow-up if wanted.
  • (low) Brace-wrapped bare names, placeholder words and the db host. These are documented trade-offs. A placeholder password drops the finding. A placeholder host or database only drops it to medium, so a real host named db is still reported.
  • (nit) The second sk_live_ pattern. Clerk's sk_live_ + 40 can never claim a value: Stripe Live runs first and the overlap dedup drops the duplicate. This is known gap 1 in the corpus README. The existing sk_live_ continuation test exercises Stripe's pattern, which is the one that fires.
  • (nit) The baseline. The baseline lines are PEM headers in the pattern table, which need their exact literal. The churn is line numbers only.

@nc9
nc9 merged commit 303d0f5 into main Oct 8, 2026
15 checks passed
@nc9
nc9 deleted the claude/leaked-secrets-precision-statsig-9mbio1 branch October 8, 2026 16:38
nc9 pushed a commit that referenced this pull request Oct 9, 2026
…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]>
nc9 added a commit that referenced this pull request Oct 9, 2026
…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]>
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