Skip to content

Constrain UID-derived CLI output paths - #130

Open
jdotc1 wants to merge 1 commit into
ImagingDataCommons:masterfrom
jdotc1:bugfix/cli-output-paths
Open

jdotc1 wants to merge 1 commit into
ImagingDataCommons:masterfrom
jdotc1:bugfix/cli-output-paths

Conversation

@jdotc1

@jdotc1 jdotc1 commented Oct 14, 2026 •

Copy link
Copy Markdown

Fixes #129.

The CLI uses server-provided SOP Instance UIDs to form instance and metadata filenames. A parent-relative or absolute UID can currently select a path outside the requested output directory.

Add a shared path guard that requires the resolved output file's parent to be the selected directory, and use it for instance, metadata, and frame export destinations. Normal filenames and existing UID-format permissiveness are preserved. This does not claim to eliminate filesystem races or provide comprehensive filesystem security.

Validation: six focused mocked cases against the actual source save helpers and new tests loaded in isolation. Instance and JSON metadata saves each cover normal, parent-relative, and absolute values. The four escaping cases failed before the fix; all six passed afterward. No server, clinical data, codecs, real writes, full suite, or frame-export integration test was used.

@sonarqubecloud

Copy link
Copy Markdown

@CPBridge

Copy link
Copy Markdown
Collaborator

Hi @jdotc1

Am I correct in understanding that the issue that this PR is trying to solve is if the server provides a UID that "breaks" the filepath formed from that UID out of the intended directory, e.g. by provided a "UID" along the lines of "../1.2.3.4"?

If so, this is not an issue that you would ever encounter unless a server is acting quite maliciously with the intention of getting you to write files outside the intended location. This then is a security precaution against a malicious server? Just trying to make sure I understand the problem you are trying to solve here. Because this is not something you would ever encounter under normal usage. No real DICOM server would ever support a UID like "../1.2.3.4"

@jdotc1

jdotc1 commented Oct 22, 2026

Copy link
Copy Markdown
Author

Yes—the intended scope is hardening against an untrusted or compromised endpoint, or malformed response data that reaches the CLI. A valid SOP Instance UID should not contain a parent-relative or absolute path.

The guard keeps a UID-derived destination within the selected output directory while preserving existing UID validation behavior. It is defense in depth at the local write boundary; it does not claim to eliminate filesystem races or make an untrusted server generally safe.

I also ran the project CLI tests and the focused output-path tests with the real dependencies: 55 and 6 passed, respectively.

@jdotc1

jdotc1 commented Oct 23, 2026

Copy link
Copy Markdown
Author

Thank you for considering this change and for the helpful discussion. When convenient, could you please approve the pending unit-test workflow for this PR? I appreciate your time.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Constrain UID-derived CLI output paths to the selected directory

2 participants