Skip to content

fix: harden Trivy integration (scanners, UTF-8 truncate, security findings) - #87

Open
Abhinesh Jha (Abhineshhh) wants to merge 5 commits into
microsoft:mainfrom
Abhineshhh:fix/trivy-stack
Open

fix: harden Trivy integration (scanners, UTF-8 truncate, security findings)#87
Abhinesh Jha (Abhineshhh) wants to merge 5 commits into
microsoft:mainfrom
Abhineshhh:fix/trivy-stack

Conversation

@Abhineshhh

Copy link
Copy Markdown
Contributor

Description

Consolidated Trivy-related fixes that all touch pkg/infrastructure/scanner/trivy.go, stacked into one PR to avoid merge conflicts and review thrash.

Related Issues

Fixes #78
Fixes #79
Fixes #73

Changes

  1. --scanners flag — replace deprecated --security-checks; use misconfig instead of config ([Bug]: Trivy invoked with deprecated --security-checks flag #78)
  2. UTF-8-safe truncateString — never cut mid-rune; multi-byte regression tests use ASCII-safe \u escapes ([Bug]: truncateString can produce invalid UTF-8 in vulnerability descriptions #79)
  3. Persist comprehensive findings — map secrets/misconfigs → SecurityFindings, store in DB, load in QueryAllImageDetails, emit in detailed JSON ([Bug]: Comprehensive Trivy findings are counted but never persisted to security_findings #73)

Stack note

This replaces the overlapping single-file PRs #80, #81, and #86 (closed in favor of this consolidated stack).

Checklist

  • go test ./... passes locally
  • Documentation updated (docs/detailed-report.md)
  • Commits are logical and reviewable in order

Comment thread pkg/infrastructure/scanner/trivy.go Outdated
Severity: s.Severity,
RuleID: s.RuleID,
Title: s.Title,
Description: truncateString(s.Match, 500),

@maniSbindra Mani Bindra (maniSbindra) Sep 1, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Abhinesh Jha (@Abhineshhh) Trivy v0.69.3 masks the matched secret span before populating Match, so this should not persist raw credentials. However, surrounding source-line text can remain visible, and this description is published through the nightly database and detailed JSON report.

As defense in depth, consider omitting Description for secret findings and retaining only the rule metadata. Alternatively, add a test documenting and protecting the assumption that Trivy supplies a censored value.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch. I dropped Description for secret findings entirely so Match never reaches the DB or the nightly detailed JSON. Findings now keep only rule metadata (ruleId, title, severity, category) plus the parent Trivy Target as filePath.

TestParseTrivyResult_SecretsAndMisconfigs now feeds a non-empty Match (including surrounding source-line text) and asserts it does not appear on the finding. Also removed the AKIA fixture from the repository test.

Pushed on this branch after rebase onto current main.

Trivy renamed --security-checks to --scanners and deprecates the
config scanner name in favor of misconfig. Switch RunTrivy to the
supported flags so comprehensive scans keep working when the alias is
removed.

Fixes microsoft#78
Byte-based slicing in truncateString could cut multi-byte characters
mid-rune (CJK, emoji), producing invalid UTF-8 stored in the database
and emitted in JSON reports.

Truncate by rune while respecting a max byte budget (including ...),
and add regression tests for multi-byte inputs.

Fixes microsoft#79
Comprehensive scans counted secrets/misconfigurations but never built
SecurityFindings, so the security_findings table stayed empty and detail
reports could not surface them.

Map Trivy secrets and misconfigs into domain findings, store them on the
image record, load them (and capabilities) in QueryAllImageDetails, and
emit them in the detailed JSON report.

Fixes microsoft#73
Replace non-ASCII literals in truncate tests with \u escapes (accented
Latin and emoji) so the suite is encoding-stable and language-neutral.
Nightly commits the detailed JSON report to the public repo.
Match can include surrounding source-line text even when Trivy
masks the secret span, so persist only rule metadata and the
parent result path.

Addresses review on microsoft#87.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants