Skip to content

fix(benchmark): fix benchmark shell command built from environment values #4439

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: 16.x.x
Choose a base branch
from

Conversation

odaysec
Copy link

@odaysec odaysec commented Jun 22, 2025

function exec(command, options = {}) {
const result = cp.execSync(command, {

exec(`cp -R ${localDir('benchmark')} ${projectPath}`);
return { revision, projectPath };
});
function prepareNPMPackage(revision) {
if (revision === LOCAL) {
const repoDir = localDir();
const archivePath = path.join(tmpDir, 'graphql-local.tgz');
fs.renameSync(buildNPMArchive(repoDir), archivePath);
return archivePath;
}
// Returns the complete git hash for a given git revision reference.
const hash = exec(`git rev-parse "${revision}"`);

exec(`git archive "${hash}" | tar -xC "${repoDir}"`);
exec('npm --quiet ci --ignore-scripts', { cwd: repoDir });

Fix the issue should avoid passing dynamically constructed shell commands to cp.execSync. Instead, we can use cp.execFileSync, which allows us to pass the command and its arguments as separate parameters. This approach ensures that the shell does not interpret special characters in the arguments, mitigating the risk of command injection or misinterpretation.

  1. Replace the exec function to use cp.execFileSync instead of cp.execSync.
  2. Update all calls to exec to pass the command and arguments as separate parameters.

Recommendation

If possible, use hard-coded string literals to specify the shell command to run, and provide the dynamic arguments to the shell command separately to avoid interpretation by the shell. Alternatively, if the shell command must be constructed dynamically, then add code to ensure that special characters in environment values do not alter the shell command unexpectedly.

@odaysec odaysec requested a review from a team as a code owner June 22, 2025 07:48
Copy link

linux-foundation-easycla bot commented Jun 22, 2025

CLA Signed


The committers listed above are authorized under a signed CLA.

@benjie
Copy link
Member

benjie commented Jun 23, 2025

Can you explain how hash and repoDir variables could be supplied with malicious values that would cause command injection without the person who is running the code having done it deliberately to themselves?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants