fix(native-profiler): prevent shell injection via device_id on iOS#378
Draft
latekvo wants to merge 1 commit into
Draft
fix(native-profiler): prevent shell injection via device_id on iOS#378latekvo wants to merge 1 commit into
latekvo wants to merge 1 commit into
Conversation
The iOS native profiler interpolated the caller-supplied device_id (`udid`)
directly into shell-interpreted `execSync` template strings
(`xcrun simctl spawn ${udid} launchctl list` and
`xcrun simctl listapps ${udid} | plutil ...`). device_id is an unvalidated
`z.string()`, so a value like `x; <cmd>` executed arbitrary shell commands.
Switch both call sites to `execFileSync` arg-arrays (no shell), splitting the
`simctl listapps | plutil` pipe into two in-process stages. Add a regression
test asserting the udid is only ever passed as a discrete argv element.
The fix previously existed on a branch but was lost when this code moved from
tools/profiler/ios-profiler/ to native-profiler/platforms/ios.ts.
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.
Summary
The iOS native profiler interpolated the caller-supplied
device_id(udid) directly into shell-interpretedexecSynctemplate strings, so an unvalidateddevice_idcould execute arbitrary shell commands.In
packages/tool-server/src/tools/profiler/native-profiler/platforms/ios.ts:execSync(\xcrun simctl spawn ${udid} launchctl list`)`execSync(\xcrun simctl listapps ${udid} | plutil -convert json -o - -`)`device_idis declaredz.string()with no format constraint andresolveDevice()returns it unchanged, so a value like`x"; touch /tmp/pwned #`runs as shell.Fix
execFileSyncarg-arrays (no shell). Thesimctl listapps | plutilpipe is split into two in-process stages so nothing is shell-interpreted.udidis only ever passed as a discrete argv element, withexecSyncmocked to fail loudly if it is ever reintroduced.Context
This fix previously existed on an old branch but was lost when the code moved from
tools/profiler/ios-profiler/ios-profiler-start.tstonative-profiler/platforms/ios.ts.Verification
npm run build(tsc) ✓ ·typecheck:tests✓ ·prettier --check✓ ·eslint --max-warnings 0✓execSyncmakes it fail (the payloadbooted"; touch /tmp/argent-pwned #reaches the shell command string), confirming it is a real guard.