Summary
A command injection vulnerability in the AWS SAM CLI Terraform hook may allow arbitrary operating system commands to run when a crafted Terraform resource address is processed.
The risk arises when an attacker can influence the Terraform configuration or plan file consumed by a build, potentially enabling command execution with the privileges of the build user on the host.
A command injection vulnerability in the AWS SAM CLI Terraform hook may allow arbitrary operating system commands to run when a crafted Terraform resource address is processed.
The risk arises when an attacker can influence the Terraform configuration or plan file consumed by a build, potentially enabling command execution with the privileges of the build user on the host.
Affected context
The vulnerability occurs in AWS SAM CLI builds that use the Terraform hook to consume Terraform configuration or plan data. It becomes risky when those inputs can be modified or supplied by an untrusted party and the build process interprets a crafted Terraform resource address in a command-execution context.
The vulnerability occurs in AWS SAM CLI builds that use the Terraform hook to consume Terraform configuration or plan data. It becomes risky when those inputs can be modified or supplied by an untrusted party and the build process interprets a crafted Terraform resource address in a command-execution context.
Exploit preconditions
- Attack surface: The AWS SAM CLI Terraform hook used during a build
- Required access: Ability to influence the Terraform configuration or plan file consumed by the build
- Trigger point: Processing of a crafted Terraform resource address
- Why exploitation is possible: Input-derived resource data reaches an operating system command without sufficient separation from command syntax
- Attack surface: The AWS SAM CLI Terraform hook used during a build
- Required access: Ability to influence the Terraform configuration or plan file consumed by the build
- Trigger point: Processing of a crafted Terraform resource address
- Why exploitation is possible: Input-derived resource data reaches an operating system command without sufficient separation from command syntax
Why this happens
The underlying bug is an OS command injection condition mapped to CWE-78. The Terraform hook incorporates attacker-influenced resource address data into a command or command-like operation without reliably treating it as data.
This insecure pattern allows shell or operating-system command interpretation to occur where only a resource identifier was expected. The issue is amplified when builds run with broad host permissions or process untrusted infrastructure inputs.
The underlying bug is an OS command injection condition mapped to CWE-78. The Terraform hook incorporates attacker-influenced resource address data into a command or command-like operation without reliably treating it as data.
This insecure pattern allows shell or operating-system command interpretation to occur where only a resource identifier was expected. The issue is amplified when builds run with broad host permissions or process untrusted infrastructure inputs.
Potential impact
- An attacker may execute arbitrary commands as the build user
- Build credentials, tokens, or environment data could be exposed
- The host running the build could be modified or compromised
- Build artifacts or generated infrastructure outputs could be tampered with
- The vulnerability could support lateral movement when the build environment has network or cloud privileges
- An attacker may execute arbitrary commands as the build user
- Build credentials, tokens, or environment data could be exposed
- The host running the build could be modified or compromised
- Build artifacts or generated infrastructure outputs could be tampered with
- The vulnerability could support lateral movement when the build environment has network or cloud privileges
General mitigation guidance
Mitigation generally focuses on preventing untrusted Terraform-derived values from reaching operating-system command interpreters.
Common defensive patterns include:
- Passing resource addresses as structured arguments rather than concatenating them into shell commands
- Avoiding shell evaluation and disabling unnecessary command interpretation
- Applying strict allowlists and canonical validation to resource identifiers
- Treating Terraform configuration and plan files as untrusted build inputs
- Running builds with dedicated, least-privileged identities and isolated workers
- Limiting access to cloud credentials, host filesystems, and sensitive environment variables
- Maintaining a supported, remediated AWS SAM CLI release through normal dependency-management processes
Mitigation generally focuses on preventing untrusted Terraform-derived values from reaching operating-system command interpreters.
Common defensive patterns include:
- Passing resource addresses as structured arguments rather than concatenating them into shell commands
- Avoiding shell evaluation and disabling unnecessary command interpretation
- Applying strict allowlists and canonical validation to resource identifiers
- Treating Terraform configuration and plan files as untrusted build inputs
- Running builds with dedicated, least-privileged identities and isolated workers
- Limiting access to cloud credentials, host filesystems, and sensitive environment variables
- Maintaining a supported, remediated AWS SAM CLI release through normal dependency-management processes
How teams detect issues like this
Detection can include static analysis for shell-command construction involving Terraform-derived values, especially string concatenation, interpolation, shell wrappers, and subprocess calls that do not use argument arrays.
Code review should examine whether resource addresses are validated against an allowlist and whether command execution is necessary at all. CI policies can flag unsafe subprocess patterns, require isolated build workers for untrusted plans, and restrict credentials available to build jobs. Automated security review tools may help identify command construction and tainted-data flows.
Detection can include static analysis for shell-command construction involving Terraform-derived values, especially string concatenation, interpolation, shell wrappers, and subprocess calls that do not use argument arrays.
Code review should examine whether resource addresses are validated against an allowlist and whether command execution is necessary at all. CI policies can flag unsafe subprocess patterns, require isolated build workers for untrusted plans, and restrict credentials available to build jobs. Automated security review tools may help identify command construction and tainted-data flows.
Sources
| Source | Link |
|---|---|
| aws. | aws.amazon.com/ |
| github. | github.com/ |
| github. | github.com/ |

