Files
codeql/javascript/ql/test/query-tests/Security/CWE-078/CommandInjection/execa.js
Owen Mansel-Chan 0eccd902c2 js: Inline expectation should have space after $
This was a regex-find-replace from `// \$(?! )` (using a negative lookahead) to `// $ `.
2026-03-04 12:45:03 +00:00

36 lines
1.8 KiB
JavaScript

import { execa, execaSync, execaCommand, execaCommandSync, $ } from 'execa';
import http from 'node:http'
import url from 'url'
http.createServer(async function (req, res) {
let cmd = url.parse(req.url, true).query["cmd"][0]; // $ Source
let arg1 = url.parse(req.url, true).query["arg1"]; // $ Source
let arg2 = url.parse(req.url, true).query["arg2"]; // $ Source
let arg3 = url.parse(req.url, true).query["arg3"]; // $ Source
await $`${cmd} ${arg1} ${arg2} ${arg3}`; // $ Alert
await $`ssh ${arg1} ${arg2} ${arg3}`; // safely escapes variables, preventing shell injection.
$({ shell: false }).sync`${cmd} ${arg1} ${arg2} ${arg3}`; // $ Alert
$({ shell: true }).sync`${cmd} ${arg1} ${arg2} ${arg3}`; // $ Alert
$({ shell: false }).sync`ssh ${arg1} ${arg2} ${arg3}`; // safely escapes variables, preventing shell injection.
$.sync`${cmd} ${arg1} ${arg2} ${arg3}`; // $ Alert
$.sync`ssh ${arg1} ${arg2} ${arg3}`; // safely escapes variables, preventing shell injection.
await $({ shell: true })`${cmd} ${arg1} ${arg2} ${arg3}`; // $ Alert
await $({ shell: false })`${cmd} ${arg1} ${arg2} ${arg3}`; // $ Alert
await $({ shell: false })`ssh ${arg1} ${arg2} ${arg3}`; // safely escapes variables, preventing shell injection.
await execa(cmd, [arg1, arg2, arg3]); // $ Alert
await execa(cmd, { shell: true }); // $ Alert
await execa(cmd, [arg1, arg2, arg3], { shell: true }); // $ Alert
execaSync(cmd, [arg1, arg2, arg3]); // $ Alert
execaSync(cmd, [arg1, arg2, arg3], { shell: true }); // $ Alert
await execaCommand(cmd + arg1 + arg2 + arg3); // $ Alert
await execaCommand(cmd + arg1 + arg2 + arg3, { shell: true }); // $ Alert
execaCommandSync(cmd + arg1 + arg2 + arg3); // $ Alert
execaCommandSync(cmd + arg1 + arg2 + arg3, { shell: true }); // $ Alert
});