Repository scans via trivy repo
don't honor all options when run against local repositories
#7543
therealpxc
started this conversation in
Bugs
Replies: 1 comment
-
This bug is related to some open issues:
|
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Description
While the help output for
trivy repo
lists giving a local filesystem path as an example of how to invoke it, when run that way, trivy doesn't actually honor repository-specific commands like--commit
and instead scans the worktree as though doing afilesystem
scan.Desired Behavior
When a repo is checked out to a commit that introduces a new vulnerable dependency to a repo that previously had none,
should not report any vulnerabilities, because it scanned the requested commit rather than the worktree.
Actual Behavior
When a repo is checked out to a commit that introduces a new vulnerable dependency to a repo that previously had none,
reports the vulnerable dependency added in the later commit even though it is not present in the specified commit, because Trivy scanned the worktree rather than the specified commit.
The same thing happens if you remove a lockfile containing the vulnerable dependency and run the scan against the commit that added it: trivy scans the worktree instead of the desired commit, and reports the vulnerability.
Reproduction Steps
git init
.npm init
.npm add phin@3.7.0
.package.json
andpackage-lock.json
.trivy repository --scanners vuln --commit $(git log HEAD~1 -1 --format='%H') .
...
Note that there is a workaround: make the reference to the local repository look like a URI by prefixing it with
file://
; just run as above withfile://.
in place of.
.Target
None
Scanner
Vulnerability
Output Format
CycloneDX
Mode
Standalone
Debug Output
Operating System
macOS Sonoma, Amazon Linux 2023
Version
Checklist
trivy clean --all
Beta Was this translation helpful? Give feedback.
All reactions