fix: EXPOSED_SECRETS silently misses hardcoded passwords in configs#14
Open
dmchaledev wants to merge 1 commit into
Open
fix: EXPOSED_SECRETS silently misses hardcoded passwords in configs#14dmchaledev wants to merge 1 commit into
dmchaledev wants to merge 1 commit into
Conversation
extractStrings() in the parser collected config string values in
isolation, so the key-aware password pattern (password: <value>) in the
EXPOSED_SECRETS rule could never match a structured JSON/YAML config — a
hardcoded "password": "..." field was silently ignored by the CRITICAL
secret-scanning rule.
Extract object string values with their key context ("key: value") so
key-dependent patterns fire, while token-shaped patterns (sk-, ghp_,
AKIA) continue to match unanchored inside the reconstructed string.
Add src/__tests__/parser.test.ts covering the regression and confirming
no false positives on a clean config.
https://claude.ai/code/session_01BcFiXXLeus31dWFPBYALgn
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
A CRITICAL-severity false negative in the flagship secret-scanning feature: a hardcoded password in an MCP config file is not flagged by the
EXPOSED_SECRETSrule.Repro (before this PR)
Root cause
EXPOSED_SECRETS(src/rules/runtime-rules.ts) scansconfig.rawStrings, which is built byextractStrings()insrc/parser.ts. That helper collected string values in isolation:But the rule's password pattern needs the surrounding key:
Since the key (
password) was stripped away from the value, this pattern could never match a structured JSON/YAML config — it was effectively dead code for the primary use case (scanning config files). The token-shaped patterns (sk-,ghp_,AKIA) happened to still work because they match the value directly.Fix
extractStrings()now extracts an object's string value with its key context ("key: value") instead of the bare value. Key-aware patterns (like the password detector) can now match, while the unanchored token-shaped patterns continue to match inside the reconstructed string. Strings inside arrays (which have no key context) are still pushed bare.Verification
Added
src/__tests__/parser.test.ts(3 tests): the password regression, token-shaped secrets still firing insidekey: value, and no false positive on a clean config. Scoped to a new file so it does not importsrc/sarif.tsand therefore runs cleanly under the current Jest config.Note on CI
CI on
mainis currently red for an unrelated, pre-existing reason — thesrc/sarif.tsimport.meta/createRequirecompile error under ts-jest's CommonJS transform (introduced in #9, fixed by the open PR #12). That breaks thescanner.test.tsandsarif.test.tssuites regardless of this change. This PR adds no new failures: thescorerand newparsersuites pass locally (13 tests). Once #12 lands, the full suite — including the new regression test — runs green.This change is independent of #12 (CI) and #13 (docs); it touches only the parser's secret-extraction logic.
https://claude.ai/code/session_01BcFiXXLeus31dWFPBYALgn
Generated by Claude Code