fix: escape SSM parameter values in eval-mode output to prevent shell injection - #49
Open
svvitale wants to merge 1 commit into
Open
fix: escape SSM parameter values in eval-mode output to prevent shell injection#49svvitale wants to merge 1 commit into
svvitale wants to merge 1 commit into
Conversation
… injection
SECOPS-25088: unescaped SSM parameter value in eval-mode output allows
shell command execution on the consuming host.
When aws-env runs without a command argument it prints export statements
for use with eval/source:
export VAR=$'<value>'
$'...' (ANSI-C quoting) terminates at an unescaped single quote. A
malicious or attacker-controlled SSM value containing a single quote
could break out of the quoting context and inject arbitrary shell
commands on the consuming host. For example, a value of
foo'; rm -rf /; echo '
would produce:
export VAR=$'foo'; rm -rf /; echo ''
which executes rm -rf / when eval'd.
The fix escapes backslashes (\ -> \\) before single quotes (' -> \')
within the ANSI-C quoted string, so special characters are preserved as
literal values. The backslash pass must come first to avoid
double-escaping characters that were already backslashes in the input.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
|
Semgrep found 7
Usage of github.com/aws/aws-sdk-go (v1) detected. Need help with this issue? Consult our appsec team or ask in #help-appsec on Slack. |
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.
Summary
Fixes SECOPS-25088: a HackerOne bug bounty submission reporting that unescaped SSM parameter values in aws-env's eval-mode output can allow shell command execution on the consuming host.
Vulnerability
When
aws-envis invoked without a command argument, it printsexportstatements intended to be consumed viaevalorsource:$'...'is ANSI-C quoting in bash/zsh. This quoting style terminates at an unescaped single quote. If an SSM parameter value contains a', it breaks out of the quoted context. A malicious or attacker-controlled value such as:produces the following output:
When
eval'd by the shell, this executesrm -rf /with the permissions of the calling process.Attack surface
Any caller using the eval-mode pattern (common in container entrypoints and shell scripts) is affected if an attacker can write a crafted value to an SSM parameter path that
aws-envreads.Fix
Added
ansiCEscape()incmd/aws-env/main.gowhich escapes the two characters with special meaning inside$'...':\→\\(must come first to avoid double-escaping)'→\'The same attack-payload value now produces:
The shell interprets this as a single literal string — no command boundary is introduced.
Testing
Added
cmd/aws-env/main_test.gowith unit tests covering:All existing tests continue to pass.
References
🤖 Generated with Claude Code