Summary
A path traversal vulnerability in the search_papers function of duartium papers-mcp-server allows attacker-controlled input in the topic argument to influence filesystem paths.
When reachable over the network, this can enable remote attackers to traverse directories and potentially access or manipulate files outside the intended application scope.
Affected context
The vulnerability occurs in the search_papers function in src/main.py, where the topic parameter is used to construct file paths without sufficient validation or normalization.
It is relevant in deployments where papers-mcp-server is exposed over a network interface and accepts user-supplied topics that are used to read from or interact with the server's filesystem.
The risk is higher when the application runs with broad filesystem permissions or has access to sensitive configuration, source, or data directories.
Exploit preconditions
- Attack surface: Remote, via the application interface that accepts the
topicparameter (e.g., HTTP or MCP-style request). - Required access: Ability to send crafted requests to the papers-mcp-server endpoint using the
topicargument. - Trigger point: Invocation of
search_paperswheretopicis interpolated into a filesystem path (e.g., open/read/list operations) without robust sanitization. - Why exploitation is possible: The application likely concatenates
topicdirectly into a relative or absolute path and does not properly reject path traversal sequences such as../, allowing the resulting path to escape the intended directory.
Why this happens
This issue is rooted in improper neutralization of path sequences when constructing filesystem paths from user-controlled input.
The search_papers function appears to trust the topic value and incorporates it directly into filesystem operations without canonicalization, whitelisting, or restricting the root directory.
This matches CWE-22: Improper Limitation of a Pathname to a Restricted Directory, where lack of normalization and validation allows an attacker to reference files outside the intended directory boundary.
Potential impact
- Unauthorized reading of files located outside the intended data or documents directory
- Disclosure of sensitive information such as configuration files, tokens, or logs
- Potential modification or deletion of files if write operations are performed on attacker-influenced paths
- Facilitation of further attacks (e.g., information gathering for privilege escalation or lateral movement)
General mitigation guidance
Effective mitigation focuses on constraining how user input is translated into filesystem paths and reducing the privileges of the running process.
Pattern-based mitigation strategies include:
- Treating all incoming
topicvalues as untrusted and validating them against a strict whitelist (e.g., known topic IDs, patterns, or enumerated names) rather than using raw strings as paths. - Constructing paths using a fixed, server-side base directory and rejecting any computed path that resolves outside that directory after canonicalization.
- Normalizing paths before use and explicitly disallowing traversal sequences such as
../, absolute paths, or embedded path separators where not expected. - Decoupling user identifiers from filesystem layout, for example mapping
topicto stored metadata that references safe internal paths instead of direct path interpolation. - Running the service under a dedicated low-privilege account and ensuring filesystem permissions limit access only to non-sensitive data directories required for normal operation.
How teams detect issues like this
Detection efforts can combine code-level inspection with behavioral monitoring:
- Static analysis rules that flag direct concatenation of user-controlled variables (such as request parameters) into filesystem paths used by APIs like
open,os.listdir,os.path.join, or similar functions. - Code review checklists emphasizing directory traversal risks whenever path construction involves request parameters, query strings, or user-controlled identifiers.
- Centralized security policies or linters that enforce the use of safe path-building utilities and mandatory checks that computed paths remain within an approved root directory.
- Runtime logging and monitoring of file access patterns, alerting on unexpected directory access or file reads outside the normal data directory tree.

