Skip to content

Commit c4367e1

Browse files
authored
Merge pull request #677 from snyk/fix/downgrade-shescape-version
Fix/downgrade shescape version to 1.7.4 due to 'Unsupported Default Shell Behavior' in >= 2.0.0
2 parents 96ab3cf + a7410df commit c4367e1

5 files changed

Lines changed: 63 additions & 21 deletions

File tree

lib/sub-process.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import * as childProcess from "child_process";
2+
import { quoteAll } from "shescape";
23

34
export { execute, CmdOutput };
45
interface CmdOutput {
@@ -12,15 +13,13 @@ function execute(
1213
options?,
1314
): Promise<CmdOutput> {
1415
const spawnOptions: any = {
15-
// Some distributions may not have /bin/bash, which would cause `child_process.spawn` to fail.
16-
// By setting `shell: false`, we tell `spawn` to execute the command directly without a shell,
17-
// which is more portable.
18-
shell: false,
16+
shell: true,
1917
env: { ...process.env },
2018
};
2119
if (options && options.cwd) {
2220
spawnOptions.cwd = options.cwd;
2321
}
22+
args = quoteAll(args, spawnOptions);
2423

2524
// Before spawning an external process, we look if we need to restore the system proxy configuration,
2625
// which overrides the cli internal proxy configuration.

package-lock.json

Lines changed: 21 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
"mkdirp": "^1.0.4",
4646
"packageurl-js": "1.2.0",
4747
"semver": "^7.6.3",
48+
"shescape": "^1.7.4",
4849
"snyk-nodejs-lockfile-parser": "^2.0.0",
4950
"snyk-poetry-lockfile-parser": "^1.4.0",
5051
"snyk-resolve-deps": "^4.7.1",

test/lib/sub-process.spec.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { quoteAll } from "shescape";
12
import { execute } from "../../lib/sub-process";
23

34
describe("sub-process", () => {
@@ -31,4 +32,24 @@ describe("sub-process", () => {
3132
expect(stdout).toContain("NO_PROXY=snyk.com");
3233
expect(process.env.NO_PROXY).toStrictEqual("example.com");
3334
});
35+
36+
describe("quoteAll", () => {
37+
const shellOptions = [false, true, "/bin/sh"];
38+
if (process.platform !== "win32") {
39+
shellOptions.push(
40+
"/bin/bash",
41+
"/bin/zsh",
42+
"/bin/dash",
43+
"/bin/ksh",
44+
"/bin/csh",
45+
"/bin/busybox",
46+
);
47+
}
48+
49+
for (const shell of shellOptions) {
50+
it(`does not throw when shell is ${shell}`, () => {
51+
expect(() => quoteAll(["test"], { shell })).not.toThrow();
52+
});
53+
}
54+
});
3455
});

test/system/plugin.spec.ts

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,23 @@ describe("plugin", () => {
9292
});
9393
});
9494

95+
test("image pulled by tag has version set", async () => {
96+
const imageNameAndTag = `nginx:1.19.0`;
97+
98+
const pluginResult = await plugin.scan({
99+
path: imageNameAndTag,
100+
});
101+
102+
const depGraph: DepGraph = pluginResult.scanResults[0].facts.find(
103+
(fact) => fact.type === "depGraph",
104+
)!.data;
105+
106+
// image name matches
107+
expect(depGraph.rootPkg.name).toEqual("docker-image|nginx");
108+
// version must not be empty
109+
expect(depGraph.rootPkg.version).toEqual("1.19.0");
110+
});
111+
95112
describe("when scanning a locally loaded image", () => {
96113
const imageName = "busybox";
97114
const imageTag = "latest";
@@ -121,23 +138,6 @@ describe("plugin", () => {
121138
});
122139
});
123140

124-
test("image pulled by tag has version set", async () => {
125-
const imageNameAndTag = `nginx:1.19.0`;
126-
127-
const pluginResult = await plugin.scan({
128-
path: imageNameAndTag,
129-
});
130-
131-
const depGraph: DepGraph = pluginResult.scanResults[0].facts.find(
132-
(fact) => fact.type === "depGraph",
133-
)!.data;
134-
135-
// image name matches
136-
expect(depGraph.rootPkg.name).toEqual("docker-image|nginx");
137-
// version must not be empty
138-
expect(depGraph.rootPkg.version).toEqual("1.19.0");
139-
});
140-
141141
test("static scan for Identifier type image (nginx:1.19.0)", async () => {
142142
// This digest resolves to the `1.19.0` tag. We're using the digest to guarantee we always get the correct
143143
// image, no matter on which platform this test is run on.

0 commit comments

Comments
 (0)