Skip to content

security: [HIGH] Unsafe eval pattern in cloud_headless_env parsing #2465

@louisgv

Description

@louisgv

Issue

The provision.sh script parses cloud driver output using regex and directly exports variables without sufficient validation (lines 59-65).

Location

sh/e2e/lib/provision.sh:59-65

Code

while IFS= read -r _env_line; do
  if [[ "${_env_line}" =~ ^export[[:space:]]+([A-Za-z_][A-Za-z0-9_]*)=\"(.*)\"$ ]]; then
    export "${BASH_REMATCH[1]}"="${BASH_REMATCH[2]}"
  fi
done <<CLOUD_ENV
$(cloud_headless_env "${app_name}" "${agent}")
CLOUD_ENV

Impact

If a cloud driver implementation has a bug or is compromised, it could inject malicious export lines that:

  1. Override critical environment variables (PATH, LD_PRELOAD)
  2. Inject commands via variable values that are later evaluated
  3. Bypass the regex with edge cases

Recommendation

  1. Validate variable names against a strict whitelist (only known cloud-specific vars)
  2. Validate variable values (reject shell metacharacters)
  3. Use a safer parsing method (e.g., JSON output from cloud drivers instead of shell export lines)

Example:

ALLOWED_VARS="LIGHTSAIL_SERVER_NAME AWS_DEFAULT_REGION LIGHTSAIL_BUNDLE DO_DROPLET_NAME ..."
# Validate BASH_REMATCH[1] is in ALLOWED_VARS before export

-- security/shell-scanner

Metadata

Metadata

Assignees

No one assigned

    Labels

    in-progressIssue is being actively worked onsafe-to-workSecurity triage: safe for automated processing

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions