Summary
A path traversal vulnerability in python-notebook-mcp affects multiple notebook file handling functions, allowing crafted paths to escape the intended workspace directory.
When exposed over a network, this can let a remote attacker read or modify files elsewhere on the server's filesystem, depending on process privileges and deployment configuration.
Affected context
The vulnerability occurs in deployments of python-notebook-mcp that expose the server.py endpoints providing notebook creation, reading, and editing capabilities.
It is relevant where:
- Notebook paths or filenames are accepted from clients and mapped directly to filesystem paths
- The application runs under an account with access to sensitive files or directories
- No strong filesystem sandboxing, chroot, or container-level restrictions prevent access outside the intended notebook directory
The issue is more severe in environments where the service runs on shared infrastructure or alongside other sensitive applications or data.
Exploit preconditions
- Attack surface: Remote HTTP (or equivalent RPC) endpoints wrapping
create_notebook,read_notebook,edit_cell, andadd_cellin server.py. - Required access: Ability to send requests to the notebook management API; any authentication or access control in front of these endpoints still determines who can attempt exploitation.
- Trigger point: Supplying crafted path components (for example, directory traversal sequences or absolute-like paths) as notebook names, IDs, or file paths that the server uses for filesystem operations.
- Why exploitation is possible: User-controlled path input is joined or concatenated with base directories and then passed to file APIs without sufficient normalization, canonicalization, or enforcement that the final resolved path stays within an allowed directory.
Why this happens
The core problem is improper neutralization of special elements in file paths, mapping directly to CWE-22: Path Traversal.
The affected functions in server.py appear to:
- Accept user-provided notebook identifiers or paths
- Construct filesystem paths from this data using simple string concatenation or naive joins
- Perform file operations (create, read, modify) without resolving and validating the resulting path against a fixed, trusted root directory
Without robust checks to prevent ../ segments, symlink jumps, drive letters, or absolute paths from escaping the intended workspace, an attacker can traverse directories and interact with arbitrary files accessible to the server process.
Potential impact
- Read access to configuration files, secrets, or keys stored on the server
- Overwriting or corrupting application or user data files
- Modification of notebooks or scripts to inject malicious code that executes later within interactive sessions
- Disclosure of system information that assists in further attacks
- Potential privilege escalation when combined with other vulnerabilities or misconfigurations (for example, overwriting files used by higher-privileged components)
General mitigation guidance
Effective mitigation focuses on constraining filesystem access and hardening how paths are processed:
- Enforce a strict root workspace directory and ensure all notebook operations resolve and remain within this directory.
- Normalize and canonicalize paths (for example, using realpath-like functions) before access, then validate that the canonical path starts with the expected base directory.
- Reject inputs containing path traversal sequences, absolute path indicators, or disallowed characters according to a clear allowlist policy.
- Store notebook metadata separately from user-controlled identifiers and map user-facing IDs to server-controlled filesystem paths.
- Run the notebook service under a dedicated low-privilege account with minimal filesystem permissions, and consider isolating it using containers, chroots, or sandboxing so that even escaped paths reach only non-sensitive data.
- Log rejected path attempts to support incident investigation and refine validation rules.
How teams detect issues like this
Organizations can detect or monitor for similar issues using a combination of static and dynamic techniques:
- Static analysis: Configure rules to flag direct concatenation of user input into filesystem paths and unvalidated use of functions like
open,os.remove,os.listdir, orshutilcalls in request-handling code. - Code review: Check endpoints that handle notebook or file names to ensure paths are normalized, validated, and restricted to a workspace directory. Red flags include raw usage of
../, absolute paths, or blind trust in client-supplied filenames. - Runtime monitoring: Capture logs of file access patterns and alert on attempts to access files outside the expected notebook tree, especially containing
..or unusual prefixes. - Security testing: Use automated web security scanners or custom scripts to send crafted path traversal payloads and monitor for unexpected file content in responses or changes on disk.

