Skip to content

security: [HIGH] Directory traversal prevention incomplete in AWS uploadFile #2687

@louisgv

Description

@louisgv

Security Issue

Severity: HIGH
File: packages/cli/src/aws/aws.ts:1091-1098
Function: uploadFile()

Description

The uploadFile() function validates remote paths to prevent injection attacks, but the validation is insufficient to prevent directory traversal:

if (
  \!/^[a-zA-Z0-9/_.~-]+$/.test(remotePath) ||
  remotePath.includes("..") ||
  remotePath.split("/").some((s) => s.startsWith("-"))
) {
  throw new Error(`Invalid remote path: ${remotePath}`);
}

While the regex blocks many dangerous characters and the code checks for "..", this approach has subtle gaps:

  1. The regex allows paths like foo/../../etc/passwd (passes character check)
  2. The includes("..") check catches this specific case
  3. However, path normalization edge cases could bypass both checks

Impact

An attacker who can control the remotePath parameter could potentially:

  1. Write files to unintended locations on the remote server
  2. Overwrite critical system files
  3. Bypass application security boundaries

Current Risk: LOW-MEDIUM (existing checks prevent obvious attacks)
Recommended Action: Defense-in-depth hardening

Evidence

Location: packages/cli/src/aws/aws.ts:1091-1098

The function is called from agent setup code where paths are usually hardcoded, reducing practical exploitability. However, it's a public-facing function in the AWS provider module.

Recommendation

Implement canonical path resolution and boundary checking:

import { resolve, normalize } from "node:path";

export async function uploadFile(localPath: string, remotePath: string): Promise<void> {
  // Validate character set
  if (\!/^[a-zA-Z0-9/_.~-]+$/.test(remotePath)) {
    throw new Error(`Invalid characters in remote path: ${remotePath}`);
  }
  
  // Normalize and check for traversal
  const normalized = normalize(remotePath);
  if (normalized.includes("..")) {
    throw new Error(`Path traversal detected: ${remotePath}`);
  }
  
  // Ensure path is within allowed directories (e.g., /home, /tmp)
  const allowedPrefixes = ["/home/", "/tmp/", "~/"];
  if (\!allowedPrefixes.some(prefix => normalized.startsWith(prefix))) {
    throw new Error(`Remote path outside allowed directories: ${remotePath}`);
  }
  
  // Check for leading dash in any path component
  if (normalized.split("/").some((s) => s.startsWith("-"))) {
    throw new Error(`Invalid path component starts with dash: ${remotePath}`);
  }
  
  // ... rest of function
}

Related Issues

Both previous issues had similar path validation gaps that were fixed. AWS provider should use the same hardened approach.


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