Repository navigation
Description
What happens
devops scan report keeps one trivy-config result for each rule. On 2026-11-30, trivy config found 46 failed checks in 14 files of the tree, but the report printed 8 results and "38 duplicate finding(s) collapsed". The SARIF that the Security Scan step of CI uploads holds the same 8 results, so code scanning shows one Trivy-config alert for each rule and not one for each file.
When an ignore entry or a fix removes the finding from one file, the alert of that rule moves to the next file that holds it. This made the chain of one-file judge items for KSV-0013: #7562 (cronjob-repos-drift.yaml), #7778 (cronjob-openrouter-reconcile.yaml), and then alert 263 (cronjob-runner.yaml) in #4409.
Cause
parse_trivy_json in src/devops_cli/security/trivy.py sets the location of a misconfiguration to <target>:<rule id>, for example k8s/devops/cronjob.yaml:KSV-0013. The normalizer reads the part after the colon as the symbol of the finding, so the finding has no line and the symbol KSV-0013. compute_fingerprint_v2 in src/devops_cli/review/fingerprint.py then hashes the tool, the rule and the logical location (the symbol) and leaves out the path. So all the results of one rule have one fingerprint, and deduplicate keeps the first.
Expected
Each Trivy result keeps its file and its line (CauseMetadata.StartLine when Trivy gives one), so two files with one rule give two results, two SARIF results and two alerts.
Steps
- Run
uv run devops scan report --scanner trivy-config --jsonon a tree where two manifests fail one rule, such as KSV-0020. - The report holds one result for the rule.
Source
Source: #4409
Proposed design
Problem statement
devops scan report keeps one trivy-config result for each rule, not one for each file. The location of a misconfiguration is <target>:<rule id>, so the normalizer reads the rule id as the symbol and the finding has no line. compute_fingerprint_v2 hashes the tool, the rule and the symbol, and leaves out the path. All the results of one rule then have one fingerprint, and deduplicate keeps the first, so code scanning shows one alert for each rule. The alert moves to the next file when a fix removes the finding from one file. The change keeps the file and the start line of each misconfiguration, so each file gets its own result and its own alert.
Acceptance criteria
Requirement: Trivy misconfiguration keeps its file
parse_trivy_json SHALL keep the file of each misconfiguration in the location of the finding.
Scenario: One rule in two files
- WHEN A Trivy JSON payload holds two results with the same misconfiguration rule and different targets.
- THEN
parse_trivy_jsonreturns two findings, and each location starts with its target path.
Requirement: Trivy misconfiguration keeps its start line
parse_trivy_json SHALL put CauseMetadata.StartLine into the location of a misconfiguration when Trivy gives one.
Scenario: A misconfiguration has a start line
- WHEN A Trivy JSON payload holds a misconfiguration with
CauseMetadata.StartLine12. - THEN The location of the finding holds
12between the target path and the rule id.
Requirement: Fingerprint keeps the path of a logical location
compute_fingerprint_v2 SHALL include a non-empty path in the fingerprint of a finding that has a logical location.
Scenario: One rule in two files
- WHEN
compute_fingerprint_v2runs twice with the same tool, rule and logical location, and a different path each time. - THEN The two calls return different fingerprints.
Requirement: Deduplicate keeps one result for each file
deduplicate SHALL keep every finding whose path differs, even when the rule is the same.
Scenario: Two files fail one rule
- WHEN The findings hold two results of one rule from two paths, with the fingerprints that
compute_fingerprint_v2gives them. - THEN
deduplicatereturns two findings.
Existing Tool Considered
No alternatives check has run. Trivy is the open, maintained tool that covers the need: its JSON gives the file Target and the line CauseMetadata.StartLine. Trivy lacks a project fingerprint and a deduplicate step; src/devops_cli/review/fingerprint.py and src/devops_cli/security/normalization.py hold them. The change reads the fields that Trivy gives and builds no new tool.
Key questions
- Where does
parse_trivy_jsonset the location of a misconfiguration?: Atsrc/devops_cli/security/trivy.py:92, it setslocation=f"{target_name}:{rule_id}".target_nameis the resultTarget, else the scan target path, at line 49. The rule id follows the colon, so the location holds no line. [sources: src/devops_cli/security/trivy.py:49, src/devops_cli/security/trivy.py:92] - Which branch of
compute_fingerprint_v2hashes a finding that has no line?: Thelogical_locationbranch atsrc/devops_cli/review/fingerprint.py:84hashes the tool, the rule and the logical location. It does not hash the path. [sources: src/devops_cli/review/fingerprint.py:84, src/devops_cli/review/fingerprint.py:85] - How should the fingerprint tell apart two files that fail the same rule?: Add the path to the
logical_locationbranch ofcompute_fingerprint_v2when the path is not empty. A finding with no path keeps its fingerprint. (best practice) [sources: src/devops_cli/review/fingerprint.py:84, src/devops_cli/security/normalization.py:457]- Chosen: Add the path to the logical-location branch. It is the smallest change. Two paths give two fingerprints, and a finding with no path keeps its fingerprint.
- Rejected: Pass the symbol as
enclosing_symbol. It changes the call insrc/devops_cli/security/normalization.pyand the fingerprint of each finding that has a symbol. - Rejected: Hash only the tool and the rule. This is the current behavior that collapses the results of one rule.
- Should the location of a Trivy misconfiguration hold its start line?: Yes.
parse_trivy_jsonputsCauseMetadata.StartLinebetween the target and the rule id when Trivy gives one. The location then names the file, the line and the rule. (best practice) [sources: src/devops_cli/security/trivy.py:92, src/devops_cli/review/fingerprint.py:84]- Chosen: Put the start line in the location. The location names the file and the line, so the report and the SARIF keep the place of the finding.
- Rejected: Keep the location as the target and the rule. The location gives no line, and two findings of one rule on one file collapse.
Fit
Fits in one pull request.
Suspected block
None.
Dependencies
None.
Activity
dan-petty commentedon Nov 30, 2026
Both address findings collapsing in deduplication, but the candidate fixes parse_trivy_json to preserve the file path while #1141 fixes the fingerprint to include line and content.fix(security): judge the 8 open Trivy-config alerts (#7876)
devops-cli-service commentedon Dec 1, 2026
Next step: the alternatives check records a verdict. See the section Proposed design of the body.