Skip to content

security: [provision.sh] Unvalidated base64 value in SSH command allows potential command injection #2527

@louisgv

Description

@louisgv

Location

sh/e2e/lib/provision.sh:176

Severity

HIGH - Defense-in-depth violation, potential command injection

Description

The provision_agent function creates a manual .spawnrc file by base64-encoding sensitive data and passing it to a remote SSH command. However, the env_b64 variable is not validated before use, creating a command injection risk if base64 encoding fails or upstream data is corrupted.

Vulnerable Code

local env_b64
env_b64=$(base64 < "${env_tmp}" | tr -d '\n')
rm -f "${env_tmp}"

# env_b64 used directly without validation
if cloud_exec "${app_name}" "printf '%s' \"${env_b64}\" | base64 -d > ~/.spawnrc && ..."

Issue

  1. No validation that base64 encoding succeeded
  2. No validation that env_b64 contains only base64-safe characters ([A-Za-z0-9+/=])
  3. If env_b64 is empty or contains shell metacharacters due to corruption, it could be exploited

Attack Vectors

  1. Upstream data corruption: If env_tmp file is corrupted or contains malicious content
  2. Base64 command failure: If base64 silently fails or behaves unexpectedly
  3. Environment variable manipulation: If an attacker can influence OPENROUTER_API_KEY before it's base64-encoded

Impact

  • Remote command execution on provisioned VMs
  • Credential theft (since this code handles API keys)
  • Compromise of E2E test infrastructure

Recommendation

Add validation before use:

local env_b64
env_b64=$(base64 < "${env_tmp}" | tr -d '\n')
rm -f "${env_tmp}"

# VALIDATE env_b64 is non-empty and contains only base64 characters
if [[ -z "${env_b64}" ]] || [[ ! "${env_b64}" =~ ^[A-Za-z0-9+/=]+$ ]]; then
    log_err "Base64 encoding failed or produced invalid output"
    return 1
fi

# Safe to use now
if cloud_exec "${app_name}" "printf '%s' \"${env_b64}\" | base64 -d > ~/.spawnrc && ..."

Additional hardening:

  • Use -- to prevent env_b64 being interpreted as a flag
  • Consider using heredoc for even better safety

References

  • CWE-77: Improper Neutralization of Special Elements used in a Command
  • Defense in Depth: Always validate before use in sensitive contexts

Filed automatically by security/shell-scanner

Metadata

Metadata

Assignees

No one assigned

    Labels

    safe-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