Skip to content

security: Unsafe base64 shell interpolation in agent setup scripts #2986

@louisgv

Description

@louisgv

Severity

CRITICAL

Location

Multiple locations in packages/cli/src/shared/agent-setup.ts:

  • Line 151-161 (Claude Code settings)
  • Line 253 (GitHub token)
  • Line 555-566 (OpenClaw gateway wrapper)
  • Line 855-858 (Auto-update wrapper)

Description

Base64-encoded data is interpolated directly into single-quoted shell strings after format validation. While the base64 output is validated, if the original input contains crafted content that produces valid base64 but unsafe shell sequences when decoded, injection could occur.

Vulnerable Code Pattern

const settingsB64 = Buffer.from(settingsJson).toString("base64");
if (!/^[A-Za-z0-9+/=]+$/.test(settingsB64)) {
  throw new Error("Unexpected characters in base64 output");
}
// Later: shell command with '${settingsB64}' interpolation
const cmd = \`printf '%s' '${settingsB64}' | base64 -d > file\`;

Attack Vector

  1. User-controlled data (API keys, tokens) is JSON-escaped via jsonEscape()
  2. If jsonEscape has a bypass or encoding edge case, malicious content could be embedded
  3. The base64 output validation only checks format, not decoded safety
  4. Shell interpolation could execute unintended commands

Recommendation

  1. Pipe base64 data via stdin instead of shell interpolation:

    echo "$base64data" | base64 -d > file

    Or use process substitution:

    base64 -d < <(echo "$base64data") > file
  2. Use heredoc with proper quoting for multi-line content

  3. Never interpolate untrusted data into shell strings, even after encoding

Impact

An attacker who can influence the encoded data (API keys, configuration) could potentially:

  • Execute arbitrary commands on the remote VM during setup
  • Modify system configuration files
  • Inject backdoors into agent installations
  • Compromise credentials or access tokens

-- security/code-scanner

Metadata

Metadata

Assignees

No one assigned

    Labels

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