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

feat: container add --exclude-node-modules option #5636

Merged
merged 1 commit into from
Dec 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions help/cli-commands/container-monitor.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,12 @@ In earlier releases, cannot be used with `--app-vulns`.

For more information see [Detecting application vulnerabilities in container images](https://docs.snyk.io/scan-using-snyk/snyk-container/use-snyk-container-from-the-web-ui/detect-application-vulnerabilities-in-container-images)

### `--exclude-node-modules`

Allow disabling the scan of node_modules directories inside node.js container images; in CLI versions v1.1292.0 and higher, node_modules scanning is enabled by default.

When the node_modules scan is disabled, snyk will report vulnerabilities for npm projects sourced from application file pairs: [package.json, package-lock.json], [package.json, yarn.lock].

### `--nested-jars-depth`

When `app-vulns` is enabled, use the `--nested-jars-depth=n` option to set how many levels of nested jars Snyk is to unpack. Depth must be a number.
Expand Down
14 changes: 7 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@
"semver": "^6.0.0",
"snyk-config": "^5.0.0",
"snyk-cpp-plugin": "2.24.0",
"snyk-docker-plugin": "6.13.18",
"snyk-docker-plugin": "6.14.0",
"snyk-go-plugin": "1.23.0",
"snyk-gradle-plugin": "4.7.0",
"snyk-module": "3.1.0",
Expand Down
1 change: 1 addition & 0 deletions src/lib/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ export interface MonitorOptions {
// Used with the Docker plugin only. Allows application scanning.
'app-vulns'?: boolean;
'exclude-app-vulns'?: boolean;
'exclude-node-modules'?: boolean;
initScript?: string;
yarnWorkspaces?: boolean;
'max-depth'?: number;
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -167,3 +167,39 @@ describe('container test projects behavior with --json flag', () => {
expect(code).toEqual(0);
});
});

describe('container test projects behavior with --exclude-node-modules flag', () => {
// Dockerfile for node-slim-image.tar
// FROM node:alpine

// COPY package.json /goof1/
// COPY package-lock.json /goof1/
// COPY package.json /
// COPY package-lock.json /
// WORKDIR /goof1
// RUN npm install
// WORKDIR /
// RUN npm install
it('should scan npm projects only when package.json and package-lock.json pairs are identified in the container image', async () => {
const { code, stdout } = await runSnykCLI(
`container test docker-archive:test/fixtures/container-projects/node-slim-image.tar --exclude-node-modules --json --exclude-base-image-vulns`,
);
const jsonOutput = JSON.parse(stdout);
const applications = jsonOutput.applications;

expect(applications.length).toEqual(2);
expect(code).toEqual(1);
}, 30000);

it('should scan npm projects from package.json and package-lock.json pairs and node_modules dependencies', async () => {
const { code, stdout } = await runSnykCLI(
`container test docker-archive:test/fixtures/container-projects/node-slim-image.tar --json --exclude-base-image-vulns`,
);
const jsonOutput = JSON.parse(stdout);
const applications = jsonOutput.applications;

expect(applications.length).toEqual(3);

expect(code).toEqual(1);
}, 30000);
});
Loading