Skip to content

fix(scanner): detect Stripe secret keys and match secret file names case-insensitively - #268

Closed
Bhishamt wants to merge 2 commits into
Sandesh13fr:mainfrom
Bhishamt:fix/scanner-secret-patterns
Closed

Bhishamt wants to merge 2 commits into
Sandesh13fr:mainfrom
Bhishamt:fix/scanner-secret-patterns

Conversation

@Bhishamt

Copy link
Copy Markdown

What changed?

Two false negatives in packages/scanner/src/classifyFile.ts, both reported as security issues:

  • [Security] Stripe secret keys are not detected: pattern expects sk-live_ but Stripe uses sk_live_ #251: SECRET_CONTENT_PATTERNS had /sk-(?:live|test|prod|dev)_[A-Za-z0-9]{20,}/, with a
    hyphen. Stripe spells its keys with an underscore (sk_live_, sk_test_, and the restricted
    rk_live_ / rk_test_), so a file holding STRIPE_KEY=sk_live_... was classified as ordinary
    source and could reach a repo map or a report. The pattern is now
    /(?:sk|rk)[_-](?:live|test|prod|dev)_[A-Za-z0-9]{20,}/: sk and rk with live or test on
    either separator, and the dashed sk-live_ form the old pattern matched still matches.
    Publishable keys (pk_) are not flagged.
  • [Security] Secret filename matching is case-sensitive #254: matchesGlob() compared basenames case-sensitively. On the default Windows and macOS
    filesystems .ENV, ID_RSA, Credentials.json and server.PEM name the same sensitive files,
    but only the lower-case spelling was flagged. Secret filename globs now match case-insensitively.
    The literal prefix check that decides whether a name looks sensitive is unchanged, so a file
    still has to be shaped like a secret before the glob is consulted.

Both are detection-only: nothing that was previously flagged stops being flagged, and the
classification result type is unchanged.

Fixes #251
Fixes #254

Contribution prerequisite

  • I starred the TCalc repository before starting this contribution.
  • I checked the issue and existing PRs for overlapping work. I understand that assignment is not required and any contributor may propose a focused solution.
  • This PR targets the Development branch, as the template asks. It targets main instead, see below.

Development is currently 14 commits behind main, and packages/scanner differs substantially
between them, including the file this PR edits, so a branch based on Development would carry
work missing from main and edit a stale copy of the scanner. The change is based on main, where
the reported code is. Retarget with one click if you would rather land it on Development and
merge forward.

Affected areas

  • CLI
  • MCP server / agent integrations
  • Web / dashboard
  • VS Code extension
  • JetBrains plugin
  • Shared package, packages/scanner
  • GitHub Action / CI / release
  • Documentation / catalog data

Validation

npx vitest run packages/scanner/tests/classifyFile.test.ts   -> 34 passed
pnpm test                                                    -> 302 passed, 2 failed
pnpm build                                                   -> all packages, no errors
pnpm lint                                                    -> all packages clean
pnpm typecheck                                               -> all packages clean

The two pnpm test failures are in apps/cli/tests/catalogCommand.test.ts (catalog validation:
valid: true and modelCount >= 20). They are not this change: running that file with
packages/scanner reverted to main reproduces both, in the same build, in this environment.

  • Regression test added for both behaviours
  • Relevant focused tests passed
  • pnpm build
  • pnpm test reports 302 passed and 2 failures, both pre-existing in an unrelated package
  • pnpm lint
  • pnpm typecheck
  • CLI/MCP smoke not applicable: no CLI surface changes

Review notes

  • Privacy, security, compatibility, or breaking-change impact: detection only widens. rk_ keys
    and mixed-case secret filenames are newly flagged, which is the point of both issues. No
    exported type, function signature or default changed.
  • Documentation updated (or not needed because): the pattern list is internal to
    classifyFile.ts and is not listed anywhere in the docs.
  • Screenshots: not applicable.

The tests are parameterised over the exact spellings in the issues, and include the negative
cases (pk_live_ is not flagged, docs/README.md is still not a secret) and a positive case for
the dashed form, so the looser patterns cannot silently over-match or drop the old behaviour.

The secret-content pattern was written as `sk-(?:live|test|prod|dev)_`,
which needs a hyphen after `sk` and so matched no Stripe key at all: real
keys read `sk_live_`/`sk_test_`, and restricted keys read `rk_live_`
and `rk_test_`. Publishable keys (`pk_`) stay undetected, as they are
not secrets.

The existing test only passed because it used the same malformed prefix.
Secret file names were compared as written, so a repository could ship
`ID_RSA`, `CERT.PEM` or `Credentials.JSON` and the scan reported no
secret risk: the glob ran on the exact-case name. Both sides are now
lower-cased, which is also how the file systems these scans run on treat
them.
@vercel

vercel Bot commented Nov 13, 2026

Copy link
Copy Markdown

@Bhishamt is attempting to deploy a commit to the Sandesh's projects Team on Vercel.

A member of the Team first needs to authorize it.

@qodo-code-review

Copy link
Copy Markdown

ⓘ Qodo reviews are paused because your trial has ended. Ask your workspace admin to add credits to resume reviews. Manage billing

@github-actions

Copy link
Copy Markdown

This PR was closed by the contribution policy:

Please resolve the items above, then reopen the PR.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 13, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-13T12:24:18.266313Z 4512a06 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@github-actions github-actions Bot closed this Nov 13, 2026
@coderabbitai

coderabbitai Bot commented Nov 13, 2026 •

Copy link
Copy Markdown

Explain Change →

Caution

Review failed

The pull request is closed.

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

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

Labels

None yet

Projects

None yet

1 participant