Skip to content

fix(scan-secrets): portable single-quote class + hyphenated key detection#4

Merged
poshan0126 merged 1 commit into
poshan0126:mainfrom
Blur-red:fix/scan-secrets-bsd-grep-and-hyphenated-keys
Jun 12, 2026
Merged

fix(scan-secrets): portable single-quote class + hyphenated key detection#4
poshan0126 merged 1 commit into
poshan0126:mainfrom
Blur-red:fix/scan-secrets-bsd-grep-and-hyphenated-keys

Conversation

@Blur-red

@Blur-red Blur-red commented Jun 5, 2026

Copy link
Copy Markdown
Contributor

Summary

hooks/scan-secrets.sh had two gaps on macOS (BSD grep) that let real secrets through. Found while installing and live-testing the kit on macOS (BSD grep 2.6.0-FreeBSD).

Bug 1 — \x27 not portable (HIGH, macOS-only)

BSD grep does not interpret \x27 as a single-quote, so the char classes ["\x27] / [^"\x27] degraded to a literal set {" \ x 2 7}.

Consequences on macOS:

  • Single-quoted credentials slipped past entirely: password = 'supersecretvalue' → allowed.
  • Double-quoted values containing 2 or 7 were truncated below the 8-char threshold (e.g. "hunter2hunter2" matched only hunter).

Fix: replace \x27 with the portable '\'' shell idiom, yielding the class ["']. Works on both BSD and GNU grep.

Bug 2 — hyphenated keys missed (MEDIUM, cross-platform)

sk-[a-zA-Z0-9]{20,} stops at the first hyphen, so modern Anthropic keys (sk-ant-api03-...) were never matched. OpenAI-style sk-proj... (no hyphen) worked. Fix: allow hyphens — sk-[a-zA-Z0-9-]{20,}.

Tests

scan-secrets.sh previously had no fixtures. Added 10 covering: clean source, process.env reference (no false positive), double- and single-quoted credentials, hyphenated sk-ant key, AWS access key, GitHub PAT, private-key block, connection string with creds, and non-Edit/Write tool ignore.

$ bash hooks/tests/run-all.sh
RESULT: 46 passed, 0 failed   # was 36

Before → after (live repro on macOS):

input before after
password = 'supersecretvalue' exit 0 (miss) exit 2
sk-ant-api03-... exit 0 (miss) exit 2
const apiKey = process.env.API_KEY exit 0 exit 0 (no regression)

No behavior change on Linux/GNU grep beyond the hyphen fix; this aligns macOS behavior with it.

…tion

Two macOS (BSD grep) gaps in scan-secrets.sh let real secrets through:

1. \x27 is not interpreted as a single-quote by BSD grep, so the char
   classes ["\x27] degraded to a literal set {" \ x 2 7}. Single-quoted
   credentials (password = 'value') slipped past, and double-quoted values
   containing 2/7 were truncated below the length threshold. Replaced with
   the portable '\'' form yielding the class ["'].

2. sk-[a-zA-Z0-9]{20,} broke at the first hyphen, so modern Anthropic keys
   (sk-ant-api03-...) were never matched. Allowed hyphens in the class.

Adds 10 scan-secrets fixtures (hook previously had no test coverage).
Full suite: 46 passed, 0 failed.
@gitguardian

gitguardian Bot commented Jun 5, 2026

Copy link
Copy Markdown

⚠️ GitGuardian has uncovered 2 secrets following the scan of your pull request.

Please consider investigating the findings and remediating the incidents. Failure to do so may lead to compromising the associated services or software components.

Since your pull request originates from a forked repository, GitGuardian is not able to associate the secrets uncovered with secret incidents on your GitGuardian dashboard.
Skipping this check run and merging your pull request will create secret incidents on your GitGuardian dashboard.

🔎 Detected hardcoded secrets in your pull request
GitGuardian id GitGuardian status Secret Commit Filename
- - GitHub Personal Access Token 7e52a9c hooks/tests/fixtures/scan-secrets/07-block-github-token.json View secret
- - PostgreSQL Credentials 7e52a9c hooks/tests/fixtures/scan-secrets/09-block-conn-string-creds.json View secret
🛠 Guidelines to remediate hardcoded secrets
  1. Understand the implications of revoking this secret by investigating where it is used in your code.
  2. Replace and store your secrets safely. Learn here the best practices.
  3. Revoke and rotate these secrets.
  4. If possible, rewrite git history. Rewriting git history is not a trivial act. You might completely break other contributing developers' workflow and you risk accidentally deleting legitimate data.

To avoid such incidents in the future consider


🦉 GitGuardian detects secrets in your source code to help developers and security teams secure the modern development process. You are seeing this because you or someone else with access to this repository has authorized GitGuardian to scan your pull request.

@poshan0126

Copy link
Copy Markdown
Owner

Nice fix — reproduced both bugs locally. Before merge, could you run bash scripts/sync-plugins.sh and commit the result? Otherwise the vendored copy under plugins/setupdotclaude/template/hooks/ keeps the buggy version. Should be just the regenerated scan-secrets.sh plus the new fixtures dir. Thanks!

@poshan0126
poshan0126 merged commit 7e52a9c into poshan0126:main Jun 12, 2026
3 checks passed
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.

2 participants