-
Notifications
You must be signed in to change notification settings - Fork 14
Closed
Labels
in-progressIssue is being actively worked onIssue is being actively worked onsafe-to-workSecurity triage: safe for automated processingSecurity triage: safe for automated processingsecuritySecurity vulnerabilities and concernsSecurity vulnerabilities and concerns
Description
Severity
MEDIUM
Location
packages/cli/src/digitalocean/digitalocean.ts lines 1362-1369, 1402-1409
Description
The remote path validation explicitly allows the $ character to support $HOME expansion:
// uploadFile validation (line 1362-1369)
if (
\!/^[a-zA-Z0-9/_.~$-]+$/.test(normalizedRemote) ||
normalizedRemote.includes("..") ||
normalizedRemote.split("/").some((s) => s.startsWith("-"))
) {
logError(`Invalid remote path: ${remotePath}`);
throw new Error("Invalid remote path");
}
// downloadFile uses the same validation (line 1402-1409)
// Then explicitly expands $HOME (line 1412)
const expandedPath = normalizedRemote.replace(/^$HOME/, "~");Risk
While the code only expands $HOME explicitly (line 1412), the path validation allows ANY $ character. This could enable:
- Unintended variable expansion by the shell during scp/ssh operations
- Information disclosure if environment variables contain sensitive paths
- Potential path traversal via environment variables like
$PWD,$OLDPWD, etc.
Example Attack Vector
If an attacker can control the remotePath parameter:
// Passes validation
uploadFile(localFile, "$OLDPWD/../../etc/passwd")
// Shell expands $OLDPWD, potentially writing outside intended directoryImpact
- Information disclosure via environment variable expansion
- Potential file write/read outside intended directories
- Affects
uploadFileanddownloadFileoperations
Recommendation
-
Strict whitelist: Only allow
$HOMEprefix, reject all other$usage// Reject paths with $ unless exactly "$HOME/..." if (\!/^\$HOME\//.test(remotePath) && remotePath.includes('$')) { throw new Error("Only \$HOME variable expansion is allowed"); }
-
Pre-expansion validation: Expand
$HOMEto~BEFORE the regex checkconst expandedPath = remotePath.replace(/^\$HOME/, "~"); if (\!/^[a-zA-Z0-9/_.~-]+$/.test(expandedPath)) { ... }
-
Remove $ from allowed charset and handle
$HOMEas special case before validation -
Use absolute paths: Require all remote paths to be absolute (start with
/or~) to prevent relative path issues
Similar Issues
This same pattern appears in other cloud providers - recommend auditing:
packages/cli/src/gcp/*packages/cli/src/aws/*packages/cli/src/hetzner/*packages/cli/src/sprite/*
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
in-progressIssue is being actively worked onIssue is being actively worked onsafe-to-workSecurity triage: safe for automated processingSecurity triage: safe for automated processingsecuritySecurity vulnerabilities and concernsSecurity vulnerabilities and concerns