feat(findings): keyed by the code they flag, not its line number (#491) #497

Merged
sharang merged 1 commits from feat/491-content-fingerprints into main 2026-10-06 10:35:14 +00:00
Owner

Closes #491. Item 1 of the OSS research's short-term list. Stage only.

Problem

Fingerprints hashed repository/rule/file/line. Since the auto-close (#443) and issue sync (#451), every line added above a finding:

  • closed it and its tracker issue;
  • reported it anew;
  • dropped its triage.

Change

  • Content-based key (finding_store::content_fingerprints).
    • RunFindings keys every finding at one place in a file by:
      • repository, scanner, rule, file;
      • the flagged line without whitespace;
      • the number of identical lines above it, so two identical lines stay two findings.
    • This is the idea behind CodeQL's primaryLocationLineHash and CodeChecker's context-free-v2. The hash is tagged content-v1.
    • It runs centrally, before grouping and on save. The scanners' own hashing is untouched except for one hunk in gitleaks.
  • Per tool: gitleaks supplies the matched secret as the content (Finding::fingerprint_content, never stored), because a hit from the git history may not be on that line of the tree any more.
  • One-time alias:
    • The replaced line-based fingerprint stays in Finding::legacy_fingerprints.
    • The first scan after deploy finds the row stored under it and takes it over instead of inserting: the fingerprint is rewritten and the old one recorded.
    • The row therefore keeps its id (and with it its tracker issue), its status (a person's decisions included) and its triage.
    • Idempotent: later scans find the new fingerprint directly.
  • Moved code: a stored finding whose code moved is updated to its new line and snippet.
  • Groups (#464/#477) keep their line-free key and never take over a member's former fingerprint (this was a real bug in the first draft).
  • Unchanged:
    • findings without file and line (CVE, malware, binaries, DAST);
    • the PLC path, which doesn't save through RunFindings; that can follow.

Scope versus the other agents' areas

Hunks touch only finding_store.rs, grouping.rs (one line), gitleaks.rs (one line), orchestrator.rs (with_tree) and Finding. Nothing in rules/vendor/, cve.rs or binaries.rs.

Tests

  • Unit:
    • a line added above and re-indentation keep the fingerprint;
    • identical lines stay distinct;
    • the old fingerprint is kept;
    • a missing file leaves the finding as it was;
    • a secret is keyed by its match (also from the history);
    • groups are untouched.
  • Mongo (tests/content_fingerprints.rs):
    • pre-change rows (one marked false positive, one open) are adopted with id and status kept and the old fingerprint recorded;
    • after lines are added above them: no new rows, no close/reopen (status_changed empty), and the line follows.
  • group_findings, group_decisions, finding_variants, resolve_findings, live_findings, finding_migrations: green.
  • fmt and clippy -D warnings: agent, core, mcp, dashboard (server and wasm).
  • Agent lib: 710 tests. Core: 85.

To check on stage

Check 18 in docs/release/staging-test-plan-after-v0.4.5.md:

  1. Rescan a target with history: nothing new, nothing closed; log … now keyed by their content with adopted=….
  2. Push lines above a finding: same finding and issue, new line; log findings whose code moved ….
  3. Duplicate a flagged line: two findings.

🤖 Generated with Claude Code

https://claude.ai/code/session_01EYKjxacrr6K88DruUmP48p

Closes #491. Item 1 of the OSS research's short-term list. Stage only. ## Problem Fingerprints hashed repository/rule/file/**line**. Since the auto-close (#443) and issue sync (#451), every line added above a finding: - closed it and its tracker issue; - reported it anew; - dropped its triage. ## Change - **Content-based key** (`finding_store::content_fingerprints`). - `RunFindings` keys every finding at one place in a file by: - repository, scanner, rule, file; - the **flagged line without whitespace**; - the **number of identical lines above it**, so two identical lines stay two findings. - This is the idea behind CodeQL's `primaryLocationLineHash` and CodeChecker's `context-free-v2`. The hash is tagged `content-v1`. - It runs centrally, before grouping and on save. The scanners' own hashing is untouched except for one hunk in gitleaks. - **Per tool:** gitleaks supplies the matched secret as the content (`Finding::fingerprint_content`, never stored), because a hit from the git history may not be on that line of the tree any more. - **One-time alias:** - The replaced line-based fingerprint stays in `Finding::legacy_fingerprints`. - The first scan after deploy finds the row stored under it and **takes it over** instead of inserting: the fingerprint is rewritten and the old one recorded. - The row therefore keeps its **id (and with it its tracker issue)**, its **status** (a person's decisions included) and its **triage**. - Idempotent: later scans find the new fingerprint directly. - **Moved code:** a stored finding whose code moved is updated to its new line and snippet. - **Groups** (#464/#477) keep their line-free key and never take over a member's former fingerprint (this was a real bug in the first draft). - **Unchanged:** - findings without file and line (CVE, malware, binaries, DAST); - the PLC path, which doesn't save through `RunFindings`; that can follow. ## Scope versus the other agents' areas Hunks touch only `finding_store.rs`, `grouping.rs` (one line), `gitleaks.rs` (one line), `orchestrator.rs` (`with_tree`) and `Finding`. Nothing in `rules/vendor/`, `cve.rs` or `binaries.rs`. ## Tests - **Unit:** - a line added above and re-indentation keep the fingerprint; - identical lines stay distinct; - the old fingerprint is kept; - a missing file leaves the finding as it was; - a secret is keyed by its match (also from the history); - groups are untouched. - **Mongo (`tests/content_fingerprints.rs`):** - pre-change rows (one marked false positive, one open) are adopted with id and status kept and the old fingerprint recorded; - after lines are added above them: **no new rows, no close/reopen** (`status_changed` empty), and the line follows. - `group_findings`, `group_decisions`, `finding_variants`, `resolve_findings`, `live_findings`, `finding_migrations`: green. - fmt and clippy `-D warnings`: agent, core, mcp, dashboard (server and wasm). - Agent lib: 710 tests. Core: 85. ## To check on stage Check 18 in `docs/release/staging-test-plan-after-v0.4.5.md`: 1. Rescan a target with history: nothing new, nothing closed; log `… now keyed by their content` with `adopted=…`. 2. Push lines above a finding: same finding and issue, new line; log `findings whose code moved …`. 3. Duplicate a flagged line: two findings. 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01EYKjxacrr6K88DruUmP48p
sharang added 1 commit 2026-10-06 10:25:46 +00:00
feat(findings): keyed by the code they flag, not its line number (#491)
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 8m19s
223db85f2a
Closes #491. Fingerprints hashed repository/rule/file/line, so since the
auto-close (#443) and issue sync (#451) every line added above a finding
closed it and its tracker issue, reported it anew and lost its triage.

- RunFindings keys every finding at one place in a file by content
  (finding_store::content_fingerprints, applied with the variant labels
  before grouping and on save): repository, scanner, rule, file, the
  flagged line without whitespace, and the number of identical lines
  above it (two identical lines stay two findings). The idea of CodeQL's
  primaryLocationLineHash and CodeChecker's context-free-v2. Version-tagged
  ("content-v1").
- Per tool: gitleaks gives the matched secret as the content
  (Finding::fingerprint_content, never stored), as a hit from the history
  may not be on that line of the tree any more.
- One-time alias: the replaced line-based fingerprint is kept
  (Finding::legacy_fingerprints); the first scan after deploy finds the
  row stored under it and takes it over (fingerprint rewritten, old one
  recorded) instead of inserting, so the row keeps its id (tracker issue),
  status (a person's decisions included) and triage. Idempotent: later
  scans find the new fingerprint directly.
- A stored finding whose code moved is updated to its new line and snippet.
- Groups (#464/#477) keep their line-free key and never take over a
  member's former fingerprint.
- Unchanged: findings without file and line (CVE, malware, binaries,
  DAST), and the PLC path, which does not save through RunFindings.
- Tests: a line added above and re-indentation keep the fingerprint,
  twins stay distinct, a secret is keyed by its match, groups untouched;
  Mongo: pre-change rows are adopted with id/status kept, a later line
  shift gives no new row and no close/reopen, the line follows.
- Docs (findings guide); staging test plan: check 18.

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