Skip to content

fix(rules): skip vendor public identifiers in script URL queries in leaked-secrets - #584

Merged
nc9 merged 3 commits into
mainfrom
claude/leaked-secrets-public-ids-1vlgjw
Oct 8, 2026
Merged

nc9 merged 3 commits into
mainfrom
claude/leaked-secrets-public-ids-1vlgjw

Conversation

@nc9

@nc9 nc9 commented Oct 8, 2026

Copy link
Copy Markdown
Contributor

Refs #574

What changed

security/leaked-secrets now has a table, PUBLIC_URL_IDENTIFIERS, of vendor identifiers that ship in the query string of a script or link URL. scanContent computes the span of each such parameter value once per content and skips any match that lies wholly inside one. The check is positional and exact: the host, the path and the parameter name must all match, so nothing is matched by substring.

Initial rows: Mida key (cdn.mida.so, cdn-eu.mida.so, /js/optimize.js), Klaviyo company_id (static.klaviyo.com, /onsite/js/klaviyo.js; Klaviyo's docs call it the public API key) and Google reCAPTCHA render (site key; www.google.com and www.recaptcha.net). Cookiebot, Zendesk and hCaptcha were considered and left out because I could not confirm a first-party statement that the value in the URL is public.

Acceptance criteria

  • The Mida repro produces no security/leaked-secrets finding. Test: the Mida optimize.js repro reports nothing in packages/rules/tests/leaked-secrets.test.ts. The fixture uses a value shape the rule does flag (a DigitalOcean Spaces key shape, medium), because the issue's literal sample value does not match any pattern on current main.
  • The suppression is a table-driven rule for the query parameter of a src or href, not a one-off for Mida. Evidence: PUBLIC_URL_IDENTIFIERS in packages/rules/src/security/leaked-secrets.ts; tests loop over every vendor case with both src and href, and one test asserts every table row is exercised.
  • A secret-shaped value in the same parameter on an unknown host is still reported, and a real secret elsewhere on the page is still reported. Tests: still reported: … (unknown host, lookalike host suffix and prefix, userinfo, port, host inside another URL's path, other path, other param, param name case), a vendor URL does not hide a real secret elsewhere on the page, the same value outside the vendor URL is still reported, a longer secret that contains the identifier is not hidden by it, a secret in a non-identifier parameter of a vendor URL is still reported.
  • Table-driven tests cover the Mida repro, at least two other vendors (Klaviyo, reCAPTCHA), an unknown host with the same parameter name, and the existing corpus tests pass unchanged. Ran tests/security/leaked-secrets.test.ts (2276 tests, 0 fail), tests/leaked-secrets.test.ts, literal-prefilter, secrets-confidence, rule-time-budget and redos-recheck, each on its own.
  • docs/rules/security/leaked-secrets.mdx lists the vendor identifiers that are not reported and how to extend the list. Section: "Vendor identifiers in script URLs are not reported".

Checks run

  • bun run typecheck in packages/rules
  • make validate in docs
  • root bun run format:check
  • detect-secrets-hook against .secrets.baseline (fixture values carry inline pragma allowlist comments; the baseline change is line numbers only)

Notes

  • I could not reproduce the finding with the sample key in the issue, and the reporter's real key is redacted, so I do not know which pattern fired for it. The suppression is pattern-independent (it drops any match inside the identifier span), so it covers whichever pattern it was.
  • Suppressed values are not listed under leaked-secrets-public either, following the issue's "no finding".

Agent skill

No change needed to the squirrelscan agent skill: no CLI flag, output field or workflow changed.


Generated by Claude Code

…eaked-secrets

Add a table-driven list of vendor identifiers that ship in the query of a
script or link URL (Mida key, Klaviyo company_id, reCAPTCHA render). A match
lying wholly inside one of those parameter values on the exact vendor host
and path is not reported. The same parameter on other hosts, other values on
the page and longer secrets that contain the value are still scanned.

Refs #574

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

nc9 commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor Author

Status: implementation, tests and docs are pushed. Waiting for the bot review; I will address critical, high and medium findings and will not merge.

@claude

claude Bot commented Oct 8, 2026

Copy link
Copy Markdown

Review of #584 (vendor public identifiers in leaked-secrets). The change is well scoped and I found nothing blocking. The matching is positional and exact, and the negative tests cover the lookalike-host, userinfo, port and nested-URL cases. I read the diff only and did not run the tests.

  • (low) leaked-secrets.ts publicUrlIdentifierSpans: the query is split on a literal &. In real HTML the attribute is often written ?v=2&amp;company_id=XYZ. The segment then reads amp;company_id and never matches, so the false positive remains for those pages. Decoding &amp; (or treating &amp; as a separator) would close this, and a test with &amp; would show it. If the value is the first parameter it works as is.
  • (low) leaked-secrets.ts publicUrlIdentifierSpans: percent-encoded or JSON-escaped URLs are not handled. \\/\\/cdn.mida.so in inline JSON stops at the \\ terminator, and the // check also fails there. That is fine as a conservative default, but the docs could say that only literal src and href URLs are covered.
  • (nit) The docs say "a src or href", but the scan is not tied to the attribute. Any //host/path?param=value token in the content that is preceded by one of :, whitespace, a quote, (, = or , is suppressed, including inside JS strings or prose. That is harmless because the host, path and param are exact, but the wording could match the behaviour.
  • (nit) publicSpans.some(...) runs per match. It is linear and the span list is tiny, so there is no practical cost. The PUBLIC_URL_MAX_PER_HOST and length caps bound the work on adversarial content.
  • (nit) The "every table row is exercised" test only checks that one host of each entry appears in the cases. It does not check every host or path, so /recaptcha/api.js and /recaptcha/enterprise.js are each covered but nothing enforces that a new host or path gets a case.

Test coverage is good. Docs and baseline updates look consistent.

nc9 commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor Author

Thanks for the review. No critical, high or medium findings, so no push for this round.

  • &amp; separator (low): checked, not an issue. Entities are decoded before the scan (decodeForLocation), so ?v=2&amp;company_id=<secret-shaped value> reports nothing, both through scanContent on the raw HTML and through scanPageForSecrets on a parsed page. The case would be worth a test; I will add it with the next push if one is needed.
  • JSON-escaped \/\/ URLs (low): intentionally conservative, a missed suppression only keeps today's behaviour.
  • Docs wording and the table-row coverage test (nits): left as is for this round.

@claude

claude Bot commented Oct 8, 2026

Copy link
Copy Markdown

Review of #584 (vendor public identifiers in URL queries, leaked-secrets)

I read the diff only and did not run the tests. I found no blocking problems. The suppression is positional and exact: host, path and param must all match, and a finding is dropped only if it lies wholly inside the value span. The negative tests cover lookalike hosts, userinfo, port, other path, other param and param-name case.

  • (low) leaked-secrets.ts publicUrlIdentifierSpans: the query is split on a literal &. In HTML source an href is often written ?v=2&amp;key=VALUE. The param name then reads as amp;key, so the suppression misses and the false positive from security/leaked-secrets: Mida optimize.js public project key in script src flagged as secret #574 comes back. The first param is unaffected. Consider also splitting on &amp;, or add a test that documents the current behaviour.
  • (low) URL_TOKEN_END_RE does not stop at a backtick or ;. In a JS template literal (...?key=X) the span would include the closing backtick. The start+length <= to check still works because the span is wider than the match, so this only matters if the value is a strict substring. This is a small imprecision, not a bug.
  • (low) Any content inside the whitelisted param is suppressed, whatever its shape. For example, cdn.mida.so/js/optimize.js?key=sk_live_... is hidden. That is intended and documented. A page could use it to hide a real secret, but only inside that value. Worth keeping in mind when adding rows.
  • (nit) The test every table row is exercised only checks that some host appears in the covered prefixes. It does not check paths or params, so a row with a wrong path would still pass. Asserting that each entry's host+path?param= appears in a case would match the test's name.
  • (nit) publicSpans.some(...) runs per match, so it is linear in the number of spans. It is capped at 64 spans per host, so the cost is fine. Skipping the call when publicSpans.length === 0 would be a micro-optimisation, not needed.
  • (nit) The PR notes that the issue's literal sample does not match any pattern, so the real trigger is unconfirmed. The fix is pattern-independent, so that is fine. Consider asking the reporter to confirm after release.

Performance: one indexOf per host per scanned content. That is negligible, and the 64-hit and 2048-char bounds prevent pathological input. No security concerns beyond the above. Docs and tests are thorough.

@claude

claude Bot commented Oct 8, 2026

Copy link
Copy Markdown

Review of #584 (vendor public identifiers in script URLs).

I read the diff and did not run the tests. Overall the design is sound: it is positional and exact, the scan is bounded, and the tests cover lookalike hosts, userinfo, ports and case. I found no blocking issues.

  • (low) leaked-secrets.ts publicUrlIdentifierSpans: the lead-character check accepts =, : and , before //host. A vendor URL nested in another URL's query (https://evil.test/r?u=//cdn.mida.so/js/optimize.js?key=SECRET) is therefore treated as a vendor URL, and a secret in its key value is suppressed. The impact is a narrow false negative. Tightening the lead set, or checking that // is preceded by scheme:, a quote or whitespace, would close it. A test for this case would be useful either way.
  • (low) Host matching is case-sensitive, so HTTPS://CDN.MIDA.SO/... is not suppressed. That fails safe (it over-reports), but hostnames are case-insensitive. Consider lowercasing the host portion, or note the limitation in the docs.
  • (nit) The "every table row is exercised" test only checks that hosts.some(...) appears in the case prefixes. It does not check that every host, path and param is covered. For example, /recaptcha/api.js is exercised but /recaptcha/enterprise.js is only covered through the recaptcha.net row. Asserting on host and path per row would make the guard stronger.
  • (nit) insidePublicIdentifier is a linear some per candidate match. That is fine given the span cap (64 per host), but an early return when publicSpans.length === 0 is cheap. It would also skip the closure on the hot path.
  • (nit) A comment on the .secrets.baseline line-number churn is unnecessary. Be aware that it will conflict whenever leaked-secrets.ts changes above line 2189.

@nc9
nc9 merged commit 8a80d04 into main Oct 8, 2026
15 checks passed
@nc9
nc9 deleted the claude/leaked-secrets-public-ids-1vlgjw branch October 8, 2026 14:56
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]>
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