Harden ssm_refresh_ecr_auth JSON parameter construction in scripts/promote-tenant-image.sh #676

Closed
opened 2026-05-12 05:13:28 +00:00 by hongming · 0 comments
Owner

From

Five-Axis review of #672 (sub-agent dispatch, comment #14939) flagged this as a non-blocking medium-severity finding.

What

scripts/promote-tenant-image.sh:ssm_refresh_ecr_auth() builds the --parameters JSON via printf with shell-unquoted interpolation of $REGION and $ECR_ACCOUNT_ID:

printf '{"commands":["aws ecr get-login-password --region %s | docker login --username AWS --password-stdin %s.dkr.ecr.%s.amazonaws.com"]}' \
  "$REGION" "$acct" "$REGION" > "$params"

If either var contained a double-quote, backslash, or other JSON-special character, the resulting parameters file would be invalid JSON (or worse, a shell-command-injection seam if the embedded shell command splits on whitespace).

Exploit prerequisite: an attacker must already control the script's caller-supplied flags (--region, --repo) or the ECR_ACCOUNT_ID env var. That's an authenticated-operator threat model, not external — hence non-blocking. But the validation is cheap.

Fix

Validate at argparse time:

[[ "$REGION" =~ ^[a-z0-9-]+$ ]] || { printf 'invalid --region: %s\n' "$REGION" >&2; exit 64; }
[[ "${ECR_ACCOUNT_ID:-}" =~ ^[0-9]{12}$ ]] || { printf 'invalid ECR_ACCOUNT_ID: %s\n' "$ECR_ACCOUNT_ID" >&2; exit 64; }

Add a test case in scripts/test-promote-tenant-image.sh that asserts exit 64 when --region '"x";rm -rf /' is passed.

Tier

low — defense-in-depth on an authenticated-operator-only threat model. Easy fix.

Cross-link

  • Parent PR: #672 (merged with finding noted)
  • Five-Axis review comment: #14939
## From Five-Axis review of #672 (sub-agent dispatch, comment #14939) flagged this as a non-blocking medium-severity finding. ## What `scripts/promote-tenant-image.sh:ssm_refresh_ecr_auth()` builds the `--parameters` JSON via `printf` with shell-unquoted interpolation of `$REGION` and `$ECR_ACCOUNT_ID`: ```bash printf '{"commands":["aws ecr get-login-password --region %s | docker login --username AWS --password-stdin %s.dkr.ecr.%s.amazonaws.com"]}' \ "$REGION" "$acct" "$REGION" > "$params" ``` If either var contained a double-quote, backslash, or other JSON-special character, the resulting parameters file would be invalid JSON (or worse, a shell-command-injection seam if the embedded shell command splits on whitespace). Exploit prerequisite: an attacker must already control the script's caller-supplied flags (`--region`, `--repo`) or the `ECR_ACCOUNT_ID` env var. That's an authenticated-operator threat model, not external — hence non-blocking. But the validation is cheap. ## Fix Validate at argparse time: ```bash [[ "$REGION" =~ ^[a-z0-9-]+$ ]] || { printf 'invalid --region: %s\n' "$REGION" >&2; exit 64; } [[ "${ECR_ACCOUNT_ID:-}" =~ ^[0-9]{12}$ ]] || { printf 'invalid ECR_ACCOUNT_ID: %s\n' "$ECR_ACCOUNT_ID" >&2; exit 64; } ``` Add a test case in `scripts/test-promote-tenant-image.sh` that asserts exit 64 when `--region '"x";rm -rf /'` is passed. ## Tier low — defense-in-depth on an authenticated-operator-only threat model. Easy fix. ## Cross-link - Parent PR: #672 (merged with finding noted) - Five-Axis review comment: #14939
hongming added the tier:low label 2026-05-12 05:13:33 +00:00
core-security was assigned by hongming 2026-05-12 05:13:35 +00:00
core-security was unassigned by core-devops 2026-05-12 05:28:24 +00:00
core-devops self-assigned this 2026-05-12 05:28:29 +00:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: molecule-ai/molecule-core#676