-
Notifications
You must be signed in to change notification settings - Fork 149
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
fix: use shell when running child_process.spawn #1804
base: main
Are you sure you want to change the base?
Conversation
🦋 Changeset detectedLatest commit: 3707e9d The changes in this PR will be included in the next version bump. This PR includes changesets to release 2 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
@@ -0,0 +1,5 @@ | |||
--- | |||
"@redocly/cli": patch |
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.
Should it include @redocly/openapi-core
bump too?
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.
No as all the changes are scoped to the cli
package.
Coverage report❌ An unexpected error occurred. For more details, check console
Test suite run failedFailed tests: 0/835. Failed suites: 0/123. Report generated by 🧪jest coverage report action from 3707e9d |
Converting back to draft as I'd like to add some input sanitization |
What/Why/How?
CLI preview command was failing on Windows with specific Node versions.
Turns out there is a breaking change in Node API that prevents passing
.cmd
files tospawn
function without usingshell: true
option. Since we're usingnpx.cmd
shell
option is now necessary.Using
shell: true
brings an actual shell which introduces a risk of shell injection. This means that the arguments should be sanitized before passing. In our case those that require to be sanitized are strings not validated byyargs
itself: paths and locale. For these values there are sanitize functions restricting input to the set of allowed characters, which significantly limits the possible risk (but also reduces characters that can be used in regular paths).To limit the risk exposure
shell: true
is used only on windows platform.Other options considered:
execFile
instead of spawn -execFile
doesn't spawn a shell which makes it safer, however it behaves differently and doesn't handle long running processes and user interaction likespawn
does.eject
use case is fine withexecFile
, butpreview
andtranslate
won't work in this casefs.existsSync
wouldn't prevent injections since a malformed path might be created (there are no limitations in characters)Reference
https://github.com/Redocly/redocly/issues/11284
Testing
Tested on Windows and MacOS with Node versions from before and after the change.
Screenshots (optional)
Check yourself
Security