fix(updateServer): uncontrolled command line via execFileSync
#3414
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.
workbox/demos/src/workbox-window/updateServer.js
Line 20 in e26d8d7
workbox/demos/src/workbox-window/updateServer.js
Lines 32 to 35 in e26d8d7
Fix the issue the code should avoid interpolating untrusted user input directly into a shell command. Instead, use safer alternatives such as
execFileSync
, which accepts arguments as an array and does not spawn a shell by default. This approach prevents command injection by treating each argument as a literal value rather than part of a shell command. Additionally, validate therepoUrl
input to ensure it conforms to expected patterns (e.g., a valid URL or repository name).Steps to fix:
execSync
withexecFileSync
to avoid spawning a shell.repoUrl
as an argument in an array toexecFileSync
.repoUrl
to ensure it is a safe and expected value (e.g., using a regular expression or an allowlist).Code that passes untrusted user input directly to
child_process.exec
or similar APIs that execute shell commands allows the user to execute malicious code.References
shell-quote