Skip to content

feat(audit): detect exposed secrets and credentials in scanned files - #1969

Merged
lex00 merged 1 commit into
mainfrom
feat/443-audit-secrets-detection
Aug 26, 2026
Merged

lex00 merged 1 commit into
mainfrom
feat/443-audit-secrets-detection

Conversation

@lex00

@lex00 lex00 commented Aug 26, 2026

Copy link
Copy Markdown
Contributor

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 under packages/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 token
  • SEC009 — 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 and docs/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 in secrets.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 in JSON.stringify(findings).

Ignore/allow mechanics

  • Inline marker — a comment containing 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.
  • Config allowlist — a .chant-audit.json at the audited root, with secrets.allow entries keyed by ruleId/fingerprint (and optionally file). The fingerprint is copied from the finding's own output, so allowlisting a false positive never means writing the secret into the config. file alone 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 new secrets.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 via just _ensure-gen) — 318/328 files passing; the 10 pre-existing failures (ajv/dist/2020 resolution, missing @intentius/chant-lexicon-aws workspace link, missing tsx binary, an ajv iri-reference format schema error) are present identically on main with this branch's changes stashed — confirmed via git stash -u + rerun, unrelated to this change
  • npx tsc --noEmit -p packages/core/tsconfig.json — same pre-existing ajv-related errors as main, nothing new
  • docs/src/content/docs/lint-rules/audit-rules.mdx regenerated from the catalog (drift test in rules-doc.test.ts passes)

Fixes #443

🤖 Generated with Claude Code

…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>
@lex00
lex00 merged commit 50de581 into main Aug 26, 2026
6 checks passed
@lex00
lex00 deleted the feat/443-audit-secrets-detection branch August 26, 2026 19:21
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.

Detect exposed secrets and credentials in scanned files

1 participant