fix(security): Replace execSync with execFileSync to prevent command injection#30
Open
fix-it-felix-sentry[bot] wants to merge 1 commit intomainfrom
Open
fix(security): Replace execSync with execFileSync to prevent command injection#30fix-it-felix-sentry[bot] wants to merge 1 commit intomainfrom
fix-it-felix-sentry[bot] wants to merge 1 commit intomainfrom
Conversation
…injection in clang-format script - Replace child_process.execSync() with execFileSync() to prevent potential shell injection - Use array of arguments instead of string concatenation for safer command execution - Addresses command injection vulnerability flagged by Semgrep Fixes: JS-1502 Related: VULN-1095 Co-Authored-By: fix-it-felix-sentry[bot] <260785270+fix-it-felix-sentry[bot]@users.noreply.github.com>
Semver Impact of This PR🟢 Patch (bug fixes) 📋 Changelog PreviewThis is how your changes will appear in the changelog. Bug Fixes 🐛
Internal Changes 🔧Release
Other
🤖 This preview updates automatically when you update the PR. |
|
|
||
| try { | ||
| child_process.execSync(cmd, {stdio: 'inherit'}); | ||
| child_process.execFileSync('./node_modules/.bin/clang-format', args, {stdio: 'inherit'}); |
There was a problem hiding this comment.
Bug: The switch to execFileSync will cause the script to fail on Windows because it cannot execute the .cmd wrapper for clang-format without a shell.
Severity: HIGH
Suggested Fix
Add the { shell: true } option to the execFileSync call. This will allow it to correctly execute shell scripts like .cmd files on Windows. The updated call would be child_process.execFileSync('./node_modules/.bin/clang-format', args, {stdio: 'inherit', shell: true});.
Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent.
Verify if this is a real issue. If it is, propose a fix; if not, explain why it's not
valid.
Location: scripts/clang-format.mjs#L6
Potential issue: The change from `execSync` to `execFileSync` to run the `clang-format`
command will cause a runtime failure on Windows. On Windows, the executable in
`node_modules/.bin` is a `.cmd` batch file. `execFileSync` does not use a shell by
default and cannot execute `.cmd` files directly, unlike `execSync`. This will cause the
script to throw an error when `yarn lint` or `yarn fix:clang` is run in a Windows
environment, breaking the linting process for developers on that platform. This issue is
not caught by the current CI, which only runs the lint job on Ubuntu.
Did we get this right? 👍 / 👎 to inform future reviews.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
This PR fixes a command injection vulnerability detected by Semgrep in the
scripts/clang-format.mjsfile.Changes
child_process.execSync()withchild_process.execFileSync()to prevent potential shell injectioncmdvariable that was constructing the shell command stringWhy This Fix?
While the original code used hardcoded arguments, using
execSync()with string concatenation is flagged as a security risk because:execFileSync()with an array of arguments is the recommended secure approach for executing commandsTesting
The fix maintains the same functionality - it still executes the clang-format command with the same arguments, just in a safer manner.
References