The file server implements strict path validation to prevent directory traversal attacks and unauthorized file access.
All file operations are restricted to a base directory. By default, this is the ./shared folder in the project root.
Configuration:
- Default:
./shared - Environment Variable: Set
FILE_SERVER_ROOTto customize the base directory
Example:
export FILE_SERVER_ROOT=/path/to/your/files
cargo runThe server validates all incoming paths to ensure:
- No Directory Traversal: Paths containing
..or absolute paths like/are resolved and validated - Confined to Base Directory: All resolved paths must remain within the configured base directory
- Canonical Path Resolution: Uses
canonicalize()to resolve symbolic links and relative paths - Forbidden Responses: Returns
403 Forbiddenfor any attempt to access files outside the allowed directory
All file and folder operations are protected:
POST /api/ls- List files and foldersPOST /api/upload- Upload filesPOST /api/download- Download filesPOST /api/delete- Delete filesPOST /api/mkdir- Create foldersPOST /api/rename-folder- Rename foldersPOST /api/search- Search filesPOST /api/sort- Sorted file listing
❌ Blocked Attempts:
// Trying to access root filesystem
{"path": "/"}
// Directory traversal
{"path": "../../../etc/passwd"}
// Absolute paths outside base
{"path": "/home/user/secrets"}✅ Allowed Access:
// Access within shared directory
{"path": "."}
{"path": "documents"}
{"path": "documents/2024"}The security implementation is located in:
/server/src/utils.rs- Path validation utilities- Applied in all endpoints in
/server/src/endpoints/
Key function: validate_and_resolve_path(requested_path: &str) -> Result<PathBuf, StatusCode>