Fix potential OS command injection in wdproxy.js#126
Open
SunLingrui wants to merge 3 commits into
Open
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.
Command Injection Reproduction Notes for
wdproxy.jsSummary
Hello,
I am writing to report a potential OS Command Injection vulnerability in the following file:
f2etest-client/f2etest-webdriver/webdriver/wdproxy.jsThe issue appears when user-controlled input is used to construct shell command strings that are later executed via child_process.execSync(...). Under certain conditions, specially crafted input values provided in the /wd/hub/session request body may allow unintended command execution on the host system. This could potentially lead to command injection risks, depending on how the input is validated and processed.
Root Cause
The issue is caused by unsafe shell command construction in the following function:
Reproduction Material
A minimal reproduction script is provided in:
poc_wdproxy.jspoc_wdproxy.js
This Proof of Concept (PoC) is intended to demonstrate that external input 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:
wdproxy.js.POSTrequest to/wd/hub/session.browserNametointernet explorerproxy.proxyTypetomanualproxy.httpProxyto a malicious payloadsetProxy(httpProxy).httpProxyvalue is concatenated into a shell command and passed toexecSync(...).In the provided example, the injected payload is crafted so that, on macOS, successful command execution opens 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 payload for desiredCapabilities.proxy.httpProxy:
How to Run
Run from the project root:
Expected Output
When the PoC runs, you should see output similar to:
In the vulnerable version, after the crafted request is processed, the local machine will launch the Calculator application as a benign demonstration effect.
This shows that the attacker-controlled desiredCapabilities.proxy.httpProxy value can influence command execution behavior through the vulnerable setProxy() path.
Patch Explanation
This branch also includes a patched version of
wdproxy.jsintended to mitigate the command injection risk described above.What the patch changes
The patch adds strict validation before proxy-related values are used by the following functions:
setProxy(proxyHost)setPac(pacUrl)In the vulnerable version, user-controlled values such as:
desiredCapabilities.proxy.httpProxydesiredCapabilities.proxy.proxyAutoconfigUrlcould reach
child_process.execSync(...)through string concatenation without validation.The patched version introduces input checks before these values are passed into command execution logic.
Validation introduced by the patch
For proxy host values, the patch only allows typical host / port style input such as:
127.0.0.1:8080
proxy.example.com:3128
Unexpected characters are rejected.
For PAC URL values, the patch checks that:
the value is a string
the value length is reasonable
the value matches an expected http:// or https:// URL format
If validation fails, the value is rejected instead of being passed into command execution.