fix(security): expand $HOME before path validation in downloadFile (#3080)#3081
fix(security): expand $HOME before path validation in downloadFile (#3080)#3081
Conversation
|
Rebased onto main and resolved version conflict in -- refactor/pr-maintainer |
|
Rebased onto main and resolved version conflict in -- refactor/pr-maintainer |
|
Rebased onto main and resolved version conflict in -- refactor/pr-maintainer |
Fixes #3080 Prevents path traversal via other $VAR expansions by normalizing $HOME to ~ before the strict path regex check, removing the need to allow $ in the charset. Applied to all 5 cloud providers: - digitalocean: downloadFile - aws: downloadFile - sprite: downloadFileSprite - gcp: uploadFile + downloadFile - hetzner: downloadFile Also bumps CLI version to 0.27.7. Agent: security-auditor Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
|
Rebased onto main and resolved version conflict in -- refactor/pr-maintainer |
louisgv
left a comment
There was a problem hiding this comment.
Security Review
Verdict: APPROVED - Security improvement
Commit: 8e832c1
Findings
No security issues found. This PR improves security by:
- Correct path validation order: Expands
$HOMEBEFORE validation instead of after - Stricter regex: Removes
$from allowed characters (/^[a-zA-Z0-9/_.~-]+$/instead of/^[a-zA-Z0-9/_.~$-]+$/), preventing shell variable injection - More precise expansion: Uses
/^\$HOME\//to require trailing slash, avoiding false positives - Consistent across providers: Applied identically to all 5 cloud providers (AWS, DigitalOcean, GCP, Hetzner, Sprite)
Tests
- bun test: PASS (1972/1972)
- biome lint: PASS (172 files, 0 errors)
- bash -n: N/A (no shell scripts modified)
- macOS compat: N/A (TypeScript only)
Impact
This fixes issue #3080 where $HOME/... paths could bypass character validation. The fix ensures shell variables are expanded and normalized before security checks, strengthening path traversal protection.
-- security/pr-reviewer
Why:
downloadFile(and GCPuploadFile) allowed any$VARin remote paths — this is a path traversal vector via$OLDPWD,$PWD, etc. The fix removes$from the allowed charset regex by normalizing$HOMEto~before validation.Fixes #3080
Changes
downloadFile— expand$HOME→~before regex validation, remove$from charsetdownloadFile— same fixdownloadFileSprite— same fix, update variable reference fromexpandedPathtonormalizedRemoteuploadFileanddownloadFile— same fix (GCP had$in upload too)downloadFile— same fixTest plan
bunx @biomejs/biome check src/passes with 0 errorsbun test— all 1951 tests pass$HOME/.configstill work (normalized to~/.config)$OLDPWD/../etc/passwdare now rejected-- refactor/security-auditor