Skip to content

@W-23807282 - prevent command injection via server-provided redirectUrl (RCE) - #520

Open
ad-shreya wants to merge 1 commit into
mainfrom
ashreya/fix-redirecturl-rce
Open

@W-23807282 - prevent command injection via server-provided redirectUrl (RCE)#520
ad-shreya wants to merge 1 commit into
mainfrom
ashreya/fix-redirecturl-rce

Conversation

@ad-shreya

@ad-shreya ad-shreya commented Aug 13, 2026

Copy link
Copy Markdown
Collaborator

@W-23807282@

Summary

Fixes a command injection → remote code execution vulnerability in sf devops stage environment add (Hackforce report a0LKa00000IqKR2MAN).

The command opened the OAuth redirectUrl returned by the target org using exec() with the URL interpolated into a shell string:

exec(`${cmd} "${url}"`);

Because --target-org accepts an arbitrary instance URL, an attacker controlling that endpoint could return a redirectUrl such as safe" & calc.exe & rem ", breaking out of the quoted URL to execute arbitrary commands on the victim's machine. It triggered regardless of --json; only --no-browser avoided it.

Fix (defense-in-depth)

  1. No shell. Switched from exec() to execFile(), passing the URL as a discrete argument so no shell can interpret it. Windows uses cmd /c start "" <url> (empty window-title arg before the URL).
  2. Validate the scheme. New sanitizeRedirectUrl() parses the value with the WHATWG URL API, rejects any non-http(s) scheme (blocking javascript:, file:, and non-URL payloads like the reported one, which don't parse at all), and returns the normalized href so residual quotes/spaces are percent-encoded. Invalid input throws a friendly error.InvalidRedirectUrl instead of launching anything.

Testing

  • Added regression tests: URL passed as a discrete arg; the reported safe" & calc.exe & rem " payload is rejected with no process spawned; a crafted http URL is normalized so no quote/space survives.
  • Updated the existing test mock from exec to execFile.
  • All 10 tests pass; yarn compile clean; yarn lint 0 errors.

🤖 Generated with Claude Code

The devops stage environment add command opened the OAuth redirectUrl
returned by the target org using exec() with the URL interpolated into a
shell string. A malicious endpoint could return a redirectUrl containing
shell metacharacters (e.g. `safe" & calc.exe & rem "`) to break out of
the quoted URL and execute arbitrary commands, leading to RCE.

Fix (defense-in-depth):
- Switch from exec() to execFile(), passing the URL as a discrete argument
  so no shell interprets it. Windows uses `cmd /c start "" <url>`.
- Add sanitizeRedirectUrl(): parse with the WHATWG URL API, reject any
  non-http(s) scheme (blocks javascript:, file:, and non-URL payloads),
  and return the normalized href so residual quotes/spaces are
  percent-encoded.

Add regression tests covering the reported payload, scheme rejection, and
metacharacter normalization.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@ad-shreya
ad-shreya requested a review from a team as a code owner August 13, 2026 14:50
@ad-shreya ad-shreya changed the title fix: prevent command injection via server-provided redirectUrl (RCE) @W-23807282 - prevent command injection via server-provided redirectUrl (RCE) Aug 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant