Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(php): skip composer.lock inside vendor folder #2718

Merged
merged 6 commits into from Aug 23, 2022
Merged

Conversation

afdesk
Copy link
Contributor

@afdesk afdesk commented Aug 16, 2022

Description

trivy scans composer.lock files in the vendor folder, but these don't reflect what is really installed.
composer.lock files in the vendor folder should be ignored.

$ trivy -d image --vuln-type library phpmyadmin:5.0.2

before:

2022-08-23T15:28:49.140+0600	INFO	Number of language-specific files: 4
2022-08-23T15:28:49.140+0600	INFO	Detecting composer vulnerabilities...
2022-08-23T15:28:49.140+0600	DEBUG	Detecting library vulnerabilities, type: composer, path: var/www/html/vendor/pragmarx/google2fa/composer.lock
2022-08-23T15:28:49.141+0600	DEBUG	Detecting library vulnerabilities, type: composer, path: var/www/html/vendor/pragmarx/google2fa-qrcode/composer.lock
2022-08-23T15:28:49.141+0600	DEBUG	Detecting library vulnerabilities, type: composer, path: var/www/html/composer.lock
2022-08-23T15:28:49.142+0600	INFO	Detecting node-pkg vulnerabilities...

after:

2022-08-23T15:29:59.233+0600	INFO	Number of language-specific files: 2
2022-08-23T15:29:59.233+0600	INFO	Detecting composer vulnerabilities...
2022-08-23T15:29:59.233+0600	DEBUG	Detecting library vulnerabilities, type: composer, path: var/www/html/composer.lock
2022-08-23T15:29:59.234+0600	INFO	Detecting node-pkg vulnerabilities...

Related issues

Checklist

  • I've read the guidelines for contributing to this repository.
  • I've followed the conventions in the PR title.
  • I've added tests that prove my fix is effective or that my feature works.
  • I've updated the documentation with the relevant information (if needed).
  • I've added usage information (if the PR introduces new options)
  • I've included a "before" and "after" example to the description (if the PR is a user interface change).

@afdesk afdesk marked this pull request as ready for review August 16, 2022 13:18
@afdesk afdesk requested a review from knqyf263 as a code owner August 16, 2022 13:18
@@ -25,6 +26,21 @@ var requiredFiles = []string{types.ComposerLock}
type composerLibraryAnalyzer struct{}

func (a composerLibraryAnalyzer) Analyze(_ context.Context, input analyzer.AnalysisInput) (*analyzer.AnalysisResult, error) {
// we should skip `composer.lock` inside `vendor` folder
Copy link
Collaborator

Choose a reason for hiding this comment

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

We should do that in Required.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

sure, done

if s == "vendor" {
path := filepath.Join(subDirs[:i]...)
f := filepath.Join(path, file)
if _, err := os.Stat(f); err == os.ErrNotExist {
Copy link
Collaborator

Choose a reason for hiding this comment

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

os.Stat doesn't work if it is from a tar file.

afdesk and others added 2 commits August 23, 2022 15:11
@knqyf263 knqyf263 merged commit da6f1b6 into main Aug 23, 2022
@knqyf263 knqyf263 deleted the skip-sub-composers branch August 23, 2022 10:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

composer.lock files in vendor folder are scanned
2 participants