Summary
A path traversal vulnerability in dexhunter's kaggle-mcp project allows crafted competition_id input to influence filesystem paths used by prepare_kaggle_dataset in src/kaggle_mcp/server.py.
When exposed remotely, this can enable attackers to read or manipulate files outside the intended directory scope on the server hosting kaggle-mcp.
Affected context
The issue appears in the server-side logic that prepares Kaggle datasets based on a competition_id argument.
It is relevant when:
- The kaggle-mcp service is reachable over a network (e.g., as an API or backend service)
- User-controlled input is passed as
competition_idand used to construct filesystem paths - There are no robust checks that restrict paths to a specific base directory
Deployments using rolling releases may all be affected until the underlying path handling logic is corrected.
Exploit preconditions
- Attack surface: Remote interface to the kaggle-mcp service exposing functionality that calls
prepare_kaggle_dataset. - Required access: Ability to send requests containing a controlled
competition_idparameter (e.g., API client, web form, or tool integration). - Trigger point: Invocation of
prepare_kaggle_datasetwherecompetition_idis used in path construction or file operations. - Why exploitation is possible: The
competition_idvalue is used without adequate normalization and enforcement against directory traversal sequences, allowing traversal outside the intended dataset directory.
Why this happens
The vulnerability arises from constructing filesystem paths from user-controlled input without enforcing strict directory boundaries.
Specifically, competition_id is likely concatenated or interpolated into path strings that are later used in file operations (such as open, list, or delete) without normalization and validation.
This aligns with CWE-22: Improper Limitation of a Pathname to a Restricted Directory ('Path Traversal'), where attackers can introduce sequences like ../ or equivalent encodings to escape the intended root directory and target arbitrary locations accessible to the service process.
Potential impact
- Reading files outside the intended dataset directory that are accessible to the application process
- Accessing configuration files, logs, or other sensitive data within the application's filesystem scope
- Overwriting or deleting files in directories reachable by the effective user, potentially corrupting datasets or application state
- Gaining additional leverage for other attacks (e.g., information disclosure that aids credential theft or lateral movement)
General mitigation guidance
Effective mitigation focuses on constraining filesystem access and treating all external identifiers as untrusted input:
- Resolve all file operations relative to a fixed, canonical base directory and reject paths that escape this boundary after normalization.
- Use high-level path utility functions that join and normalize paths, combined with checks ensuring the final path starts with the expected base directory.
- Implement strict allowlists for acceptable
competition_idvalues (e.g., only alphanumeric plus known safe separators; reject any path separator characters or traversal patterns). - Separate identifiers from actual filesystem structure, for example by mapping
competition_idto internally managed directory names or IDs instead of using it directly as a path segment. - Run the service with least-privilege filesystem permissions so that even if a traversal occurs, accessible data and writable locations are minimized.
How teams detect issues like this
Organizations can pursue several detection approaches:
- Static analysis: Scan for pattern of concatenating request parameters or unvalidated input into filesystem paths, especially uses of
os.path.join, raw string concatenation, or similar APIs that touch the file system. - Code review: Flag any functions where user-supplied identifiers are used directly in path construction; reviewers should look for missing normalization and base-directory checks.
- Security testing: Implement automated tests and dynamic scanners that attempt directory traversal strings (e.g.,
../) against endpoints dealing with file access to confirm that such input is rejected. - Policy enforcement: Establish guidelines that require path access helpers and centralized validation routines, and ensure that new code using file operations must rely on these vetted utilities.

