Repository navigation
Conversation
|
@DongZifan is attempting to deploy a commit to the Parth Desai's projects Team on Vercel. A member of the Team first needs to authorize it. |
This branch has not been deployed
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.
Summary
Hello,
I am writing to report a potential OS Command Injection vulnerability in the following file:
next-remote-watch.jsThe issue appears when the changed file path (
filePathContext) and event name (eventContext) are interpolated into a user-provided--commandtemplate and the resulting string is executed viaspawn(shell, ['-c', ...]). Under these conditions, a file whose name contains shell metacharacters (such as;,&,|, or$()) can escape the intended command context and execute arbitrary code on the host system. This poses a significant security risk as it allows for Remote Code Execution (RCE).Root Cause
The issue is caused by unsanitized interpolation of attacker-influenced values into a shell command in the following function:
Because
spawn(shell, ['-c', command])runs the command through the system shell, any shell metacharacters present in the interpolatedfilePathContext(oreventContext) are interpreted as command syntax rather than literal text.Reproduction Material
A minimal reproduction script is provided in:
poc_next-remote-watch.jspoc_next-remote-watch.js
This Proof of Concept (PoC) is intended to demonstrate that a malicious file path can reach dangerous command execution logic through the vulnerable code path.
What the PoC Does
The PoC performs a minimal end-to-end trigger of the vulnerable code path:
child_process.spawnto log intercepted commands before they execute.next-remote-watch.js(with its optional dependencies stubbed for a self-contained run).chokidarevent callback registered by the file.README.md; calc #and the default event namechange.--commandis set toecho {event} {path}, the file path is substituted into the shell command and passed tospawn(shell, ['-c', ...]), where;is interpreted as a command separator andcalcis executed as a second command.In the provided example, the injected payload is crafted so that successful command execution launches the Calculator application. This serves as a visible indicator that external input can reach the OS command execution sink without proper sanitization.
Example Payload
The PoC uses the following malicious file path for the changed file:
How to Run
Run from the folder containing the files:
Expected Output
When the PoC runs, you should see output similar to:
In the vulnerable version, when the crafted file path is processed, the shell interprets the
;metacharacter and executes the injectedcalccommand, launching the Calculator application as a benign demonstration effect.This shows that an attacker-controlled file path can influence command execution behavior through the vulnerable
--commandpath.Patch Explanation
This branch also includes a patched version of
next-remote-watch.js(new_next-remote-watch.js) intended to mitigate the command injection risk described above.What the patch changes
The patch introduces shell escaping for the interpolated values so that shell metacharacters in
filePathContextandeventContextare treated as literal text rather than command syntax, while preserving the existing--commandfeature for legitimate callers.Validation introduced by the patch
A
shellQuotehelper is added to escape each interpolated value:The command construction now escapes both interpolated values before substitution:
Before the patch, a file path such as
README.md; calc #would be interpreted by the shell as two commands (echo README.mdandcalc). After the patch, the value is wrapped in single quotes (with embedded single quotes escaped), so the shell treats the whole path as a single literal argument. Shell metacharacters such as;,&,|,$(), and`are no longer interpreted, while legitimate file paths (including those containing spaces) continue to work as expected.