@W-23807282 - prevent command injection via server-provided redirectUrl (RCE) - #520
Open
ad-shreya wants to merge 1 commit into
Open
@W-23807282 - prevent command injection via server-provided redirectUrl (RCE)#520ad-shreya wants to merge 1 commit into
ad-shreya wants to merge 1 commit into
Conversation
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>
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.
@W-23807282@
Summary
Fixes a command injection → remote code execution vulnerability in
sf devops stage environment add(Hackforce reporta0LKa00000IqKR2MAN).The command opened the OAuth
redirectUrlreturned by the target org usingexec()with the URL interpolated into a shell string:Because
--target-orgaccepts an arbitrary instance URL, an attacker controlling that endpoint could return aredirectUrlsuch assafe" & 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-browseravoided it.Fix (defense-in-depth)
exec()toexecFile(), passing the URL as a discrete argument so no shell can interpret it. Windows usescmd /c start "" <url>(empty window-title arg before the URL).sanitizeRedirectUrl()parses the value with the WHATWGURLAPI, rejects any non-http(s)scheme (blockingjavascript:,file:, and non-URL payloads like the reported one, which don't parse at all), and returns the normalizedhrefso residual quotes/spaces are percent-encoded. Invalid input throws a friendlyerror.InvalidRedirectUrlinstead of launching anything.Testing
safe" & calc.exe & rem "payload is rejected with no process spawned; a craftedhttpURL is normalized so no quote/space survives.exectoexecFile.yarn compileclean;yarn lint0 errors.🤖 Generated with Claude Code