Summary
A path traversal vulnerability in o1lab/xmysql allows unauthenticated remote attackers to read or download arbitrary files from the server.
The issue becomes risky when user-controlled file names are combined with a server-side working directory without canonicalization or boundary checks.
Affected context
The vulnerability occurs in the xmysql file-download handling where the req.query.name parameter influences a path passed to res.download. Deployments are exposed when this parameter is accepted from unauthenticated requests and the resulting path is not restricted to an intended directory. The risk depends on the server process permissions and the files available within its runtime environment.
Exploit preconditions
- Attack surface: Network-accessible file-download functionality
- Required access: No authentication may be required
- Trigger point: Processing of the user-controlled
namequery parameter - Why exploitation is possible: Input is joined with a server-side path without sufficient traversal filtering, canonicalization, or enforcement that the resolved path remains within the permitted directory
Why this happens
The underlying bug is improper limitation of a user-controlled path component. The application combines req.query.name with a trusted base directory using path.join but does not adequately normalize and validate the resulting path before passing it to the download response handler.
This maps to CWE-22: Improper Limitation of a Pathname to a Restricted Directory, commonly known as path traversal. The insecure pattern treats externally supplied path data as a safe relative filename without verifying its resolved location against an approved directory boundary.
Potential impact
- An attacker may read sensitive operating system or application files
- An attacker may download configuration files containing credentials or secrets
- The vulnerability could expose source code, logs, and deployment metadata
- Disclosure of sensitive files can enable follow-on compromise of the host or connected services
General mitigation guidance
Mitigation generally focuses on reducing trust in client-supplied paths and enforcing a strict file access boundary.
Common defensive patterns include:
- Accepting opaque file identifiers or an allowlisted set of file names instead of raw path input
- Resolving candidate paths canonically and verifying that they remain beneath the intended directory
- Rejecting traversal indicators and alternate path representations as a supplementary control, not the sole defense
- Restricting downloads to a dedicated directory with minimal contents and permissions
- Running the service with least privilege and limiting access to sensitive filesystem locations
- Applying authentication and authorization controls to file-download functionality where feasible
How teams detect issues like this
Organizations can detect similar issues through:
- Static analysis rules for user input flowing into filesystem APIs such as
path.join,path.resolve, file reads, or download handlers - Code review checks for missing canonicalization and directory-boundary validation
- Tests using varied path encodings and platform-specific path forms to verify confinement to an approved directory
- Runtime logging and alerting for abnormal file-download requests or access outside expected directories
- Policy enforcement requiring allowlisted file resources and authenticated access for sensitive downloads
Automated code review and software composition tools may help identify risky data flows and related file-handling patterns.

