Skip to content

Commit 0f54465

Browse files
authored
Merge pull request #3874 from snyk/feat/no-app-vulns
feat: add flag to exclude app vulnerabilities
2 parents b0467ee + 9216c49 commit 0f54465

File tree

4 files changed

+63
-6
lines changed

4 files changed

+63
-6
lines changed

src/cli/commands/monitor/index.ts

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import * as Debug from 'debug';
44
import * as pathUtil from 'path';
55
import { legacyPlugin as pluginApi } from '@snyk/cli-interface';
66
import { checkOSSPaths } from '../../../lib/check-paths';
7+
import * as theme from '../../../lib/theme';
78

89
import {
910
MonitorOptions,
@@ -50,6 +51,11 @@ import { processCommandArgs } from '../process-command-args';
5051

5152
const SEPARATOR = '\n-------------------------------------------------------\n';
5253
const debug = Debug('snyk');
54+
const appVulnsReleaseWarningMsg = `${theme.icon.WARNING} Important: Beginning January 24th, 2023, application dependencies in container
55+
images will be scanned by default when using the snyk container test/monitor
56+
commands. If you are using Snyk in a CI pipeline, action may be required. Read
57+
https://snyk.io/blog/securing-container-applications-using-the-snyk-cli/ for
58+
more info.`;
5359

5460
// This is used instead of `let x; try { x = await ... } catch { cleanup }` to avoid
5561
// declaring the type of x as possibly undefined.
@@ -87,9 +93,18 @@ export default async function monitor(...args0: MethodArgs): Promise<any> {
8793
throw new Error('`--remote-repo-url` is not supported for container scans');
8894
}
8995

90-
// TODO remove once https://github.com/snyk/cli/pull/3433 is merged
91-
if (options.docker && !options['app-vulns']) {
92-
options['exclude-app-vulns'] = true;
96+
// TODO remove 'app-vulns' options and warning message once
97+
// https://github.com/snyk/cli/pull/3433 is merged
98+
if (options.docker) {
99+
if (!options['app-vulns'] || options['exclude-app-vulns']) {
100+
options['exclude-app-vulns'] = true;
101+
}
102+
103+
// we can't print the warning message with JSON output as that would make
104+
// the JSON output invalid.
105+
if (!options['app-vulns'] && !options['json']) {
106+
console.log(theme.color.status.warn(appVulnsReleaseWarningMsg));
107+
}
93108
}
94109

95110
// Handles no image arg provided to the container command until

src/cli/commands/test/index.ts

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ const cloneDeep = require('lodash.clonedeep');
44
const assign = require('lodash.assign');
55
import chalk from 'chalk';
66
import { MissingArgError } from '../../../lib/errors';
7+
import * as theme from '../../../lib/theme';
78

89
import * as snyk from '../../../lib';
910
import { Options, TestOptions } from '../../../lib/types';
@@ -48,6 +49,12 @@ import { checkOSSPaths } from '../../../lib/check-paths';
4849
const debug = Debug('snyk-test');
4950
const SEPARATOR = '\n-------------------------------------------------------\n';
5051

52+
const appVulnsReleaseWarningMsg = `${theme.icon.WARNING} Important: Beginning January 24th, 2023, application dependencies in container
53+
images will be scanned by default when using the snyk container test/monitor
54+
commands. If you are using Snyk in a CI pipeline, action may be required. Read
55+
https://snyk.io/blog/securing-container-applications-using-the-snyk-cli/ for
56+
more info.`;
57+
5158
// TODO: avoid using `as any` whenever it's possible
5259

5360
export default async function test(
@@ -88,9 +95,18 @@ export default async function test(
8895
throw new MissingArgError();
8996
}
9097

91-
// TODO remove once https://github.com/snyk/cli/pull/3433 is merged
92-
if (options.docker && !options['app-vulns']) {
93-
options['exclude-app-vulns'] = true;
98+
// TODO remove 'app-vulns' options and warning message once
99+
// https://github.com/snyk/cli/pull/3433 is merged
100+
if (options.docker) {
101+
if (!options['app-vulns'] || options['exclude-app-vulns']) {
102+
options['exclude-app-vulns'] = true;
103+
}
104+
105+
// we can't print the warning message with JSON output as that would make
106+
// the JSON output invalid.
107+
if (!options['app-vulns'] && !options['json']) {
108+
console.log(theme.color.status.warn(appVulnsReleaseWarningMsg));
109+
}
94110
}
95111

96112
const ecosystem = getEcosystemForTest(options);

src/lib/types.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ export interface Options {
7373
experimental?: boolean;
7474
// Used with the Docker plugin only. Allows application scanning.
7575
'app-vulns'?: boolean;
76+
'exclude-app-vulns'?: boolean;
7677
debug?: boolean;
7778
sarif?: boolean;
7879
'group-issues'?: boolean;
@@ -107,6 +108,7 @@ export interface MonitorOptions {
107108
experimental?: boolean;
108109
// Used with the Docker plugin only. Allows application scanning.
109110
'app-vulns'?: boolean;
111+
'exclude-app-vulns'?: boolean;
110112
initScript?: string;
111113
yarnWorkspaces?: boolean;
112114
'max-depth'?: number;

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

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,30 @@ describe('container test projects behavior with --app-vulns, --file and --exclud
2424
expect(jsonOutput[1].uniqueCount).toBeGreaterThan(0);
2525
expect(code).toEqual(1);
2626
}, 10000);
27+
it('should find nothing when app-vulns are explicitly disabled', async () => {
28+
const { code, stdout } = await runSnykCLI(
29+
`container test docker-archive:test/fixtures/container-projects/os-packages-and-app-vulns.tar --json --exclude-app-vulns`,
30+
);
31+
const jsonOutput = JSON.parse(stdout);
32+
expect(Array.isArray(jsonOutput)).toBeFalsy();
33+
expect(jsonOutput.applications).toBeUndefined();
34+
expect(jsonOutput.ok).toEqual(false);
35+
expect(jsonOutput.uniqueCount).toBeGreaterThan(0);
36+
expect(code).toEqual(1);
37+
}, 10000);
38+
it('should find nothing on conflicting app-vulns flags', async () => {
39+
// if both flags are set, --exclude-app-vulns should take precedence and
40+
// disable it.
41+
const { code, stdout } = await runSnykCLI(
42+
`container test docker-archive:test/fixtures/container-projects/os-packages-and-app-vulns.tar --json --app-vulns --exclude-app-vulns --experimental`,
43+
);
44+
const jsonOutput = JSON.parse(stdout);
45+
expect(Array.isArray(jsonOutput)).toBeFalsy();
46+
expect(jsonOutput.applications).toBeUndefined();
47+
expect(jsonOutput.ok).toEqual(false);
48+
expect(jsonOutput.uniqueCount).toBeGreaterThan(0);
49+
expect(code).toEqual(1);
50+
}, 10000);
2751
it('should find all vulns when using --app-vulns without experimental flag', async () => {
2852
const { code, stdout } = await runSnykCLI(
2953
`container test docker-archive:test/fixtures/container-projects/os-packages-and-app-vulns.tar --json --app-vulns`,

0 commit comments

Comments
 (0)