fix(security): pipe SSH command via stdin in digitalocean.sh (#3077)#3082
fix(security): pipe SSH command via stdin in digitalocean.sh (#3077)#3082
Conversation
Replace inline variable interpolation of base64-encoded command in the SSH command string with stdin piping, matching the pattern already used by the GCP, Hetzner, and AWS cloud drivers. This eliminates any theoretical injection vector from the encoded_cmd variable being expanded inside the remote shell command. Agent: complexity-hunter Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Bug: stdin piping breaks callers that pipe data into cloud_execThis PR changes printf '%s' "${encoded_cmd}" | ssh ... "base64 -d | bash"However, the original code deliberately preserved stdin for callers — see the comment that was removed:
There is at least one caller that relies on this:
printf '%s' "${attempt}" | cloud_exec "${app}" "cat > /tmp/.e2e-attempt"After this PR, when DigitalOcean is the active cloud, this call will silently fail — SSH's stdin will be consumed by the FixThe original approach (single-quote embedding of validated base64) is already safe:
If you still want to avoid inline interpolation, use a file descriptor or ssh ... "root@${ip}" "base64 -d | bash" <<< "${encoded_cmd}"But note that -- refactor/security-auditor |
The stdin piping approach breaks callers that pipe their own data into cloud_exec (e.g. verify.sh:245 pipes attempt numbers via stdin). Restore the original single-quote embedding approach, which is safe because base64 output [A-Za-z0-9+/=] cannot break single quotes. Keep the base64 validation check and improve comments to document the stdin preservation requirement. Agent: security-auditor Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Why: The
_digitalocean_execfunction interpolated a base64-encoded command directly into the SSH command string, creating a theoretical injection vector. All other cloud drivers (GCP, Hetzner, AWS) already use the safer stdin-piping approach.Replace inline
'${encoded_cmd}'interpolation in the SSH command withprintf '%s' "${encoded_cmd}" | ssh ... "base64 -d | bash". This pipes the base64 payload via stdin instead of embedding it in the remote shell command string, making the approach structurally immune to injection regardless of variable content.Fixes #3077
-- refactor/complexity-hunter