Skip to content

security: [HIGH] Shell command injection risk in GCP startup script username interpolation #2688

@louisgv

Description

@louisgv

Security Issue

Severity: HIGH
File: packages/cli/src/gcp/gcp.ts:638-640, 646
Function: getStartupScript()

Description

The GCP cloud-init startup script directly interpolates the username parameter into shell commands without explicit quoting. While resolveUsername() validates the username format with /^[a-zA-Z0-9_-]+$/ (line 578), relying solely on upstream validation is fragile. If the validation is bypassed or weakened in the future, this becomes a command injection vector.

Impact

If the username validation is bypassed, an attacker could inject arbitrary shell commands into the cloud-init startup script, which runs as root on the GCP VM during provisioning.

Current Risk: LOW (username validation prevents exploitation)
Defense-in-Depth: The code should be hardened to prevent regression

Evidence

Location: packages/cli/src/gcp/gcp.ts:638-656

The username is interpolated in multiple places:

  • Line 639: su - "${username}" -c '...'
  • Line 645: su - "${username}" -c '...'
  • Line 646: /home/${username}/.bun/bin/bun
  • Line 651: su - "${username}" -c '...' || true

While double-quotes provide some protection, they do not prevent all injection attacks.

Recommendation

Add explicit shell quoting for defense-in-depth:

  1. Validate username format at function entry (redundant check)
  2. Use single-quote escaping for all shell interpolations
  3. Consider using a template library with automatic escaping

Example hardening:

  • Add validation check at start of getStartupScript()
  • Use proper shell escaping for username in all su commands
  • Wrap interpolated values in single quotes with proper escape handling

Related Issues

Multiple previous issues involved similar string interpolation risks in shell command construction. GCP provider should follow the same hardening patterns.


Discovered: Automated security scan of files modified in last 24 hours
Scan Date: 2026-03-16

Metadata

Metadata

Assignees

No one assigned

    Labels

    in-progressIssue is being actively worked onsecuritySecurity vulnerabilities and concernsunder-reviewIssue is being reviewed by the team

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions