Stop PowerShell command injection in the extractor sidecar - #35
Open
sxyrxyy wants to merge 1 commit into
Open
Conversation
The sidecar built a pwsh -Command string by interpolating parameters.fqdn, tenantId, startDate, endDate (and the cert path/password, app id) into single-quoted literals. A single quote in any of them broke out and ran arbitrary PowerShell - RCE on the sidecar for anyone who can create an extraction, plus a path to the cloud metadata endpoint. Route every interpolated value through a helper that wraps it as a safe single-quoted string (PowerShell escapes ' by doubling it). Longer term these should be -ArgumentList / an encoded command.
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.
What
The extractor sidecar runs a built command via
spawn('pwsh', ['-Command', cmd]), and thatcmdwas assembled by dropping values straight into single-quoted PowerShell literals:parameters.fqdn/parameters.organizationparameters.tenantIdparameters.startDate/parameters.endDateorgOutputPathcredentials.applicationId, the cert path, and the cert passwordA single
'in any of them ends the literal and the rest of the value runs as PowerShell. Theparameters.*values come from the extraction request body (only a few sub-fields are validated; the rest pass through and then override the org defaults injobService), so an analyst who can create an extraction can inject commands -> RCE on the sidecar container, and a clean SSRF tohttp://169.254.169.254/...for cloud credentials.Fix
Add a small
psQuote()helper that wraps a value as a safe single-quoted PowerShell string (the only special character inside one is', escaped by doubling it) and route every interpolated value through it. One file, no behavior change for legitimate values.Repro (before)
The injected
Invoke-RestMethodruns on the sidecar. After this PR the'is doubled and the value stays a literal.Notes
-ArgumentList/ a base64-EncodedCommandand stop building a command string at all - happy to do that as a follow-up.services/extractor/src/index.js) has the samebuildPowerShellCommandpattern, but no user-selectable extraction type routes there today, so it isn't the live sink. Worth hardening the same way; left out here to keep the PR focused.