Skip to content

security: Unsafe variable expansion in remote SSH command (digitalocean.sh) #3077

@louisgv

Description

@louisgv

Location

sh/e2e/lib/clouds/digitalocean.sh line 189

Vulnerability

The _digitalocean_exec_long function interpolates a base64-encoded command into a remote SSH command string with insufficient quoting:

ssh ... "root@${ip}" "timeout ${timeout_secs} bash -c \"\$(printf '%s' '${encoded_cmd}' | base64 -d)\""

The ${encoded_cmd} variable is expanded inside single quotes that are themselves inside double quotes. This creates a potential command injection vector if encoded_cmd somehow contains a single quote character.

Current Mitigation

The attack surface is mitigated because:

  1. encoded_cmd is base64-encoded from the original command
  2. Base64 output only contains [A-Za-z0-9+/=] characters (no single quotes)

However, this relies on the base64 implementation being correct and the command variable not being corrupted.

Recommended Fix

Pass the base64-encoded command via stdin instead of interpolating it into the remote command string:

printf '%s' "${encoded_cmd}" | ssh ... "root@${ip}" "timeout ${timeout_secs} bash -c '\$(base64 -d)'"

This completely eliminates the interpolation risk.

Severity

MEDIUM - Low exploitability due to base64 encoding, but violates defense-in-depth principles.

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