Summary
A path traversal flaw in pydicom allows a malicious DICOMDIR entry to reference files outside the intended File-set root directory.
When a crafted ReferencedFileID is used, FileSet operations such as copy(), write(), and certain remove()+write() flows may read, copy, move, or delete arbitrary files on the filesystem within the privileges of the running process.
Affected context
This vulnerability affects applications that use pydicom versions 2.0.0-rc.1 through 3.0.1 to process DICOMDIR structures and perform FileSet-based file operations.
It becomes relevant when the application:
- Consumes DICOMDIR files from external or semi-trusted sources
- Uses pydicom FileSet APIs (e.g., copy(), write(), remove()+write(use_existing=True)) to manage files on disk
- Assumes that ReferencedFileID entries will always remain under a defined File-set root and does not perform additional path validation
The issue is tied to how pydicom resolves and uses ReferencedFileID paths relative to the File-set root without enforcing directory containment.
Exploit preconditions
- Attack surface: DICOMDIR parsing and FileSet operations exposed through pydicom.
- Required access: Ability to provide or influence a DICOMDIR containing malicious ReferencedFileID values (e.g., upload, import, or ingestion of external DICOM media).
- Trigger point: The application invokes pydicom FileSet methods such as copy(), write(), or remove()+write(use_existing=True) on a FileSet that includes the crafted entries.
- Why exploitation is possible: pydicom resolves the ReferencedFileID to confirm existence but does not verify that the normalized path remains within the File-set root directory. As a result, paths containing traversal segments or absolute locations can cause file operations to target arbitrary filesystem locations accessible by the process.
Why this happens
The underlying bug is a classic directory traversal issue (CWE-22) in directory and path handling logic.
pydicom treats ReferencedFileID values from DICOMDIR as relative paths intended to live under a specific File-set root, but only checks that the resolved path exists, not that it is still contained within the designated root after resolution.
Without enforcing that the canonical, normalized path remains under the configured root directory, path traversal sequences (such as parent directory references) or crafted paths can escape the intended file tree.
Subsequent FileSet operations trust these unchecked paths and perform file I/O on them, enabling unintended access to files outside the File-set root.
Potential impact
- Arbitrary file read from locations outside the File-set root, within the permissions of the application process
- Unauthorized copying of sensitive files to attacker-controlled destinations or export locations
- In some flows, unintended move or deletion of files outside the File-set root via remove()+write(use_existing=True) or similar operations
- Indirect escalation of impact if accessed files contain credentials, configuration secrets, or other security-relevant data
General mitigation guidance
Effective mitigation focuses on constraining file paths to an expected root and treating external DICOMDIR content as untrusted input:
- Normalize and canonicalize all ReferencedFileID-derived paths, then explicitly verify that they remain under the configured File-set root before performing any file I/O.
- Introduce a strict allowlist policy for accessible directories, rejecting or logging any path that attempts to traverse outside these boundaries.
- Run applications that process untrusted DICOMDIRs under dedicated, least-privilege accounts with tightly limited filesystem access.
- Separate storage for imported DICOM media from sensitive directories (e.g., configuration, logs, user data) to minimize the blast radius of any path misuse.
- Treat all metadata-driven file operations (from DICOMDIR or similar index files) as high risk and apply uniform validation of paths at a single, well-tested abstraction layer.
How teams detect issues like this
Detecting this class of issue and its misuse typically involves both code-level and operational strategies:
- Static analysis rules or code review checklists that flag file operations constructed from externally supplied or metadata-based paths without:
- Canonicalization (e.g., resolving ".." and symlinks), and
- A containment check against a configured root directory
- Review of FileSet-related code paths to ensure that ReferencedFileID values are treated as untrusted input and validated before use.
- Logging and monitoring of FileSet operations, including recording the resolved absolute paths for copy(), write(), and remove() operations, then alerting on attempts to access directories outside the configured File-set root.
- File access monitoring (e.g., OS-level auditing or EDR) for processes handling DICOM files, focusing on unexpected reads or writes to sensitive directories when DICOMDIR processing occurs.

