Skip to content

fix(updateServer): uncontrolled command line via execFileSync #3414

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: v7
Choose a base branch
from

Conversation

odaysec
Copy link

@odaysec odaysec commented Jun 2, 2025

const {execSync} = require('child_process');

execSync(
`git checkout -- ./ && git pull -X theirs ${repoUrl} ` +
`glitch && refresh && git branch -D glitch`,
);

Fix the issue the code should avoid interpolating untrusted user input directly into a shell command. Instead, use safer alternatives such as execFileSync, which accepts arguments as an array and does not spawn a shell by default. This approach prevents command injection by treating each argument as a literal value rather than part of a shell command. Additionally, validate the repoUrl input to ensure it conforms to expected patterns (e.g., a valid URL or repository name).

Steps to fix:

  1. Replace execSync with execFileSync to avoid spawning a shell.
  2. Pass the repoUrl as an argument in an array to execFileSync.
  3. Validate repoUrl to ensure it is a safe and expected value (e.g., using a regular expression or an allowlist).

Code that passes untrusted user input directly to child_process.exec or similar APIs that execute shell commands allows the user to execute malicious code.

References
shell-quote


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.

1 participant