Summary
PyMuPDF contains a path traversal vulnerability in the font-processing branch of extract_objects(). A crafted document may cause extracted output to be written outside the intended directory when a document-controlled font name is used to construct the output path.
Affected context
The vulnerability affects PyMuPDF workflows that process PDF, EPUB, XPS, or FB2 documents through the affected object-extraction logic. It becomes risky when an attacker can supply or influence a document and the application allows extracted objects to be written to a filesystem location without normalizing or constraining document-controlled path components.
Exploit preconditions
- Attack surface: Applications or services that process attacker-controlled PDF, EPUB, XPS, or FB2 files
- Required access: Ability to submit or cause processing of a crafted document; authentication or elevated privileges may not be required
- Trigger point: Font handling within
extract_objects()during document extraction - Why exploitation is possible: A document-controlled BaseFont value can influence the output filename, while path separators, traversal components, or absolute-path syntax are not sufficiently constrained
Why this happens
The underlying bug is path construction based on untrusted document metadata. The affected logic joins a user-supplied output directory with a BaseFont-derived filename without reliably stripping or rejecting path separators, parent-directory references, or absolute paths. This maps to CWE-22: Improper Limitation of a Pathname to a Restricted Directory, because attacker-controlled input can escape the intended filesystem boundary.
Potential impact
- Files may be written outside the designated output directory
- Existing files could be overwritten if filesystem permissions allow it
- Application data or configuration may be modified
- A subsequent execution or loading process could be influenced
- The affected service may experience integrity, availability, or operational impacts
General mitigation guidance
Mitigation generally focuses on treating document metadata as untrusted and enforcing a strict output-directory boundary.
Common defensive patterns include:
- Resolve candidate paths and verify that they remain beneath the approved output directory
- Reject absolute paths, parent-directory components, and platform-specific path separators
- Generate server-side filenames rather than deriving names directly from document metadata
- Use isolated, least-privileged worker processes for document conversion and extraction
- Apply restrictive filesystem permissions and separate writable workspaces from sensitive application paths
- Avoid allowing extracted filenames to control arbitrary destination locations
How teams detect issues like this
Organizations can identify similar issues through:
- Static analysis rules for path joins involving document metadata or other untrusted strings
- Code review checks for missing canonicalization and containment validation
- Tests using traversal markers, encoded separators, absolute-path forms, and platform-specific path syntax
- Runtime monitoring for writes outside approved extraction directories
- Policy enforcement requiring generated filenames and sandboxed document-processing workers
- Automated security review tools that flag filesystem operations whose paths derive from untrusted input

