Summary
A path traversal flaw in PyMuPDF's embedded get function allows crafted paths to escape intended directories and write files to arbitrary locations.
When an application exposes this functionality to untrusted input, an attacker may overwrite or create files on the host system, leading to data loss or further compromise.
Affected context
This vulnerability occurs in applications that integrate PyMuPDF 1.26.5 and rely on its embedded get function in _main_.py for handling file paths.
It is most relevant when user-controllable input is used to construct file system paths without adequate normalization or restriction.
Environments where the PyMuPDF process has access to sensitive directories or shared volumes are more exposed, but impact depends on local file permissions and deployment configuration.
Exploit preconditions
- Attack surface: Interfaces that accept or construct file paths using PyMuPDF's embedded get function (CLI arguments, APIs, web endpoints, or plugins).
- Required access: Ability to provide or influence path strings processed by the vulnerable function; typically remote via an application front-end or local via command-line.
- Trigger point: Invocation of the embedded get function with attacker-controlled relative segments such as
../or absolute paths. - Why exploitation is possible: The function does not robustly normalize or validate path input against an allowed base directory, allowing traversal outside the intended path and file creation or overwrite in arbitrary locations permitted by the process.
Why this happens
The underlying bug class is improper path sanitization, mapping directly to CWE-22: Improper Limitation of a Pathname to a Restricted Directory.
The embedded get function trusts caller-supplied or derived path values and performs file operations without enforcing a strict allowlist or resolving and checking the canonical path against a constrained root.
This missing validation permits sequences like ../ or crafted absolute paths to bypass logical directory boundaries, turning a content retrieval or write mechanism into a general-purpose file system primitive.
Potential impact
- An attacker could write arbitrary files within directories accessible to the PyMuPDF process.
- Application or configuration files may be overwritten, leading to data corruption or service disruption.
- Log or script files could be modified, potentially enabling code execution under certain deployment scenarios.
- Sensitive files may be replaced with booby-trapped content, aiding lateral movement or persistence.
General mitigation guidance
Mitigation focuses on constraining file system access and reducing trust in path input.
Common defensive patterns include:
- Resolving incoming paths to their canonical form and verifying they remain within a predefined base directory (a "chroot-like" root).
- Using explicit allowlists of permissible directories or filenames instead of accepting arbitrary paths.
- Separating untrusted file storage areas from sensitive application and system directories, combined with least-privilege filesystem permissions.
- Centralizing path handling logic in a safe utility that enforces normalization, validation, and rejection of traversal sequences before passing paths to PyMuPDF or other libraries.
How teams detect issues like this
Effective detection typically combines static and review-based techniques:
- Static analysis rules that flag direct use of user input in path joins, open/write calls, or in the embedded get function.
- Code review checklists that require verification of path normalization and root directory checks in any file access logic around PyMuPDF.
- Runtime monitoring for anomalous file creation or modification patterns outside expected directories.
- CI/CD policies that block changes introducing new uses of unvalidated paths or disable generic path concatenation helpers without validation.

