Skip to content

fix(security): keep one Trivy result for each file #7875

Backlog

Description

@dan-petty

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

  1. Run uv run devops scan report --scanner trivy-config --json on a tree where two manifests fail one rule, such as KSV-0020.
  2. 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_json returns 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.StartLine 12.
  • THEN The location of the finding holds 12 between 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_v2 runs 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_v2 gives them.
  • THEN deduplicate returns 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_json set the location of a misconfiguration?: At src/devops_cli/security/trivy.py:92, it sets location=f"{target_name}:{rule_id}". target_name is the result Target, 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_v2 hashes a finding that has no line?: The logical_location branch at src/devops_cli/review/fingerprint.py:84 hashes 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_location branch of compute_fingerprint_v2 when 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 in src/devops_cli/security/normalization.py and 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_json puts CauseMetadata.StartLine between 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

  1. added
    type/bug
    scope/security
    source/agent
    status/new
    value/medium
    effort/low
    on Nov 30, 2026
  2. dan-petty commented on Nov 30, 2026

    @dan-petty
    OwnerAuthor
  3. added
    priority/p2-medium
    on Nov 30, 2026
  4. devops-cli-service commented on Dec 1, 2026

    @devops-cli-service
    Contributor

    Next step: the alternatives check records a verdict. See the section Proposed design of the body.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    effort/lowpriority/p2-mediumscope/securitysource/agentstatus/newtype/bugvalue/medium

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions