pydicom has a path traversal in FileSet/DICOMDIR ReferencedFileID allows file access outside the File-set root

説明

Summary

A crafted DICOMDIR can set ReferencedFileID to a path outside the File-set root. pydicom resolves the path only to confirm that it exists, but does not verify that the resolved path remains under the File-set root. Subsequent public FileSet operations such as copy(), write(), and remove()+write(use_existing=True) use that unchecked path in file I/O operations. This allows arbitrary file read/copy and, in some flows, move/delete outside the File-set root.

Details

Verified on pydicom 3.1.0.dev0.

Relevant logic is in src/pydicom/fileset.py:

  • RecordNode._file_id converts ReferencedFileID directly to Path(...)
  • FileSet.load() checks only (root / file_id).resolve(strict=True) to confirm existence
  • FileSet.load() does not verify that the final resolved path is contained within the File-set root
  • FileInstance.path returns self.file_set.path / self.node._file_id
  • FileSet.copy() uses shutil.copyfile(instance.path, dst)
  • FileSet.write() uses Path(instance.path).unlink() and shutil.move(...)

Because there is no containment check such as resolved.relative_to(root.resolve(strict=True)), a malicious DICOMDIR can reference:

  • absolute paths such as /etc/passwd
  • traversal paths such as ../...
  • syntactically conformant file IDs that escape via symlinks

This is not limited to obviously invalid VR input. Even when pydicom emits warnings for invalid ReferencedFileID values, the operation is not blocked. I also confirmed a symlink-based variant using a conformant file ID.

A realistic server-side scenario is:

  1. a user uploads a DICOM File-set zip
  2. the server loads the uploaded DICOMDIR using FileSet
  3. the server re-exports or reorganizes the File-set using FileSet.copy() or FileSet.write()
  4. a server-local file referenced by the malicious DICOMDIR is included in the exported result

PoC

Minimal reproduction:

  1. Copy a sample File-set that contains a valid DICOMDIR
  2. Modify one DirectoryRecordSequence item so that ReferencedFileID = "/etc/passwd" (or /tmp/secret.txt)
  3. Load it with FileSet(ds) or FileSet(path_to_dicomdir)
  4. Call FileSet.copy(new_root)
  5. Observe that the exported File-set contains the contents of the referenced external file

Example:

from pathlib import Path
from tempfile import mkdtemp
import shutil
from pydicom import dcmread
from pydicom.fileset import FileSet

base = Path("src/pydicom/data/test_files/dicomdirtests")
root = Path(mkdtemp(prefix="fsroot_"))
out = Path(mkdtemp(prefix="fsout_"))

shutil.copy2(base / "DICOMDIR", root / "DICOMDIR")
for d in ("77654033", "98892003", "98892001"):
    shutil.copytree(base / d, root / d)

ds = dcmread(root / "DICOMDIR")
item = next(x for x in ds.DirectoryRecordSequence if "ReferencedFileID" in x)
item.ReferencedFileID = "/etc/passwd"

fs = FileSet(ds)
fs.copy(out)

I also verified the issue in a simple web import/export demo where an uploaded malicious File-set caused /etc/passwd to be copied into the exported result.

If useful, I can provide the exact malicious sample and the demo environment separately.

Impact

This is a path traversal / root containment bypass in FileSet handling.

Observed impact:

arbitrary file read/copy outside the File-set root via FileSet.copy()
arbitrary file move outside the File-set root via FileSet.write()
arbitrary file delete outside the File-set root via FileSet.remove(...); write(use_existing=True)
Affected applications are those that accept untrusted DICOMDIR / File-set input and then call public FileSet workflows such as load(), copy(), write(), or remove().

A realistic impact is server-side file disclosure in import/export workflows.

基本情報

タイプ
reviewed
深刻度
high
GitHub 上のアドバイザリ
アドバイザリを開く ↗
リポジトリのアドバイザリ
リポジトリのアドバイザリを開く ↗
ソースコード
ソースを見る ↗
公開(アドバイザリ)
2026-03-20 15:57:01 UTC
更新
2026-03-20 15:57:02 UTC
GitHub レビュー済み
2026-03-20 15:57:01 UTC
NVD で公開
2026-03-20 02:16:33 UTC

EPSS Score

Score Percentile
0.01% 0.27%

CVSS Scores

Base score Version Severity Vector
7.8 3.1
CVSS:3.1/AV:L/AC:L/PR:N/UI:R/S:U/C:H/I:H/A:H クリックして展開
攻撃ベクター (AV:L)
対象ホスト上でコードを実行できること、または別ユーザーの誤操作・悪意ある操作が前提になる。
攻撃の複雑さ (AC:L)
攻撃者が条件を満たせば、レース条件や珍しい構成に依存せずに再現しやすい。
必要な権限 (PR:N)
事前のログインや昇格は不要で、匿名アクセスのまま踏み台にしうる。
ユーザーの関与 (UI:R)
インストールの許可、設定変更、悪意あるファイルの実行など、人の一度の判断がトリガーになる。
スコープ (S:U)
影響は脆弱コンポーネントと同一のセキュリティ権限・信頼境界の内側に収まる。
機密性への影響 (C:H)
広範な機微データの読み取りや持ち出しが現実的。
完全性への影響 (I:H)
権限の奪取や広範なログ改竄など、システムの信頼根拠を揺るがす改ざんが現実的。
可用性への影響 (A:H)
長時間のサービス停止、データ損壊による復旧不能に近い状態など、利用者に著しい不便を与えうる。

Identifiers

CWEs

CWE id Name
CWE-22 Improper Limitation of a Pathname to a Restricted Directory ('Path Traversal')

Credits

  • jh4nks (reporter)

Affected packages (2)

Vulnerable version ranges and first patched releases as published by GitHub.

Ecosystem Package Vulnerable range First patched Vulnerable functions
pip pydicom >= 3.0.0, <= 3.0.1 3.0.2
pip pydicom < 2.4.5 2.4.5

References

cvelogic Threat Intelligence