Summary
A path traversal vulnerability in rustypaste allows a custom filename supplied through an HTTP header to escape the configured upload directory. An attacker who can submit uploads may write files to arbitrary filesystem locations when the application validates the destination before incorporating the custom filename.
Affected context
The vulnerability occurs in rustypaste deployments that support an optional custom filename HTTP header and validate the upload destination before applying that filename. When path components from the header are not revalidated against the configured directory, a crafted upload request may resolve outside the intended storage location.
Exploit preconditions
- Attack surface: HTTP upload functionality
- Required access: Ability to submit an upload request and provide the custom filename header
- Trigger point: Construction of the final destination path during upload handling
- Why exploitation is possible: Directory-boundary validation is performed before the attacker-controlled filename is incorporated, allowing the final path to escape the configured upload directory
Why this happens
The underlying bug is an order-of-validation error combined with insufficient path canonicalization. The application checks a destination path before incorporating attacker-controlled filename data, so the security decision does not cover the final path that will be used for file creation. This maps to CWE-22: Improper Limitation of a Pathname to a Restricted Directory, in which untrusted path components can influence filesystem access outside an intended directory.
Potential impact
- Attackers may write files outside the configured upload directory
- Sensitive files may be overwritten or corrupted
- Application configuration or executable files could be modified
- The service may experience denial of service
- Arbitrary file writes could contribute to code execution, depending on filesystem permissions and file locations
General mitigation guidance
Mitigation generally focuses on treating filenames as untrusted data and validating the complete destination path after all user-controlled components have been incorporated.
Common defensive patterns include:
- Resolve and canonicalize the final path before performing filesystem operations
- Enforce that the resolved path remains within a dedicated upload directory
- Prefer generated server-side filenames over client-supplied names
- Reject path separators, traversal components, and unexpected encoding forms where custom names are supported
- Store uploads under a separate, minimally privileged account or service identity
- Apply restrictive filesystem permissions and avoid placing uploads in executable locations
- Use isolated storage with quotas and controlled overwrite behavior
How teams detect issues like this
Organizations can identify similar issues through:
- Static analysis rules for unsafe path joins involving request headers or form fields
- Code review checks confirming validation occurs after complete path construction
- Tests using normalized, encoded, absolute, and platform-specific path components
- Runtime monitoring for writes outside approved upload directories
- Filesystem policy enforcement that limits the service to a dedicated storage area
- Automated security review tools that flag user-controlled input reaching file APIs without containment checks

