Skip to content
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

Security Fix for Command Injection #12590

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Security Fix for Command Injection #12590

wants to merge 1 commit into from

Conversation

th13vn
Copy link

@th13vn th13vn commented Jul 14, 2022

Q | A
Version Affected | *
Bug Fix | YES

Description Pull Request

Used child_process.execFileSync() instead of child_process.execSync().

Description Vulnerability

The use of the child_process function execSync() is highly discouraged if you accept user input and don't sanitize/escape them.
In the program, url param was passed into function openBrowser() will go to startBrowserProcess() and be used by execFileSync() (L92-L102). url was encoded by encodeURI(), but encodeURI() is not encoded some special characters ;,/?:@&=+$#-_.!~*'() so attacker could put $(command) into URL string and arbitrarily execute command. In addition, the $IFS could bypass white space encoded by encodeURI().

PoC

Create a .js file with the content below and run it, then the file /tmp/th13ntc can be illegally created.

// poc.js
var openBrowser = require('react-dev-utils/openBrowser');

openBrowser('http://example.com/#$(touch$IFS/tmp/th13ntc)');

Proof of Fix (PoF)

Use:

//code fixed
execFileSync(
  "osascript",
  ["openChrome.applescript", encodeURI(url), chromiumBrowser],
  {
    cwd: __dirname,
    stdio: "ignore",
  }
);

Replace:

execSync(
  'osascript openChrome.applescript "' +
    encodeURI(url) +
    '" "' +
    chromiumBrowser +
    '"',
  {
    cwd: __dirname,
    stdio: "ignore",
  }
);

User Acceptance Testing (UAT)

var openBrowser = require('react-dev-utils/openBrowser');
openBrowser('http://example.com/'); //works correctly

References

  1. Credit to thientc from VNG Cloud Security Team with CodeQL Agent supported.
  2. Past context: Security Fix for Command Injection - huntr.dev #10644

Occurrences

#L92-L102

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants