fix Unsafe shell command constructed from library input shell-quote() OS Command Injection#14172
Merged
sobolk merged 1 commit intoaws-amplify:devfrom Apr 21, 2025
odaysec:patch-1
Merged
fix Unsafe shell command constructed from library input shell-quote() OS Command Injection#14172sobolk merged 1 commit intoaws-amplify:devfrom odaysec:patch-1
sobolk merged 1 commit intoaws-amplify:devfrom
odaysec:patch-1
Conversation
sobolk
approved these changes
Apr 21, 2025
Amplifiyer
approved these changes
Apr 21, 2025
Contributor
|
@odaysec Thank you for the contribution. Please keep in mind that The request.srcRoot.
The amplify-cli/packages/amplify-category-function/src/index.ts Lines 233 to 244 in c55512f Amplify CLI controls all inputs involved in |
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.
amplify-cli/packages/amplify-go-function-runtime-provider/src/localinvoke.ts
Line 73 in e936bfd
To fix the problem, we should avoid using
execa.commandwith a dynamically constructed command string. Instead, we can useexecawith an array of arguments to safely pass the executable and its arguments without shell interpretation. This approach ensures that the input is not interpreted by the shell, preventing command injection.execa.commandwithexecaand pass the executable and arguments as an array.lambdaExecutablePathandlambdaExecutableDirare passed as separate arguments to avoid shell interpretation.Dynamically constructing a shell command with inputs from exported functions may inadvertently change the meaning of the shell command. Clients using the exported function may use inputs containing characters that the shell interprets in a special way, for instance quotes and spaces. This can result in the shell command misbehaving, or even allowing a malicious user to execute arbitrary commands on the system.
POC
The following shows a dynamically constructed shell command that downloads a file from a remote URL.
The shell command will, however, fail to work as intended if the input contains spaces or other special characters interpreted in a special way by the shell. Even worse, a client might pass in user-controlled data, not knowing that the input is interpreted as a shell command. This could allow a malicious user to provide the input
http://redactedaws.org; cat /etc/passwdin order to execute the commandcat /etc/passwd. To avoid such potentially catastrophic behaviors, provide the inputs from exported functions as an argument that does not get interpreted by a shell:As another example, consider the following code which is similar to the preceding, but pipes the output of
wgetintowc -lto count the number of lines in the downloaded file.In this case, using
child_process.execFileis not an option because the shell is needed to interpret the pipe operator. Instead, you can useshell-quoteto escape the input before embedding it in the command:References
Command Injection
shell-quote
CWE-78
CWE-88
Checklist
yarn testpassesBy submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.