feat(secrets): Betterleaks instead of gitleaks, findings carry over (#516) #517

Merged
sharang merged 1 commits from feat/516-betterleaks into main 2026-10-06 15:59:11 +00:00
Owner

Closes #516: secret scanning moves from gitleaks 8.21.2, which is feature-frozen, to Betterleaks 1.9.0. Betterleaks is MIT and comes from gitleaks' author. Live verification stays out of scope.

What

  • Agent image: Betterleaks pinned by version and sha256 from the release checksums, instead of gitleaks. tool-versions.json lists betterleaks.
  • Scanner:
    • Our rules/gitleaks.toml is passed unchanged with --config, including the #464/#482 allowlists. A repository's .gitleaks.toml or .betterleaks.toml cannot override it; a test covers both.
    • A git checkout is scanned with git . (Betterleaks has no detect), a plain tree with dir .. The JSON report shape matches gitleaks'.
  • No validation: Betterleaks validates only when --validation is passed. That's a CLI flag, not bound to any environment variable or config (checked in its source, cmd/root.go, detect/detect.go). We never pass it, a unit test pins that, and the fixture comparison ran in a network namespace without network.
  • Continuity: findings keep the scanner name gitleaks (finding_store::SECRET_SCANNER), so content fingerprints (#491) and tracker issues carry over for every rule that kept its id.
  • Renamed rules: RunFindings::adopt_renamed_secrets handles a secret now reported under a different rule. It hands over the stored row with the same target, file and match, provided this run no longer finds that row under its old rule. The row keeps its id, status, triage and issue, and takes the new rule, title, description and severity. Cases this covers:
    • a lone AWS key id: Betterleaks' aws-access-token is a composite that needs the secret key, so the lone id comes out as generic-api-key;
    • gitleaks rules with no exact counterpart: datadog-access-token, etsy-access-token, jfrog-*.

Comparison (gitleaks 8.21.2 vs Betterleaks 1.9.0, our config)

  • Fixture trees: identical rule, file and line on all 15 trees with secret findings, except fixtures/nightly/firmware/c-sensor-node. There Betterleaks also finds the two planted hard-coded passwords (generic-password, cli.cpp:8, comms.c:9); its nightly baseline is updated.
  • Git history: same findings and commits, except the lone AWS key id described above.
  • Rule counts: Betterleaks has 466 rules, about 270 more than gitleaks.

Tests

  • tests/secret_rules.rs (Mongo):
    • a secret whose rule changed keeps its row and its "accepted risk" status, with no close or reopen;
    • a secret still found under its old rule keeps that row, and the new rule's finding is a row of its own.
  • The existing store tests (content_fingerprints, resolve_findings, group_*, finding_migrations, live_findings, finding_variants) pass, and so do the scanner unit tests including the mobile-secrets test against the real binary.
  • clippy -D warnings for the agent.

Docs: tools.md (the section, the differences, no validation) and the guides. Test plan check 33, marked [visible]. Stage only; no tag.

🤖 Generated with Claude Code

https://claude.ai/code/session_01EYKjxacrr6K88DruUmP48p

Closes #516: secret scanning moves from gitleaks 8.21.2, which is feature-frozen, to **Betterleaks 1.9.0**. Betterleaks is MIT and comes from gitleaks' author. Live verification stays out of scope. ## What - **Agent image:** Betterleaks pinned by version and sha256 from the release checksums, instead of gitleaks. `tool-versions.json` lists `betterleaks`. - **Scanner:** - Our `rules/gitleaks.toml` is passed unchanged with `--config`, including the #464/#482 allowlists. A repository's `.gitleaks.toml` or `.betterleaks.toml` cannot override it; a test covers both. - A git checkout is scanned with `git .` (Betterleaks has no `detect`), a plain tree with `dir .`. The JSON report shape matches gitleaks'. - **No validation:** Betterleaks validates only when `--validation` is passed. That's a CLI flag, not bound to any environment variable or config (checked in its source, `cmd/root.go`, `detect/detect.go`). We never pass it, a unit test pins that, and the fixture comparison ran in a network namespace without network. - **Continuity:** findings keep the scanner name `gitleaks` (`finding_store::SECRET_SCANNER`), so content fingerprints (#491) and tracker issues carry over for every rule that kept its id. - **Renamed rules:** `RunFindings::adopt_renamed_secrets` handles a secret now reported under a different rule. It hands over the stored row with the same target, file and match, provided this run no longer finds that row under its old rule. The row keeps its id, status, triage and issue, and takes the new rule, title, description and severity. Cases this covers: - a lone AWS key id: Betterleaks' `aws-access-token` is a composite that needs the secret key, so the lone id comes out as `generic-api-key`; - gitleaks rules with no exact counterpart: `datadog-access-token`, `etsy-access-token`, `jfrog-*`. ## Comparison (gitleaks 8.21.2 vs Betterleaks 1.9.0, our config) - **Fixture trees:** identical rule, file and line on all 15 trees with secret findings, except `fixtures/nightly/firmware/c-sensor-node`. There Betterleaks also finds the two planted hard-coded passwords (`generic-password`, `cli.cpp:8`, `comms.c:9`); its nightly baseline is updated. - **Git history:** same findings and commits, except the lone AWS key id described above. - **Rule counts:** Betterleaks has 466 rules, about 270 more than gitleaks. ## Tests - `tests/secret_rules.rs` (Mongo): - a secret whose rule changed keeps its row and its "accepted risk" status, with no close or reopen; - a secret still found under its old rule keeps that row, and the new rule's finding is a row of its own. - The existing store tests (`content_fingerprints`, `resolve_findings`, `group_*`, `finding_migrations`, `live_findings`, `finding_variants`) pass, and so do the scanner unit tests including the mobile-secrets test against the real binary. - clippy `-D warnings` for the agent. Docs: tools.md (the section, the differences, no validation) and the guides. Test plan check 33, marked [visible]. Stage only; no tag. 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01EYKjxacrr6K88DruUmP48p
sharang added 1 commit 2026-10-06 15:46:38 +00:00
feat(secrets): Betterleaks instead of gitleaks, findings carry over (#516)
CI / Check (push) Skipped
CI / Detect Changes (pull_request) Skipped
CI / Deploy Agent (pull_request) Skipped
CI / Deploy Dashboard (pull_request) Skipped
CI / Deploy Docs (pull_request) Skipped
CI / Deploy MCP (pull_request) Skipped
CI / Check (pull_request) Successful in 11m59s
ee30ecfddb
- The agent image ships Betterleaks 1.9.0 (MIT, gitleaks' successor by its
  author; pinned with checksum) instead of gitleaks 8.21.2. It reads our
  rules/gitleaks.toml unchanged, incl. the #464/#482 allowlists; `git .`
  replaces `detect --source .`, `dir .` stays. Live validation (which sends
  secrets to their providers) is never passed and a test pins that; the
  scan runs without network.
- The findings keep the scanner name `gitleaks` (finding_store::
  SECRET_SCANNER), so fingerprints (#491) and tracker issues carry over.
- RunFindings::adopt_renamed_secrets: a secret now reported under another
  rule (Betterleaks' composite aws-access-token reports a lone key id as
  generic-api-key; renamed vendor rules) takes over the stored row of the
  same target, file and match whose old rule no longer reports it: same id,
  status, triage and issue, with the new rule, title and severity.
- Compared on every fixture tree: identical results, except two planted
  hard-coded passwords Betterleaks finds in the C firmware fixture
  (generic-password), added to its nightly baseline.
- Docs (tools, guides), test plan check 33.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EYKjxacrr6K88DruUmP48p
sharang merged commit d96509db8c into main 2026-10-06 15:59:11 +00:00
Sign in to join this conversation.