Summary
An unauthenticated path traversal vulnerability in the MindsDB file upload API allows arbitrary file reads from the server filesystem when using JSON-based uploads with a non-url source_type.
Because user-controlled path components are joined directly into filesystem paths without sanitization, an attacker can cause the server to ingest and expose sensitive files by moving them into MindsDB's internal storage.
Affected context
The issue arises in MindsDB deployments that expose the file upload API and accept JSON request bodies for uploads where source_type is not "url".
In this code path, the PUT handler in file.py directly concatenates user-provided values into a filesystem path and then reads from that path, moving files into MindsDB's storage layer.
Only multipart uploads and URL-based uploads are sanitized; JSON uploads bypass filename cleaning and normalization checks, creating a path traversal condition when combined with an accessible filesystem.
Exploit preconditions
- Attack surface: Public or internal MindsDB HTTP endpoint handling file upload requests.
- Required access: No authentication required; any network client that can reach the upload API can attempt exploitation.
- Trigger point: A JSON-based PUT upload request with
source_typeset to a non-urlvalue, containing crafted path segments in user-controlled fields. - Why exploitation is possible: The handler joins user input directly into filesystem paths without applying
clear_filenameor equivalent sanitization and without restricting path normalization, allowing traversal sequences (such as parent directory references) to resolve to files outside the intended upload directory.
Why this happens
The root cause is improper neutralization of user-controlled path input before it is used to construct filesystem locations, aligning with CWE-22: Improper Limitation of a Pathname to a Restricted Directory ('Path Traversal').
The file upload implementation applies validation and cleanup only to multipart and URL-based upload flows but omits these protections for JSON-based uploads.
As a result, the JSON code path effectively trusts the provided filename or path fragments and joins them directly into server-side paths.
This inconsistent input handling across different content types leads to a condition where directory traversal sequences can escape the intended upload directory and access arbitrary files.
Potential impact
- Access to sensitive configuration files that may contain credentials, API keys, or connection strings.
- Exposure of application logs revealing internal topology, queries, or user behavior.
- Disclosure of environment-specific secrets (e.g., cloud metadata, environment variables written to disk).
- Partial mapping of the server filesystem structure through trial-and-error requests.
- Potential pivot to other attacks if sensitive data (such as database passwords or signing keys) is obtained.
General mitigation guidance
Effective mitigation centers on consistent, strict path handling and defensive file access patterns across all upload flows:
- Apply the same filename sanitization and canonicalization routines (e.g., stripping directory separators, normalizing paths) to all upload variants, including JSON-based uploads.
- Enforce a dedicated, fixed base directory for user-controlled files and validate that all resolved filesystem paths remain within that directory after normalization.
- Treat any user-supplied path or name as untrusted data; operate on server-generated identifiers rather than directly trusting user filenames when constructing storage paths.
- Separate privileges so that the component handling uploads runs with minimal filesystem permissions, limiting what files it can read or move even if input validation fails.
- Centralize file access utilities so that developers cannot bypass safety checks by calling low-level filesystem APIs directly.
How teams detect issues like this
Detection typically involves both code-centric and operational approaches:
- Static analysis: Configure rules to flag direct concatenation of user input into filesystem paths and to require normalization and base-directory checks for all file operations.
- Code review: Examine file upload and import handlers for divergent code paths where some request types (e.g., JSON vs multipart) bypass shared sanitization helpers such as
clear_filename. - Logging and monitoring: Enable detailed, privacy-conscious logging of upload paths and reject logs for paths containing suspicious traversal patterns; monitor for repeated access attempts to common sensitive files.
- Security testing: Incorporate path traversal test cases into API security tests and CI pipelines, including tests that exercise each content type and source option for the upload API.
- Policy enforcement: Use automated review tools or pre-commit checks to enforce patterns like "no raw
os.path.joinwith request-derived values" without passing through a validation utility.

