Skip to content

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

Open
Abhinesh Jha (Abhineshhh) wants to merge 4 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 4 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

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant