Repository navigation
feat(audit): detect exposed secrets and credentials in scanned files - #1969
Merged
Merged
Conversation
…ndings Adds a lexicon-independent finding family (#443): pattern detectors for provider keys/tokens (AWS, GitHub, Slack, Google, Stripe), PEM private-key blocks, and credential-bearing connection strings, plus a tunable high-entropy heuristic catch-all (SEC001-SEC010). Scans the raw text of every file the audit already reads, so it fires regardless of which (or whether any) lexicon is installed. Findings never carry the matched value — only rule id, kind, file/line, and a non-reversible fingerprint — enforced by a dedicated redaction test. Suppression: an inline `chant-audit-ignore` comment marker, or a `.chant-audit.json` config allowlist keyed by rule id / fingerprint (never the secret itself). Test fixtures use concatenation-built (never contiguous-literal) fake values so this commit's own diff doesn't trip GitHub's secret-scanning push protection on what are just realistic-shaped examples. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This was referenced Aug 26, 2026
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
New finding family for
chant audit(#443): detects likely secrets and credentials in every file the audit already scans, independent of lexicon — it fires even when no lexicon is installed. Lives entirely underpackages/core/src/audit/(secrets.ts), pure (no fs/network/Node-only APIs) so it runs in the hosted service's Workers runtime as well as the CLI.Detectors (
SEC001–SEC010)SEC001— AWS access key ID (AKIA…and sibling prefixes)SEC002— AWS secret access key (contextual,aws_secret_access_key = …)SEC003— GitHub token (ghp_/gho_/ghu_/ghs_/ghr_)SEC004— Slack token (xox[baprs]-…)SEC005— Google API key (AIza…)SEC006— Stripe live secret key (sk_live_…/rk_live_…)SEC007— PEM private key block (-----BEGIN … PRIVATE KEY-----)SEC008— Bearer/authorization tokenSEC009— Credentials embedded in a connection string (scheme://user:pass@host)SEC010— High-entropy string catch-all (tunable threshold/min-length; skips pure-hex runs and dashed/slashed identifiers like a model id or package spec to stay conservative)All ten are cataloged in
catalog.ts(merge-worthy, guidance fix, security category, cite GitHub's secret-scanning docs as authority) and documented in the audit rules reference anddocs/cli/audit.mdx.Redaction guarantee
A finding's
message,entity, and every other field never contain the matched value — only the rule id, a human label for the kind of secret, file/line location, and a non-reversible fingerprint (two intertwined 32-bit hashes, not a matched-value echo). Tested explicitly insecrets.test.ts's "redaction guarantee" suite: it builds content containing every detector's example secret, scans it, and asserts none of those literal values appear anywhere inJSON.stringify(findings).Ignore/allow mechanics
chant-audit-ignore(optionally scoped:chant-audit-ignore: SEC001,SEC010) on the flagged line, or the line above it (for a PEM block whose-----BEGIN…-----line can't carry a trailing comment), suppresses the finding..chant-audit.jsonat the audited root, withsecrets.allowentries keyed byruleId/fingerprint(and optionallyfile). The fingerprint is copied from the finding's own output, so allowlisting a false positive never means writing the secret into the config.filealone never blanket-suppresses everything in a file.Both are wired into
chant audit(CLI): secrets scanning runs on every candidate file (now including.env*,.pem,.key,.crt,.cer,.pfx,.p12, in addition to the existing YAML/JSON/Dockerfile/Chart.yaml set) and its findings ride alongside lexicon findings in every report format (stylish, json, sarif, markdown, html) — including when zero lexicons are installed, since this family doesn't depend on one.Test plan
CHANT_SKIP_ARTIFACT_CHECK=1 npx vitest run packages/core/src/audit— 14 files, 187 tests passing (includes the newsecrets.test.ts: 37 tests covering each detector's positive/negative, entropy tunability, the identifier-slug false-positive guard, redaction, the inline marker, and the config allowlist)CHANT_SKIP_ARTIFACT_CHECK=1 npx vitest run packages/core/src/cli/commands/audit.test.ts— 36 tests passing, incl. a new "secrets detection (Detect exposed secrets and credentials in scanned files #443)" suite exercising the CLI end-to-end (no-lexicons case, alongside lexicon findings, inline marker, config allowlist, explicit option override)npx vitest run packages/core(full core suite, artifacts built viajust _ensure-gen) — 318/328 files passing; the 10 pre-existing failures (ajv/dist/2020resolution, missing@intentius/chant-lexicon-awsworkspace link, missingtsxbinary, an ajviri-referenceformat schema error) are present identically onmainwith this branch's changes stashed — confirmed viagit stash -u+ rerun, unrelated to this changenpx tsc --noEmit -p packages/core/tsconfig.json— same pre-existingajv-related errors asmain, nothing newdocs/src/content/docs/lint-rules/audit-rules.mdxregenerated from the catalog (drift test inrules-doc.test.tspasses)Fixes #443
🤖 Generated with Claude Code