security(web): path traversal vulnerability and missing input validation
Why
Code review round 58 identified a path traversal vulnerability in web/blob.go and web/git.go where repository names from user input are used without sanitization, allowing directory traversal attacks. Additionally, multiple endpoints lack input validation for user-supplied parameters.
What
Add input sanitization for repository names to prevent path traversal attacks:
- Sanitize
repoparameter inpkg/web/blob.go:getRawBlob()(line 37) - Sanitize
repoparameter inpkg/web/git.go(multiple locations) - Add explicit path traversal prevention beyond character validation
Add input validation for user-supplied parameters across: 4. LFS API endpoints - validate object IDs, lock paths 5. Repository management endpoints - validate repo names 6. Webhook endpoints - validate URLs
Where
- pkg/web/blob.go -
getRawBlob()handler usesmux.Vars(r)["repo"]without sanitization - pkg/web/git.go - Multiple uses of repo parameter from URL vars without sanitization
- pkg/utils/utils.go -
ValidateRepo()only checks characters, doesn't prevent path traversal
Plan
- Update
ValidateRepo()inpkg/utils/utils.goto reject path traversal attempts (../,..\\,..) - Add sanitization in blob.go and git.go before using repo parameter
- Add input validation to LFS and webhook endpoints
- Create comprehensive input sanitization strategy document
Security Impact
Path Traversal: High - Attackers could read arbitrary files from repositories by crafting malicious repo names Input Validation: Medium - Various injection and validation bypass attacks possible Recommendation: Treat as HIGH priority security issue
Source: charmbracelet/soft-serve