-
-
Notifications
You must be signed in to change notification settings - Fork 359
fix(scripts): prevent command injection in expo-upload-sourcemaps #5636
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
Conversation
Replaced execSync with spawnSync to eliminate shell command injection vulnerability. Arguments are now passed as an array directly to the binary, preventing any shell metacharacter interpretation. Security improvements: - No shell invocation - uses spawnSync instead of execSync - Arguments passed as array, not string concatenation - Eliminates need for platform-specific escaping - Immune to command injection by design Added comprehensive test suite with 12 tests covering: - Basic functionality (uploads, error handling) - Security (command injection prevention) - Hermes support (--debug-id-reference flag) - Environment variable validation - Sourcemap processing All tests pass. No behavior changes for legitimate use cases. Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Semver Impact of This PR⚪ None (no version bump detected) 📋 Changelog PreviewThis is how your changes will appear in the changelog. This PR will not appear in the changelog. 🤖 This preview updates automatically when you update the PR. |
iOS (legacy) Performance metrics 🚀
|
| Revision | Plain | With Sentry | Diff |
|---|---|---|---|
| e07935d+dirty | 1217.37 ms | 1211.44 ms | -5.93 ms |
| 46da307+dirty | 1217.08 ms | 1224.16 ms | 7.08 ms |
| 534ba8c+dirty | 1230.22 ms | 1231.18 ms | 0.96 ms |
| c7f264b+dirty | 1211.82 ms | 1218.04 ms | 6.22 ms |
| 20d5eaa+dirty | 1231.12 ms | 1226.00 ms | -5.12 ms |
| 276d348+dirty | 1224.22 ms | 1227.38 ms | 3.16 ms |
| ebf60f9+dirty | 1217.66 ms | 1214.82 ms | -2.84 ms |
| 98f632c+dirty | 1236.40 ms | 1241.62 ms | 5.22 ms |
| 1853710+dirty | 1224.35 ms | 1230.18 ms | 5.84 ms |
| 59d1977+dirty | 1225.28 ms | 1227.83 ms | 2.54 ms |
App size
| Revision | Plain | With Sentry | Diff |
|---|---|---|---|
| e07935d+dirty | 3.41 MiB | 4.58 MiB | 1.17 MiB |
| 46da307+dirty | 2.63 MiB | 3.87 MiB | 1.24 MiB |
| 534ba8c+dirty | 2.63 MiB | 3.81 MiB | 1.18 MiB |
| c7f264b+dirty | 2.63 MiB | 3.91 MiB | 1.28 MiB |
| 20d5eaa+dirty | 2.63 MiB | 3.81 MiB | 1.18 MiB |
| 276d348+dirty | 2.63 MiB | 3.98 MiB | 1.34 MiB |
| ebf60f9+dirty | 3.41 MiB | 4.67 MiB | 1.25 MiB |
| 98f632c+dirty | 2.63 MiB | 3.81 MiB | 1.18 MiB |
| 1853710+dirty | 2.63 MiB | 3.91 MiB | 1.28 MiB |
| 59d1977+dirty | 3.38 MiB | 4.60 MiB | 1.22 MiB |
iOS (new) Performance metrics 🚀
|
| Revision | Plain | With Sentry | Diff |
|---|---|---|---|
| e07935d+dirty | 1225.85 ms | 1227.72 ms | 1.87 ms |
| 46da307+dirty | 1213.45 ms | 1207.96 ms | -5.49 ms |
| 534ba8c+dirty | 1225.00 ms | 1237.43 ms | 12.43 ms |
| c7f264b+dirty | 1229.78 ms | 1225.84 ms | -3.94 ms |
| 20d5eaa+dirty | 1224.67 ms | 1223.16 ms | -1.51 ms |
| 276d348+dirty | 1222.10 ms | 1229.02 ms | 6.92 ms |
| ebf60f9+dirty | 1218.85 ms | 1212.53 ms | -6.32 ms |
| 98f632c+dirty | 1221.38 ms | 1229.26 ms | 7.88 ms |
| 1853710+dirty | 1213.67 ms | 1226.35 ms | 12.67 ms |
| 59d1977+dirty | 1200.76 ms | 1207.90 ms | 7.14 ms |
App size
| Revision | Plain | With Sentry | Diff |
|---|---|---|---|
| e07935d+dirty | 3.41 MiB | 4.58 MiB | 1.17 MiB |
| 46da307+dirty | 3.19 MiB | 4.44 MiB | 1.25 MiB |
| 534ba8c+dirty | 3.19 MiB | 4.38 MiB | 1.19 MiB |
| c7f264b+dirty | 3.19 MiB | 4.48 MiB | 1.29 MiB |
| 20d5eaa+dirty | 3.19 MiB | 4.38 MiB | 1.19 MiB |
| 276d348+dirty | 3.19 MiB | 4.54 MiB | 1.36 MiB |
| ebf60f9+dirty | 3.41 MiB | 4.67 MiB | 1.25 MiB |
| 98f632c+dirty | 3.19 MiB | 4.38 MiB | 1.19 MiB |
| 1853710+dirty | 3.19 MiB | 4.48 MiB | 1.29 MiB |
| 59d1977+dirty | 3.38 MiB | 4.60 MiB | 1.22 MiB |
Android (new) Performance metrics 🚀
|
| Revision | Plain | With Sentry | Diff |
|---|---|---|---|
| 294387d+dirty | 359.44 ms | 393.40 ms | 33.97 ms |
| 083f560+dirty | 383.96 ms | 417.76 ms | 33.80 ms |
| 8db9631+dirty | 351.44 ms | 396.28 ms | 44.84 ms |
| 955f2eb+dirty | 388.13 ms | 433.56 ms | 45.44 ms |
| a206511+dirty | 331.54 ms | 356.98 ms | 25.44 ms |
| a0b15d6+dirty | 414.33 ms | 448.85 ms | 34.52 ms |
| 8ece263+dirty | 369.44 ms | 414.65 ms | 45.21 ms |
| 20d5eaa+dirty | 358.31 ms | 442.37 ms | 84.06 ms |
| 6c36ba5+dirty | 367.14 ms | 426.80 ms | 59.66 ms |
| d9f44bb+dirty | 460.61 ms | 496.62 ms | 36.00 ms |
App size
| Revision | Plain | With Sentry | Diff |
|---|---|---|---|
| 294387d+dirty | 43.94 MiB | 48.87 MiB | 4.93 MiB |
| 083f560+dirty | 7.15 MiB | 8.43 MiB | 1.28 MiB |
| 8db9631+dirty | 7.15 MiB | 8.43 MiB | 1.28 MiB |
| 955f2eb+dirty | 7.15 MiB | 8.42 MiB | 1.27 MiB |
| a206511+dirty | 43.94 MiB | 48.90 MiB | 4.96 MiB |
| a0b15d6+dirty | 7.15 MiB | 8.42 MiB | 1.27 MiB |
| 8ece263+dirty | 7.15 MiB | 8.41 MiB | 1.26 MiB |
| 20d5eaa+dirty | 7.15 MiB | 8.42 MiB | 1.27 MiB |
| 6c36ba5+dirty | 43.94 MiB | 49.27 MiB | 5.33 MiB |
| d9f44bb+dirty | 43.94 MiB | 49.22 MiB | 5.29 MiB |
Android (legacy) Performance metrics 🚀
|
| Revision | Plain | With Sentry | Diff |
|---|---|---|---|
| 294387d+dirty | 424.30 ms | 465.40 ms | 41.10 ms |
| c7f264b | 434.98 ms | 452.96 ms | 17.98 ms |
| ec14be7+dirty | 403.50 ms | 411.46 ms | 7.96 ms |
| a206511+dirty | 424.28 ms | 474.82 ms | 50.54 ms |
| 11ded16+dirty | 317.29 ms | 329.15 ms | 11.86 ms |
| 1bea095+dirty | 401.42 ms | 426.93 ms | 25.52 ms |
| 77061ed+dirty | 369.55 ms | 408.35 ms | 38.80 ms |
| d861c16+dirty | 336.96 ms | 349.14 ms | 12.18 ms |
| 6c36ba5+dirty | 385.48 ms | 442.36 ms | 56.88 ms |
| d9f44bb+dirty | 400.64 ms | 431.65 ms | 31.01 ms |
App size
| Revision | Plain | With Sentry | Diff |
|---|---|---|---|
| 294387d+dirty | 43.75 MiB | 48.04 MiB | 4.29 MiB |
| c7f264b | 17.75 MiB | 19.68 MiB | 1.94 MiB |
| ec14be7+dirty | 17.75 MiB | 19.69 MiB | 1.94 MiB |
| a206511+dirty | 43.75 MiB | 48.07 MiB | 4.32 MiB |
| 11ded16+dirty | 17.75 MiB | 19.75 MiB | 2.00 MiB |
| 1bea095+dirty | 17.75 MiB | 19.70 MiB | 1.95 MiB |
| 77061ed+dirty | 17.75 MiB | 19.68 MiB | 1.94 MiB |
| d861c16+dirty | 17.75 MiB | 19.70 MiB | 1.96 MiB |
| 6c36ba5+dirty | 43.75 MiB | 48.41 MiB | 4.66 MiB |
| d9f44bb+dirty | 43.75 MiB | 48.40 MiB | 4.64 MiB |
lucas-zimerman
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
| try { | ||
| const stdOutBuffer = execSync('npx expo config --json'); | ||
| const config = JSON.parse(stdOutBuffer.toString()); | ||
| const result = spawnSync('npx', ['expo', 'config', '--json'], { encoding: 'utf8' }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bug: The spawnSync('npx', ...) call will fail on Windows because npx is not a native executable and spawnSync is called without the shell: true option.
Severity: MEDIUM
Suggested Fix
For the spawnSync call involving npx, either set the shell option to true or conditionally use npx.cmd on Windows platforms to ensure the command can be resolved.
Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent.
Verify if this is a real issue. If it is, propose a fix; if not, explain why it's not
valid.
Location: packages/core/scripts/expo-upload-sourcemaps.js#L19
Potential issue: On Windows, the `spawnSync` call to `npx` on line 19 will fail with an
`ENOENT` error. This occurs because `npx` is a `.cmd` script on Windows, and `spawnSync`
is called without `shell: true`, preventing it from resolving the command. This bug is
triggered when the script needs to fall back to fetching configuration via `expo config`
because environment variables like `SENTRY_ORG` or `SENTRY_PROJECT` are not set. This
will prevent Windows users from using the automatic configuration fallback feature.
Did we get this right? 👍 / 👎 to inform future reviews.
📢 Type of change
📜 Description
Replaced execSync with spawnSync to eliminate shell command injection vulnerability. Arguments are now passed as an array directly to the binary, preventing any shell metacharacter interpretation.
Security improvements:
Added comprehensive test suite with 12 tests covering:
💡 Motivation and Context
Fixes https://linear.app/getsentry/issue/RN-485/command-injection-vulnerabilities-in-getsentrysentry-react-native-in-7
💚 How did you test it?
Added unit tests
📝 Checklist
sendDefaultPIIis enabled🔮 Next steps
#skip-changelog