Summary
A path traversal flaw in the ruoyi-vue-pro AppFileController upload endpoint allows attackers to manipulate the generated upload path and escape intended storage directories.
When user-supplied file paths or names are not properly normalized and validated, a remote attacker can potentially write files to arbitrary locations on the server filesystem.
Affected context
The vulnerability occurs in deployments of the ruoyi-vue-pro application that expose the AppFileController file upload endpoint and rely on FileServiceImpl.generateUploadPath to determine where uploaded content is stored.
It becomes relevant when the upload path or filename incorporates user-controlled input without robust normalization or directory constraints, and when the application runs with permissions that allow writing beyond the intended upload directory.
In typical setups, this affects environments where file uploads are accepted from remote clients as part of application functionality.
Exploit preconditions
- Attack surface: HTTP file upload endpoint exposed by AppFileController.
- Required access: Ability to send crafted upload requests (e.g., authenticated or unauthenticated user, depending on deployment configuration).
- Trigger point: Invocation of
generateUploadPathwhen processing an upload request, using data influenced by user-controlled fields (such as filename or path segments). - Why exploitation is possible: The path generation logic does not sufficiently sanitize or normalize input to prevent directory traversal sequences (e.g.,
../), allowing constructed paths to escape the intended upload root.
Why this happens
This vulnerability stems from improper validation of file paths derived from user input, aligning with CWE-22: Improper Limitation of a Pathname to a Restricted Directory ('Path Traversal').
The generateUploadPath function builds filesystem paths without strictly enforcing that the final resolved path remains within a designated upload directory.
By failing to canonicalize and validate paths before use, the application allows user-controlled segments to influence directory navigation, enabling traversal outside the expected storage area in an abstract sense.
Potential impact
- Attackers may write files to unexpected locations on the server filesystem.
- Malicious uploads could overwrite or replace existing application or configuration files.
- Uploaded content can be placed in web-accessible locations, potentially enabling code or script execution depending on server configuration.
- Sensitive data may be exposed or corrupted if application logs or other files are targeted.
- The overall integrity of the application environment could be undermined through filesystem abuse.
General mitigation guidance
Effective mitigation focuses on constraining filesystem operations to well-defined, trusted directories and minimizing reliance on user-controlled path components.
Common defensive patterns include:
- Constructing upload paths from server-side identifiers (such as UUIDs) instead of raw client-provided filenames or subpaths.
- Canonicalizing the computed path and verifying that it resides within a preconfigured upload root before any write operation.
- Stripping or rejecting directory traversal patterns and illegal characters from filenames and path segments.
- Applying least-privilege file system permissions so the application process can only write to designated upload directories.
- Using storage abstractions (such as object stores) that reduce direct interaction with the server's local filesystem.
These patterns collectively reduce the risk of path traversal and make file handling more robust by default.
How teams detect issues like this
Organizations can detect path traversal risks by combining code-level analysis with operational monitoring:
- Static analysis rules that flag uses of user-controlled input in filesystem APIs (
File,Paths,FileOutputStream) without prior normalization and directory checks. - Code review guidelines focusing on any method that constructs paths from request parameters or uploaded filenames, checking for canonicalization and root directory enforcement.
- Runtime security controls or WAF rules that inspect upload requests for traversal sequences (such as
../, encoded variants, or suspicious path patterns). - Logging and alerting around file write operations, particularly when writes occur outside the expected upload directory structure.
Automated code review tools and SAST solutions can help consistently surface these patterns during development.

