Potential OS Command Injection Vulnerability in node-express-spawn#92
Open
SunLingrui wants to merge 1 commit intoapex:masterfrom
Open
Potential OS Command Injection Vulnerability in node-express-spawn#92SunLingrui wants to merge 1 commit intoapex:masterfrom
node-express-spawn#92SunLingrui wants to merge 1 commit intoapex:masterfrom
Conversation
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.
Potential OS Command Injection Vulnerability in
node-express-spawnHello,
I am writing to report a critical OS Command Injection vulnerability in the
node-express-spawnexample project. Because user-supplied input is passed directly to thechild_process.spawnfunction without adequate validation or sanitization, an unauthenticated attacker can execute arbitrary system commands on the host server.Location of Issue
The vulnerability is located in the routing logic of the Express application, specifically where the requested URL path is used to determine the program to execute.
File:
apex/up-examples/aa866c6/oss/node-express-spawn/app.jsVulnerable Snippet 1 (
/cmd/*route):Steps to Reproduce (PoC)
To demonstrate and verify this vulnerability, I have created and attached an automated Proof of Concept (PoC) script (
poc_app.js).poc_app.js
How the PoC works:
Instead of manually starting the server and sending HTTP requests, this script programmatically stubs the Express application to capture the vulnerable route handler. It then simulates an injection attack by passing the
touchcommand to create an empty.txtfile (poc_test_file.txt). Crucially, the script includes an automated testing function that asserts whether the new file was successfully written to the filesystem. This provides definitive, programmatic proof of the arbitrary command execution.Usage Instructions:
poc_app.jsfile.apex/up-examples/aa866c6/oss/node-express-spawn/).Expected Output (Vulnerable State):
If the application is vulnerable, the script will successfully execute the OS injection, create the file, pass the internal assertion, and output the following confirmation:
Proposed Solution
The most robust way to prevent OS Command Injection when allowing users to specify commands is to implement a strict Allowlist (Whitelist). Additionally, POSIX utilities like ls should use the -- separator to explicitly mark the end of command-line options.
In this Pull Request, I have introduced the following fixes:
Defined an ALLOWED_COMMANDS array containing only the intentionally supported executables. Added a check to return a 403 Forbidden status if the requested pgm is not in the allowlist.
Once the proposed Allowlist patch is applied, running this identical PoC script will result in a [TEST FAILED / EXPLOIT BLOCKED] message with a 403 status code, as the script's internal assertion will confirm the malicious file was never created.