Skip to content

security/leaked-secrets: placeholder and documentation examples still reported (localhost connection string, vendor sample key, bare PEM header, example-password) #1227

Closed

Description

@nc9

Observed on squirrel v0.0.138; packages/rules/src/security/leaked-secrets.ts is unchanged since on main. I checked each case against the shipped binary with a local page, so this lists only what still fires. Cases that earlier work already handles (API_KEY="YOUR_API_KEY", apiKey = "your-api-key-here", postgres://app:[email protected]:5432/prod, Password: ••••••••) no longer report and need no change.

Still flagged: placeholders and documentation examples

Each snippet is placed in its own inline <script>; all hosts and values are made up.

Snippet Reported as
var u = "postgres://user:s3cret@localhost:5432/app"; PostgreSQL Connection String, in leaked-secrets-high (fail)
var s = "curl https://api.example.com/v1/charges -u sk_test_<the sample key printed in Stripe's own API reference>:"; Stripe Test Key, leaked-secrets-high (fail)
var h = "Paste your key, it starts with -----BEGIN OPENSSH PRIVATE KEY-----"; (UI help text or an input placeholder; no key material follows) Private Key (OpenSSH), leaked-secrets-high (fail)
var o = { password: 'example-password' }; (SDK JSDoc style example) Generic Secret Assignment, leaked-secrets-medium (warn)

Why these are noise: a connection string pointing at localhost with a short human word as the password is documentation, not a credential; a published vendor sample key is public by definition and unusable; a PEM header with no base64 body is not a private key; example-password names itself as an example.

Expected

  • A PEM header counts only when a base64 body follows (at least one plausible line of base64 and, ideally, the matching -----END ...-----), for every Private Key (...) pattern.
  • A connection string whose host is localhost, 127.0.0.1, *.internal, *.local, *.test or *.example is treated as a placeholder, like example.com already is.
  • The placeholder-word list covers example-*, sample-*, changeme and s3cret-style leetspeak words, and the vendor-published sample keys (an allowlist of exact documented values) are suppressed.

Acceptance Criteria

  • None of the four snippets above produces an item in security/leaked-secrets (fixture test per snippet).

  • A real-shaped PEM block (header, base64 body, footer) is still reported as a private key.

  • A connection string with a non-local host and a high-entropy password is still reported.

  • The existing placeholder fixtures (YOUR_API_KEY, your-api-key-here) still pass.

  • A PEM block whose body is elided (..., MIIE...) or under 64 base64 chars is not reported (fixture). (amended 2026-11-01: the floor is 32 base64 characters in a run, as built and tested: 31 stay silent, 32, 40 and 63 report, and a test pins that two 40-character lines report.)

  • A connection string whose user, password or host contains ${, {{, %s or <…> is not reported (fixture from a bundled driver's template literal), and a password-less redis://host:port/ isn't a secret.

  • Stripe's published documentation key is suppressed in its sk_live_/rk_live_ variants as well as sk_test_.

  • Bearer followed by a placeholder (YOUR_*, PASTE_*, <…>, {{…}}, xxx…) is not reported (fixture).

  • A JWT that is only a header segment (no payload or signature) is not reported (fixture).

  • A live-shaped token (sk_live_, ghp_, an AKIA pair, a PEM with a body) inside <pre>/<code> is still reported at its normal confidence: a secret pasted into a docs block is still a leak; only the documented exact-match samples (vendor doc sample keys, the jwt.io sample token, bodiless PEM headers, placeholder words) are dropped (amended 2026-11-01, replaces the downgrade-to-info criterion)

Activity

  1. added
    bug
    size: M
    rules
    security
    on Oct 28, 2026
  2. added theissue type on Oct 28, 2026
  3. nc9 commented on Oct 29, 2026

    @nc9
    ContributorAuthor

    Corpus evidence from a ~38k-site batch (v0.0.141, up to 200 first-party scripts per site, hand-triaged with masked context; no credential used or tested):

    • Bare PEM headers: 41 of 41 Private Key (RSA/OpenSSH/EC/PGP) flags were false positives. They came from input placeholders and labels (placeholder:"-----BEGIN RSA PRIVATE KEY-----\n..."), other scanners' rule tables (/-----BEGIN (?:RSA )?PRIVATE KEY-----/g), key-type validators, and docs with elided bodies (MIIE...). This confirms the PEM-body requirement here. Add: skip bodies that contain ... or other elisions.
    • Templated connection strings: 27 flags (1 real). Most were postgresql://${encodeURIComponent(user)}:${encodeURIComponent(password)}@${host}/${db} inside bundled DB-driver code (11 rows from 6 different driver builds), compose/deploy docs (DATABASE_URL=postgres://app:pw@service-name:5432/db) and password-less redis://redis7:6379/.
    • Stripe's documentation key with a sk_live_ prefix, as used in redaction demos (2 rows). The current allowlist covers only the sk_test_ form.

    Adding criteria for these to the checklist.

  4. nc9 commented on Oct 29, 2026

    @nc9
    ContributorAuthor

    More corpus evidence (hand-verified JWT/bearer and generic-secret lanes, v0.0.141, masked, nothing used): documentation and code-block examples are a large false-positive class that a value-only check can't separate. It needs code-block / docs context:

    • Bearer YOUR_TOKEN, Bearer PASTE_*, Authorization: Bearer <token> in docs and MCP-config snippets: 39 flags.
    • Realistic-looking prefixed keys in curl -H 'x-api-key: …' and MCP headers: examples on docs pages: 24 flags.
    • Truncated JWT samples (Bearer eyJhbGciOiJIUzI1NiIs, header only) in tutorials and glossaries: 10 flags.
    • .env / test-runner examples inside <pre>/<code> blocks: 45 flags on 27 sites.

    Adding criteria.

  5. nc9 commented on Nov 1, 2026

    @nc9
    ContributorAuthor

    Amended acceptance criterion: the third criterion (values inside <pre>/<code> on docs-like pages downgraded to an info note) is descoped. A secret pasted into a docs block is still a leak, and a downgrade by context would also hide real tokens that sit in a docs-looking page. The criterion now says a live-shaped token inside <pre>/<code> is still reported at its normal confidence, and only the documented exact-match samples (vendor doc sample keys, the jwt.io sample token, bodiless PEM headers, placeholder words) are dropped. A probe on the stack's first PR confirms a live-shaped sk_live_ and ghp_ token inside <pre><code> is still reported.

    nik

  6. nc9 commented on Nov 1, 2026

    @nc9
    ContributorAuthor

    Amended the PEM criterion to the shipped floor: a body of fewer than 32 base64 characters in a run is not reported (31 silent; 32, 40 and 63 report; a test pins that two 40-character lines report). The other criteria are ticked as met on v0.0.158. One criterion stays open: a header-only JWT after Bearer (Bearer eyJ... with no dot) still reports at medium; a fix is in progress.

    nik

  7. nc9 commented on Nov 2, 2026

    @nc9
    ContributorAuthor

    Shipped in v0.0.159 and checked against it: every acceptance criterion is met, including the last open one. A header-only Bearer eyJ... value (a bare header, a truncated header, a full header with no dot) is no longer reported, while an opaque base64url JSON bearer, a full JWT after Bearer, and a %2E- or comma-separated JWT after Bearer still report. Release: https://github.com/squirrelscan/squirrelscan/releases/tag/v0.0.159

    nik

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugrulessecuritysize: M

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions