-
Notifications
You must be signed in to change notification settings - Fork 8
Description
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:
- The regex allows paths like
foo/../../etc/passwd(passes character check) - The
includes("..")check catches this specific case - However, path normalization edge cases could bypass both checks
Impact
An attacker who can control the remotePath parameter could potentially:
- Write files to unintended locations on the remote server
- Overwrite critical system files
- 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
- Issue security: [HIGH] Unvalidated localPath parameter in gcp.ts uploadFile() #2521: Similar validation issue in GCP
uploadFile()(closed) - Issue security: Potential command injection in daytona uploadFile function #2130: Daytona
uploadFileinjection (closed)
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