Summary
BabelDOC's vendored PDF parser can deserialize attacker-controlled pickle data while loading CMap files selected from PDF-controlled values. If a PDF can influence the resolved CMap path to an attacker-writable pickle file, arbitrary Python code may execute with the privileges of the BabelDOC process.
Affected context
The vulnerability occurs in BabelDOC deployments using the affected vendored PDF parser and processing PDFs that control Encoding, CMapName, or embedded PostScript usecmap references. After path separators are decoded, incomplete name normalization and path construction may allow CMap resolution to escape trusted directories and reach an attacker-writable .pickle.gz file.
Exploit preconditions
- Attack surface: PDF processing and CMap file loading in the BabelDOC parser
- Required access: Ability to provide or cause processing of a malicious PDF, plus access to a reachable attacker-writable pickle file path
- Trigger point: CMap loading through
CMapDB._load_data() - Why exploitation is possible: PDF-controlled names can influence path resolution, and the selected compressed pickle data is passed to
pickle.loads()without a safe data-only restriction
Why this happens
The underlying bug combines unsafe deserialization with insufficient path canonicalization. CMap names are only partially normalized, while decoded separators and path traversal sequences can influence os.path.join() and escape intended directories. When the resulting file is loaded, Python pickle deserialization can instantiate objects or invoke behavior during reconstruction, mapping the issue to CWE-502: Deserialization of Untrusted Data.
Potential impact
- Arbitrary Python code may execute in the BabelDOC process
- The host or container could be compromised with the process account's privileges
- Confidential documents or translation data could be accessed or modified
- Processing availability could be disrupted
- Compromised environments could be used for further lateral movement
General mitigation guidance
Mitigation generally focuses on removing executable deserialization from document-controlled workflows and enforcing strict file-boundary controls.
Common defensive patterns include:
- Use a data-only parser or a restricted serialization format instead of Python pickle
- Treat all PDF-derived CMap and encoding names as untrusted input
- Canonicalize paths and verify that resolved files remain within an explicitly trusted directory
- Reject absolute paths, traversal components, decoded separators, and unexpected file extensions
- Keep CMap resources immutable and inaccessible to untrusted writers
- Run document processing with least privilege, filesystem isolation, and appropriate sandboxing
- Apply resource and process restrictions so parser compromise has limited impact
How teams detect issues like this
Organizations can look for:
- Static analysis findings involving
pickle.loads(), pickle-based loaders, or deserialization of compressed file content - Code review signals where document metadata controls filesystem paths
- Missing canonical-path containment checks after URL, escape, or separator decoding
- Tests that supply traversal sequences, absolute paths, unusual CMap names, and embedded
usecmapreferences - Runtime monitoring for unexpected child processes, filesystem access outside approved CMap directories, or anomalous network activity
- Policy enforcement that blocks executable serialization formats in untrusted document-processing components
Automated code review and dependency-analysis tools may help identify unsafe deserialization patterns and affected parser components.

