Summary
PsiTransfer's upload PATCH endpoint mishandles encoded versus decoded path values, allowing an attacker to write files outside the intended upload directory in certain custom deployments.
In environments where the upload directory name prefixes a JavaScript configuration path, an unauthenticated attacker can create a config.<NODE_ENV>.js file in the application root that will be executed on the next process restart.
Affected context
This vulnerability appears in PsiTransfer deployments that:
- Expose the
/files/:uploadIdtus upload PATCH endpoint to unauthenticated clients - Use a custom
PSITRANSFER_UPLOAD_DIRwhose basename prefixes a startup-loaded JavaScript configuration path (for example,confleading toconfig.<NODE_ENV>.js) - Run in an environment where application configuration files (like
config.<NODE_ENV>.js) are loaded and executed from the application root on process start
Under these conditions, mismatched validation and write paths between encoded req.path and decoded req.params.uploadId can let uploads escape the intended directory layout.
Exploit preconditions
- Attack surface: HTTP PATCH requests to the
/files/:uploadIdendpoint using the tus upload protocol - Required access: No authentication required; the endpoint is typically public for file uploads
- Trigger point: Sending a crafted
uploadIdthat, once decoded, resolves to a path that overlaps with or escapes toward a JavaScript configuration filename in the application root - Why exploitation is possible:
- The framework validates the mounted path using the still-encoded
req.path, assuming it constrains the upload to the configured directory - The downstream tus handler later interprets and writes using the decoded
req.params.uploadId - When
PSITRANSFER_UPLOAD_DIRis chosen such that its basename prefixes a config filename path, the decoded upload ID can be manipulated so the resulting write lands atconfig.<NODE_ENV>.jsin the application root
Why this happens
The bug stems from inconsistent use of encoded versus decoded request path values when validating and using filesystem paths.
The application checks mount constraints against the encoded req.path, implicitly assuming that this validation guarantees that subsequent operations will stay within the upload directory.
However, the tus handler later uses the decoded req.params.uploadId to derive the actual file system path, effectively bypassing the earlier validation.
This pattern maps to CWE-22: Improper Limitation of a Pathname to a Restricted Directory, where user-controlled path segments are insufficiently normalized and constrained before being used for file writes, enabling directory traversal or arbitrary file write into sensitive locations.
Potential impact
- Attacker-controlled creation of
config.<NODE_ENV>.jsin the application root - Execution of attacker-supplied JavaScript code on the next application restart
- Full compromise of the server-side application runtime (remote code execution on restart)
- Tampering with application behavior, including authentication, logging, or routing logic defined in configuration
- Potential pivot to broader system compromise depending on runtime privileges
General mitigation guidance
Effective mitigation focuses on strict, normalized path handling and isolation of upload data:
- Normalize and validate all path components after decoding, ensuring the final resolved path is within an expected upload root directory
- Treat
uploadIdand similar identifiers as opaque tokens, not as file paths; map them through a safe lookup (e.g., an ID-to-filename mapping) rather than using them directly in filesystem operations - Use filesystem APIs that operate on precomputed, canonical paths and compare them against an expected base directory before writing
- Avoid choosing upload directories whose names overlap or prefix sensitive configuration or code paths in the application root
- Separate writable upload locations from executable or configuration directories, and configure runtimes so that user-writable locations are never interpreted as code
How teams detect issues like this
Organizations can look for this class of issue using:
- Static analysis patterns:
- Identification of request path parameters (e.g.,
req.params.uploadId,req.path) being concatenated or interpolated into filesystem paths - Checks that path validation occurs after URL decoding and that canonicalization (e.g., resolving
.., symlinks) is performed before use - Rules that flag code writing to executable or configuration directories using user-controlled data
- Code review signals:
- Inconsistent usage of encoded versus decoded path variables
- Use of URL or path segments from HTTP requests as direct filenames without normalization and boundary checks
- Writable directories located in or adjacent to code/config folders
- Policy enforcement and tooling:
- CI checks to prevent new code paths that mix HTTP parameters and filesystem operations without canonicalization
- Optional use of dependency and configuration scanners to flag applications where upload directories and configuration directories overlap or share naming patterns

