Skip to content

Commit 4756f27

Browse files
committedDec 19, 2024··
feat: container test/monitor add support for --exclude-node-modules option
1 parent fc240b2 commit 4756f27

File tree

6 files changed

+51
-8
lines changed

6 files changed

+51
-8
lines changed
 

‎help/cli-commands/container-monitor.md

+6
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,12 @@ In earlier releases, cannot be used with `--app-vulns`.
134134

135135
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)
136136

137+
### `--exclude-node-modules`
138+
139+
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.
140+
141+
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].
142+
137143
### `--nested-jars-depth`
138144

139145
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.

‎package-lock.json

+7-7
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@
116116
"semver": "^6.0.0",
117117
"snyk-config": "^5.0.0",
118118
"snyk-cpp-plugin": "2.24.0",
119-
"snyk-docker-plugin": "6.13.18",
119+
"snyk-docker-plugin": "6.14.0",
120120
"snyk-go-plugin": "1.23.0",
121121
"snyk-gradle-plugin": "4.7.0",
122122
"snyk-module": "3.1.0",

‎src/lib/types.ts

+1
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ export interface MonitorOptions {
144144
// Used with the Docker plugin only. Allows application scanning.
145145
'app-vulns'?: boolean;
146146
'exclude-app-vulns'?: boolean;
147+
'exclude-node-modules'?: boolean;
147148
initScript?: string;
148149
yarnWorkspaces?: boolean;
149150
'max-depth'?: number;
Binary file not shown.

‎test/jest/acceptance/snyk-test/app-vuln-container-project.spec.ts

+36
Original file line numberDiff line numberDiff line change
@@ -167,3 +167,39 @@ describe('container test projects behavior with --json flag', () => {
167167
expect(code).toEqual(0);
168168
});
169169
});
170+
171+
describe('container test projects behavior with --exclude-node-modules flag', () => {
172+
// Dockerfile for node-slim-image.tar
173+
// FROM node:alpine
174+
175+
// COPY package.json /goof1/
176+
// COPY package-lock.json /goof1/
177+
// COPY package.json /
178+
// COPY package-lock.json /
179+
// WORKDIR /goof1
180+
// RUN npm install
181+
// WORKDIR /
182+
// RUN npm install
183+
it('should scan npm projects only when package.json and package-lock.json pairs are identified in the container image', async () => {
184+
const { code, stdout } = await runSnykCLI(
185+
`container test docker-archive:test/fixtures/container-projects/node-slim-image.tar --exclude-node-modules --json --exclude-base-image-vulns`,
186+
);
187+
const jsonOutput = JSON.parse(stdout);
188+
const applications = jsonOutput.applications;
189+
190+
expect(applications.length).toEqual(2);
191+
expect(code).toEqual(1);
192+
}, 30000);
193+
194+
it('should scan npm projects from package.json and package-lock.json pairs and node_modules dependencies', async () => {
195+
const { code, stdout } = await runSnykCLI(
196+
`container test docker-archive:test/fixtures/container-projects/node-slim-image.tar --json --exclude-base-image-vulns`,
197+
);
198+
const jsonOutput = JSON.parse(stdout);
199+
const applications = jsonOutput.applications;
200+
201+
expect(applications.length).toEqual(3);
202+
203+
expect(code).toEqual(1);
204+
}, 30000);
205+
});

0 commit comments

Comments
 (0)
Please sign in to comment.