Potential fix for code scanning alert no. 11: Unsafe shell command constructed from library input #46
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.
Potential fix for https://github.com/Layr-Labs/ecloud/security/code-scanning/11
To mitigate the possibility of shell injection or command misbehavior, the best way to fix this is to avoid constructing the shell command via string concatenation with user/library input. Instead, pass command arguments as arrays to APIs that do not invoke a shell (such as
child_process.execFile). In the case that shell features (such as pipes or redirects) are required, inputs must be safely escaped using a library such asshell-quote.For the case in question (
verifyImageExistsusingexecAsyncto rundocker manifest inspect ${imageRef}), we should replace it withexecFileAsync, passing the command and arguments as an array so theimageRefis not interpreted by the shell.This requires us to define an appropriate async wrapper around
execFile(e.g., usingpromisifyas withexec), and update the usage to pass command and args accordingly.Edits are limited to
packages/sdk/src/client/common/docker/push.tsin the region whereexecAsyncis invoked fordocker manifest inspect ${imageRef}.Required changes:
execFile(e.g.,execFileAsync)execAsynchere withexecFileAsync, passing command asdocker, then an array of args (["manifest", "inspect", imageRef]), and optionsexecAsynccould receive tainted input, ensure argument arrays rather than concatenated strings are usedSuggested fixes powered by Copilot Autofix. Review carefully before merging.