Summary
The qrscp application's DICOM C-STORE handler trusts attacker-supplied dataset values when constructing filesystem paths, allowing crafted input to control where files are written.
When qrscp processes malicious C-STORE requests without proper path sanitization, an attacker can cause file writes outside the intended storage directory, turning routine image ingestion into a critical filesystem compromise.
Affected context
This vulnerability manifests in deployments of the qrscp application that accept DICOM C-STORE requests and persist incoming datasets to disk.
The affected code path uses values taken directly from the DICOM instance (such as identifiers or filenames) when calling os.path.join() to build output paths.
In environments where qrscp runs with elevated or service-level privileges and no additional filesystem isolation, a malicious DICOM sender can influence these paths far beyond the intended storage directory.
Exploit preconditions
- Attack surface: Network-exposed DICOM C-STORE endpoint of qrscp
- Required access: Ability to send crafted DICOM datasets to the qrscp server (e.g., as a DICOM node or client)
- Trigger point: Handling of a C-STORE operation where dataset fields are used directly in
os.path.join()to form the destination path - Why exploitation is possible: User-controlled DICOM instance values are not normalized or constrained before being combined into filesystem paths, enabling directory traversal sequences and arbitrary write locations
Why this happens
The underlying flaw is a classic path traversal issue where untrusted input is used in filesystem path construction without validation or restriction, aligning with CWE-22: Improper Limitation of a Pathname to a Restricted Directory.
In qrscp, the C-STORE handler treats fields from attacker-supplied DICOM datasets as safe path components and passes them directly to os.path.join() without checks for traversal tokens, absolute paths, or disallowed characters.
This insecure pattern breaks the intended directory boundary for stored images and allows a remote actor to escape the storage root and target arbitrary locations on the host filesystem.
Potential impact
- An attacker could write files to arbitrary paths accessible to the qrscp process.
- Malicious file placement can lead to configuration tampering or log poisoning.
- Under certain deployments, arbitrary file writes may enable code execution (e.g., writing scripts or binaries into executable directories).
- Critical service disruption can occur by overwriting application or system files.
General mitigation guidance
Effective mitigation relies on strictly constraining how filesystem paths are derived from DICOM data and ensuring storage operates within a well-defined, restricted root.
Common defensive patterns include:
- Normalizing and validating all path components derived from DICOM datasets against an allowlist of expected formats and characters.
- Rejecting or sanitizing any input containing directory traversal tokens, absolute paths, or unexpected separators.
- Resolving the final path and enforcing that it remains inside a configured storage root (e.g., by checking canonical paths).
- Using per-service directories with least-privilege permissions so that qrscp can only write where necessary.
- Avoiding direct mapping of user-controlled identifiers to filesystem names; instead, using generated identifiers or database-backed metadata.
How teams detect issues like this
Organizations can detect this class of issue by:
- Applying static analysis rules that flag uses of
os.path.join()or similar APIs with parameters derived from network or DICOM input without validation. - During code reviews, looking for direct usage of dataset fields when building paths and verifying the presence of canonicalization and boundary checks.
- Enforcing secure coding standards that require path normalization, root directory enforcement, and rejection of traversal patterns for any file IO.
- Using automated security testing or dynamic analysis to send crafted DICOM datasets containing traversal sequences and observing write locations.

