Skip to content

fix: escape SSM parameter values in eval-mode output to prevent shell injection - #49

Open
svvitale wants to merge 1 commit into
masterfrom
fix/secops-25088-eval-shell-injection
Open

fix: escape SSM parameter values in eval-mode output to prevent shell injection#49
svvitale wants to merge 1 commit into
masterfrom
fix/secops-25088-eval-shell-injection

Conversation

@svvitale

Copy link
Copy Markdown
Contributor

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-env is invoked without a command argument, it prints export statements intended to be consumed via eval or source:

export VAR=$'<value>'

$'...' 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:

foo'; rm -rf /; echo '

produces the following output:

export VAR=$'foo'; rm -rf /; echo ''

When eval'd by the shell, this executes rm -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-env reads.

Fix

Added ansiCEscape() in cmd/aws-env/main.go which escapes the two characters with special meaning inside $'...':

  • \\\ (must come first to avoid double-escaping)
  • '\'

The same attack-payload value now produces:

export VAR=$'foo\'; rm -rf /; echo \''

The shell interprets this as a single literal string — no command boundary is introduced.

Testing

Added cmd/aws-env/main_test.go with unit tests covering:

  • Plain values (no change)
  • The injection payload from the ticket report
  • Backslash handling
  • Backslash immediately before a single quote (double-escaping check)
  • Empty string
  • Newlines (unaffected, passed through as-is)

All existing tests continue to pass.

References

  • SECOPS-25088
  • Related: OFFSEC-673

🤖 Generated with Claude Code

… 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-code-sendgrid

Copy link
Copy Markdown

Semgrep found 7 aws-sdk-go-v1 findings:

Usage of github.com/aws/aws-sdk-go (v1) detected.
This SDK has reached End of Life status on 2025-07-31.
You must migrate to aws-sdk-go-v2.

Need help with this issue? Consult our appsec team or ask in #help-appsec on Slack.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant