Skip to content

Commit 0a02219

Browse files
committed
update the comment doc for getAmpxPath, scope down the shell option to windows only
1 parent 98c8fe7 commit 0a02219

File tree

1 file changed

+16
-3
lines changed
  • packages/amplify-codegen-e2e-tests/src/gen2-codegen-tests-base

1 file changed

+16
-3
lines changed

packages/amplify-codegen-e2e-tests/src/gen2-codegen-tests-base/commands.ts

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,28 @@ import { spawnSync } from 'child_process';
1010
const getNpxPath = (): string => (process.platform === 'win32' ? getScriptRunnerPath().replace('node.exe', 'npx.cmd') : 'npx');
1111

1212
/**
13-
* Retrieve the path to the `ampx` executable for interacting with the amplify gen2 cli.
13+
* Retrieve the path to the `ampx` executable for interacting with the Amplify Gen2 CLI.
1414
* @param cwd current working directory
1515
* @returns the local `ampx` executable path
1616
*
1717
* Note:
18-
* Use shell: true to properly execute the .cmd file on Windows
18+
* On Windows, batch files (like npx.cmd) must be executed through a shell.
19+
* Therefore, this function uses `shell: process.platform === 'win32'` to ensure that the command
20+
* is run via the shell on Windows. This change was required after upgrading to Node 18,
21+
* where a security update now causes an EINVAL error if a .cmd file is executed without the shell option.
22+
*
23+
* See: https://nodejs.org/en/blog/vulnerability/april-2024-security-releases-2#command-injection-via-args-parameter-of-child_processspawn-without-shell-option-enabled-on-windows-cve-2024-27980---high
24+
*
25+
* Warning:
26+
* Command arguments **must** be sanitized to avoid injection risks.
1927
*/
2028
const getAmpxPath = (cwd: string): string =>
21-
spawnSync(getNpxPath(), ['which', 'ampx'], { cwd, env: process.env, stdio: 'pipe', shell: true }).stdout.toString().trim();
29+
spawnSync(getNpxPath(), ['which', 'ampx'], {
30+
cwd,
31+
env: process.env,
32+
stdio: 'pipe',
33+
shell: process.platform === 'win32',
34+
}).stdout.toString().trim();
2235

2336
const codegenPackagesInGen2 = [
2437
'@aws-amplify/graphql-generator',

0 commit comments

Comments
 (0)