Skip to content

Flag Magic sk_ secret keys in Gitleaks - #1143

Merged
pws-kj merged 2 commits into
masterfrom
karl/gitleaks-magic-secret-key
Dec 2, 2026
Merged

pws-kj merged 2 commits into
masterfrom
karl/gitleaks-magic-secret-key

Conversation

@pws-kj

@pws-kj pws-kj commented Dec 2, 2026 •

Copy link
Copy Markdown
Contributor

📦 Pull Request

Gitleaks catches Magic secret keys only through its default Stripe rule (stripe-access-token). That rule matches the old sk_live_ keys by accident and misses the new sk_v2_ + 64 hex keys from magiclabs/dashboard-api#499. The default generic-api-key rule catches a key only in a KEY=value style assignment.

  • New magic-secret-key rule: (?i)\b(sk_[a-z0-9_]{16,99})\b, keyword sk_. It matches any sk_ key, so both the old sk_live_ keys and the new sk_v2_ keys are caught by a Magic rule rather than by the Stripe one. It is case-insensitive because the backends resolve a key by the SHA-256 of its uppercased value, so SK_V2_… and the lowercase form are the same key.
  • Real Stripe sk_live_/sk_test_ keys now also match this rule, alongside stripe-access-token.

CI config only, so skip-release.

🚨 Test instructions

Gitleaks runs in CI only. The rules' regexes (this file plus the 8.24.3 default config) ran through Go's regexp, the RE2 engine Gitleaks uses, against sample strings:

  • With the earlier sk_v2_-only rule: sk_live_ + 16 hex and sk_live_ + 32 hex, as a quoted string, an env line and bare text, matched only stripe-access-token.
  • With this rule: those four, plus sk_v2_ + 64 hex as a string, an env line, lowercase and SK_V2_, all match magic-secret-key. The sk_live_XXXXXXXX and sk_v2_XXXXXXXX doc placeholders and a bare "sk_" match nothing.
  • Across dashboard-api, toaster, fridge, nft-api and the three repos here, the rule matches no code identifiers; outside real-key shapes it matches only test placeholders such as sk_live_supersecret.

No sample key is committed.

🤖 Generated with Claude Code

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@pws-kj pws-kj added the skip-release Preserve the current version when merged label Dec 2, 2026
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@pws-kj pws-kj changed the title Flag Magic sk_v2_ secret keys in Gitleaks Flag Magic sk_ secret keys in Gitleaks Dec 2, 2026
@pws-kj
pws-kj added this pull request to the merge queue Dec 2, 2026
Merged via the queue into master with commit 8da5458 Dec 2, 2026
11 checks passed
@pws-kj
pws-kj deleted the karl/gitleaks-magic-secret-key branch December 2, 2026 20:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

skip-release Preserve the current version when merged

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants