Summary
A path traversal vulnerability in luci-app-openvpn allows authenticated users to bypass the intended upload directory through insufficient validation of the instance_name2 parameter. An attacker may write arbitrary files to accessible system locations, potentially enabling persistent root code execution when malicious files are processed during reboot.
Affected context
The issue occurs in luci-app-openvpn file-upload functionality when the instance_name2 parameter influences the destination path without adequately restricting it to the intended directory. Exploitation depends on an authenticated account being able to reach the upload endpoint and the target system allowing the written file to affect startup, authentication, or another privileged execution path.
Exploit preconditions
- Attack surface: Authenticated web-based file-upload functionality in luci-app-openvpn
- Required access: Valid credentials with permission to access the affected upload operation
- Trigger point: Processing of an upload request containing a path-manipulating
instance_name2value - Why exploitation is possible: The destination path is not sufficiently constrained, allowing uploaded content to be written outside the designated directory
- Additional condition for persistence: A writable system location must be linked to a privileged startup, authentication, or reboot-time processing path
Why this happens
The vulnerability results from treating a user-controlled filename or instance identifier as a trusted filesystem path. When path components are not canonicalized and constrained to an approved directory, an attacker can influence path resolution and escape the intended upload location. This behavior maps to CWE-73: External Control of File Name or Path, because external input controls filesystem access without adequate boundary enforcement.
Potential impact
- Arbitrary files may be written outside the intended upload directory
- System configuration or authentication-related files could be modified
- Persistent access may be established across reboots
- The attacker may gain root-level code execution
- Device confidentiality, integrity, and availability could be compromised
General mitigation guidance
Mitigation generally focuses on making upload destinations independent of untrusted path input and enforcing strict filesystem boundaries.
Common defensive patterns include:
- Generate server-side storage names rather than accepting path components from clients
- Canonicalize candidate paths and verify that they remain within an approved directory
- Reject traversal markers, absolute paths, symbolic-link escapes, and unexpected separators
- Apply strict allowlists for instance identifiers and uploaded file types
- Store uploads in non-executable locations with restrictive ownership and permissions
- Run the management service with the minimum privileges required for its operations
- Separate upload handling from privileged system directories and startup mechanisms
How teams detect issues like this
Detection can combine application testing, source review, and filesystem monitoring.
Useful approaches include:
- Static analysis rules that flag user-controlled values passed to file path construction or file-write APIs
- Code review checks for missing canonicalization, directory-boundary validation, and symlink handling
- Dynamic tests using benign path-boundary cases to verify that uploads cannot leave the approved directory
- Web application logs that identify unusual upload destinations, rejected path values, or repeated traversal attempts
- File-integrity monitoring for unexpected changes to system, startup, and authentication-related locations
- Policy enforcement requiring centralized upload helpers and approved path-validation libraries

