- What language is this for: typescript
- Which rule: typescript:S4036
- Why do you believe it’s a false-positive/false-negative:
The rule states that I need ‘Make sure the “PATH” used to find this command included only what you intend’. I believe having the PATH overridden in the command call itself should be enough to fulfill that rule but it demands that I define only one path to the command inline in the call. - SonarQube Server / Community Build version 2025.1
- How can we reproduce the problem? Give us a self-contained snippet of code:
import { execSync } from "child_process";
function getBranchName(): string {
try {
return execSync("git rev-parse --abbrev-ref HEAD", {
env: {
PATH: "/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin"
}
}).toString();
} catch(error: unknown) {
if(
error &&
typeof error === "object" &&
"stderr" in error &&
error.stderr instanceof Buffer
) {
throw new Error(error.stderr.toString());
}
throw new Error("Unknown Error");
}
}
I also think this should be acceptable:
import { execSync } from "child_process";
function getBranchName(): string {
try {
return execSync("PATH='/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin' git rev-parse --abbrev-ref HEAD").toString();
} catch(error: unknown) {
if(
error &&
typeof error === "object" &&
"stderr" in error &&
error.stderr instanceof Buffer
) {
throw new Error(error.stderr.toString());
}
throw new Error("Unknown Error");
}
}