Summary
FileRise before 3.16.0 contains a path traversal flaw in the shared-folder upload endpoint that allows crafted filenames to escape the intended upload directory and overwrite arbitrary files on the server.
An attacker with a valid upload-enabled shared-folder link can abuse URL-encoded path separators to overwrite application data such as users/users.txt, leading to administrator account takeover and potentially remote code execution.
Affected context
This vulnerability affects FileRise instances that expose the shared-folder upload endpoint (/api/folder/uploadToSharedFolder.php) and rely on upload-enabled links or tokens that may be shared with external users.
It manifests when filenames are validated only in their encoded form and are later URL-decoded and used to build filesystem paths without a containment check.
Environments where the application stores authentication or configuration data in predictable, writable locations (such as users/users.txt) are at higher risk of account takeover or remote code execution.
Exploit preconditions
- Attack surface: HTTP POST requests to
/api/folder/uploadToSharedFolder.php. - Required access: Possession of a valid, non-expired, upload-enabled shared-folder link/token (intended for semi-public sharing).
- Trigger point: Submission of an uploaded file whose
filenameparameter contains URL-encoded directory traversal sequences (e.g.,..%2f). - Why exploitation is possible:
- Initial validation applies
basename()andREGEX_FILE_NAMEto the raw (encoded) filename, blocking literal/and\but allowing%. - The code then calls
trim(urldecode(basename($fileName))), reintroducing path separators after validation (e.g.,..%2fusers%2fusers.txtbecomes../users/users.txt). UploadNamePolicy::isAllowedForWrite()appliesbasename()again, only checking the final component (e.g.,users.txt) and ignoring the traversal portion.- The resulting path is passed directly into
move_uploaded_file()withoutrealpath-based containment checks, enabling writes outside the intended upload directory.
Why this happens
The root cause is an improper neutralization of special elements in a path before using it in filesystem operations, aligning with CWE-22: Improper Limitation of a Pathname to a Restricted Directory.
Validation is performed on the URL-encoded representation of the filename and relies on basename() plus a regex that blocks only literal directory separators, not their encoded forms.
Afterwards, the code URL-decodes the basename and reconstructs the path, effectively bypassing the earlier validation and allowing .. and directory separators into the effective path.
A secondary issue is that security checks in UploadNamePolicy::isAllowedForWrite() only inspect the final path component, not the full path hierarchy, and there is no realpath containment or chroot-style enforcement around the upload directory.
This insecure pattern—validating one representation of a path but using another, combined with incomplete path canonicalization—leaves the file write sink (move_uploaded_file) exposed to traversal sequences.
Potential impact
- Overwrite of arbitrary files writable by the web server user within the application filesystem.
- Creation or modification of
users/users.txtor equivalent credential stores to add or elevate an administrator account. - Unauthorized administrator access to the FileRise instance without prior authentication.
- Potential remote code execution if an attacker can overwrite configuration, script files, or plugin components that the server executes.
- Loss of integrity for user data stored in shared folders or application directories.
- Facilitation of further lateral movement within the hosting environment or connected services.
General mitigation guidance
Effective mitigation focuses on strict path handling, consistent decoding, and reducing trust in user-supplied filenames:
- Validate after decoding: Normalize and URL-decode filenames before any validation. Apply validation rules to the decoded value that will actually be used.
- Enforce no path separators: Reject any upload filename containing
/,\,.., or equivalent Unicode/encoded separators; only allow a conservative character set (e.g., alphanumerics plus a small safe subset). - Canonicalization and containment: Use
realpath()or equivalent to compute the canonical filesystem path and verify that it resides inside the designated upload directory before performing any write. - Separate name from path: Treat the user-provided filename as a label only; generate server-side unique names and always prepend a fixed, trusted upload directory.
- Least privilege for the web process: Run the application with minimal filesystem permissions, restricting write access to a dedicated upload directory that does not hold configuration, code, or authentication data.
- Harden authentication data storage: Store sensitive user and admin account data outside web-writable areas and behind stricter access controls, avoiding text files in the general application tree where possible.
How teams detect issues like this
Detection can leverage both static and runtime analysis:
- Static code review:
- Search for
move_uploaded_file, file write APIs, or upload handlers that use user-supplied filenames or paths. - Flag any logic where validation is applied to the encoded form of input while a decoded form is later used in path construction.
- Identify uses of
basename()as the only safeguard against traversal, especially when combined with URL-decoding or string concatenation. - Static analysis tooling:
- Configure SAST rules to detect missing
realpath()containment checks before file writes. - Add patterns that warn when
urldecode()is used near file path operations without subsequent validation on the decoded value. - Runtime monitoring:
- Log all upload paths and alert on paths containing
../, unusual directory hierarchies, or writes outside expected upload directories. - Monitor for unexpected changes to sensitive files such as user account stores or configuration files shortly after upload operations.
- Policy enforcement:
- Employ secure coding guidelines for file uploads, and enforce them via pre-commit hooks or CI checks that scan for risky file API usage.

