Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
58 commits
Select commit Hold shift + click to select a range
e9834f9
DICOM: redact a user identity's username and password from the associ…
wshallwshall Nov 23, 2026
d144088
DICOM: redact a refused value from a peer's DIMSE message on pynetdic…
wshallwshall Nov 23, 2026
7cb93e0
DICOM: redact a refusal chained in an exception on any pynetdicom logger
wshallwshall Nov 23, 2026
e9f4c4f
DICOM: redact pydicom's charset and IS/DS lines and the no-context line
wshallwshall Nov 23, 2026
037baa1
DICOM: codec errors, the SCU's warnings filter, and engine error text
wshallwshall Nov 23, 2026
1b68df9
DICOM: keep the pydicom warning filters linear and out of the send path
wshallwshall Nov 23, 2026
88dd40d
DICOM test: time the DS warning filter against its quadratic form
wshallwshall Nov 23, 2026
ce21eae
DICOM: repair the first review round of the log redaction
wshallwshall Nov 23, 2026
ef2ceac
DICOM: repair the second review round of the log redaction
wshallwshall Nov 23, 2026
0d3d15a
DICOM: redact two more peer-value lines; refuse an unproposable object
wshallwshall Nov 23, 2026
8677560
DICOM SCP: a bounded per-message rate setting for slow links
wshallwshall Nov 23, 2026
ac75260
DICOM SCU: hold the reactor so it cannot take a store's response
wshallwshall Nov 23, 2026
a2eb2f0
DICOM: the known-gaps list, and what the shape patterns can backtrack…
wshallwshall Nov 23, 2026
8eb41a7
DICOM: handover for the row, ahead of the review rounds
wshallwshall Nov 23, 2026
a95944a
DICOM: simplify pass over the slow-link and log redaction work
wshallwshall Nov 23, 2026
5bb234e
DICOM: repair review round one of the slow-link and redaction work
wshallwshall Nov 23, 2026
af1441e
DICOM: repair review round two of the slow-link and redaction work
wshallwshall Nov 23, 2026
d2acb17
DICOM SCP: raise the least min_message_bytes_per_second to 16 KiB a s…
wshallwshall Nov 23, 2026
2c99c51
DICOM SCP: correct the rationale for the 16 KiB a second least rate (…
wshallwshall Nov 23, 2026
0265abe
DICOM SCP: scope the slow-link remedy text to links at or above the 1…
wshallwshall Nov 23, 2026
97db1da
DICOM logs: a library line that matches no pinned template is withheld
wshallwshall Nov 23, 2026
c2d9d05
DICOM logs: state the fail-closed screen in the docs, and close two r…
wshallwshall Nov 23, 2026
7c4f3e6
DICOM logs: simplify the screen, and generate its value-free lines
wshallwshall Nov 23, 2026
4921b49
DICOM logs: repair review round one of the fail-closed screen
wshallwshall Nov 23, 2026
18bebb0
DICOM logs: repair review round two of the fail-closed screen
wshallwshall Nov 23, 2026
2713588
DICOM logs: screen a line made during a hold
wshallwshall Nov 23, 2026
cee5094
DICOM logs: tell the screening record factory by its type
wshallwshall Nov 23, 2026
be89c44
DICOM logs: clear an exception's notes whenever they are set
wshallwshall Nov 23, 2026
942c70e
DICOM SCU: a delivery error carries no library text on its chain
wshallwshall Nov 23, 2026
1331051
DICOM docs: say what the TCP error line keeps, and the unwrapped path
wshallwshall Nov 23, 2026
f0f567f
DICOM SCU: a failed association release keeps the delivery outcome
wshallwshall Nov 23, 2026
582eedf
DICOM SCU tests: every chained refusal carries no library text
wshallwshall Nov 23, 2026
461d238
DICOM SCU: the chain scrub never raises
wshallwshall Nov 23, 2026
2ce2b73
DICOM SCU tests: read dcmread from the module that defines it
wshallwshall Nov 23, 2026
6c19736
DICOM log redaction is fail-closed: an unrecognised library line is w…
wshallwshall Nov 23, 2026
a8a13fd
DICOM SCU: the peer's confirmed status decides delivery
wshallwshall Nov 23, 2026
c8df897
DICOM SCU: a failed release aborts the association
wshallwshall Nov 23, 2026
49fc4b6
DICOM SCU: the chain holds an engine exception naming the class
wshallwshall Nov 23, 2026
2cfedda
DICOM SCU: C-ECHO guards its release too
wshallwshall Nov 23, 2026
78b6863
DICOM SCU tests: declare the slot the chain test fills
wshallwshall Nov 23, 2026
fe3b3ed
DICOM log redaction is fail-closed: an unrecognised library line is w…
wshallwshall Nov 23, 2026
0e49d98
DICOM SCU: naming a library exception runs none of its code
wshallwshall Nov 23, 2026
f4468e7
Static scan: record the DICOM log template patterns
wshallwshall Nov 23, 2026
957014a
DICOM log redaction is fail-closed: an unrecognised library line is w…
wshallwshall Nov 23, 2026
b24c0f0
ReDoS scanner pin records the DICOM warning filters' pattern (BACKLOG…
wshallwshall Nov 23, 2026
0df0868
Merge b629/6637-dicom at b24c0f0068 into the DICOM redactor branch
wshallwshall Nov 23, 2026
c38ca76
Static scan: the template entry claims only what was read
wshallwshall Nov 23, 2026
92bdff8
DICOM log redaction is fail-closed: an unrecognised library line is w…
wshallwshall Nov 23, 2026
e0a1150
DICOM logs: the screen names a class without running its code
wshallwshall Nov 23, 2026
fa55dbe
Static scan: read every built DICOM log template for a nested quantifier
wshallwshall Nov 23, 2026
c93d453
Static scan: the template entry says it depends on fullmatch
wshallwshall Nov 23, 2026
80ecefb
DICOM log redaction is fail-closed: an unrecognised library line is w…
wshallwshall Nov 23, 2026
f830deb
Merge origin/main into the DICOM redactor branch after PR 3197 squash…
wshallwshall Nov 24, 2026
a4da3e5
DICOM log default-deny: its own security fragment, and PHI.md says wh…
wshallwshall Nov 24, 2026
85e7339
DICOM log default-deny: PHI.md points to DICOM.md, fragment named by …
wshallwshall Nov 24, 2026
c69d557
DICOM log default-deny: one PHI.md pointer, and the fragment names wh…
wshallwshall Nov 24, 2026
b15eb1a
Merge origin/main into the DICOM redactor branch
wshallwshall Nov 24, 2026
86618db
DICOM log default-deny: delete or narrow five false statements
wshallwshall Nov 24, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions changelog.d/6637-dicom-slow-link-and-log-values.added.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,5 @@
than that would have an object over a size set by the link cut at the same point on every
attempt. On a link at or above 16 KiB a second, set the rate at or under the link's. The least
it takes is 16 KiB a second, and no value turns the per-message deadline off, so a slower link
also needs `timeout_seconds` raised. It is refused on an outbound connection. The DICOM log filter also redacts more
peer values, and the C-STORE client dead-letters an object it can never propose instead of
retrying it. (`BACKLOG #6637`)
also needs `timeout_seconds` raised. It is refused on an outbound connection. The C-STORE client
also dead-letters an object it can never propose instead of retrying it. (`BACKLOG #6637`)
6 changes: 6 additions & 0 deletions changelog.d/6637.security.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
- **pynetdicom's and pydicom's log lines are now default-deny.** Where the screen applies, a line
from either library is written only if it is one of the value-free lines or fully matches one of
the templates pinned in `messagefoundry/transports/_dicom_log_lines.py`; a line that matches none
is withheld. See
[DICOM.md](../docs/DICOM.md) section 5 for what stays and what is lost. Its limits are in
DICOM.md section 5. (`BACKLOG #6637`)
118 changes: 74 additions & 44 deletions docs/DICOM.md
Original file line number Diff line number Diff line change
Expand Up @@ -338,53 +338,83 @@ numpy**), lazily imported so a SQLite-only install and a console peek-import sta
class/instance UID, AE title, peer host) or a redacted URL — never the dataset, an element value, or pixel data.
The rule holds for pynetdicom's and pydicom's own loggers too (owner ruling 2026-11-03, BACKLOG #5081). A
UID or AE title a peer sent that either library refuses or flags as non-conformant is not a routing-safe
identifier. The DICOM transport applies that rule through a log filter on those libraries' loggers, which
meets it only for the line shapes the filter knows. The filter is installed when the transport is imported
and again at each SCP start, so it reads the SCU's lines as well as the SCP's. It redacts the value from at
least these lines, which stay with the element's name and the reason while the value reads `[redacted]`:
pynetdicom's non-conformant and refused value lines; its non-conformant transfer syntax and related SOP
class lines, and its line naming a transfer syntax under the DICOM root that is no transfer syntax; the
refusal in an exception logged by any pynetdicom module that logs one, such as its DUL when a received PDU
does not decode or its DIMSE provider when a received message does not convert, in the record's message
and in each link of its traceback's chain; pydicom's invalid value, Specific Character Set, VR IS and
DS, and invalid private creator lines, as lines and as refusals inside such an exception; pynetdicom's `No presentation context for`
line, which keeps its SOP class and transfer syntax only when both are conformant or named in pydicom's
UID dictionary; its `No supported service class` line, which keeps a SOP class on the same terms; the
UID and AE title fields of pynetdicom's DEBUG dumps of an association request, an
association acceptance and a DIMSE message; and the username and password of a user identity and the
hex of an extended negotiation item's application information in those dumps, which are never kept. A
dump field otherwise keeps at
least these values: an empty one; a
conformant UID; a name in pydicom's UID dictionary, on a field that is no instance UID; and, on the AE title
fields and on Their Implementation Version Name, a value that passes pynetdicom's AE title check, which an
empty or all-space value does. `_kept` in `messagefoundry/transports/dicom.py` is the source of record.
pynetdicom runs no AE title check on the two titles of an association acceptance, only `decode_bytes` on
their bytes, and the filter applies the title check to them anyway. The dump's `unknown` for a missing implementation class
UID is redacted too, since a peer can send that word itself. The lines are a list of the known pynetdicom
3.0.4 and pydicom 3.0.2 shapes. A line of another shape, or on another logger, passes whole, so a new shape
that a library upgrade adds reaches the log until it is added to the list. The pin tests in
identifier. The DICOM transport applies that rule by default-deny on
every `pynetdicom.*` and `pydicom` logger, at every level (BACKLOG #6637). A line is written only if it is one of
the value-free lines or fully matches one of the templates pinned in
`messagefoundry/transports/_dicom_log_lines.py`. Anything else is withheld: the record then names its logger,
its level and any exception class, with a fixed note, and none of its message or arguments. On a pinned line
the fixed text stays and the value reads `[redacted]` where the library is refusing or flagging it. The UID and AE
title fields of pynetdicom's DEBUG dumps stay only where they pass `_kept` in
`messagefoundry/transports/dicom.py`, the source of record: at least an empty value; a conformant UID; a name in
pydicom's UID dictionary, on a field that is no instance UID; and, on the AE title fields and on Their
Implementation Version Name, a value that passes pynetdicom's AE title check, which an empty or all-space value
does. pynetdicom runs no AE title check on the two titles of an association acceptance, and the screen applies
it to them anyway. The dump's `unknown` for a missing implementation class UID is redacted, since a peer can
send that word itself. A user identity's username and password, and the hex of an extended negotiation item's
application information, are never kept.

**What an operator still reads and what is lost.** Association requested, accepted, rejected with its result
and reason, released and aborted, the send and receive lines for C-STORE and C-ECHO with their status, and the
library's fixed protocol error lines stay, at least those for a malformed PDU or association field. Lost, at least: the C-FIND, C-GET and C-MOVE progress lines and
identifier dumps, which this engine does not serve; the text of a library exception that matches no template,
including an operating system's socket error text; and every note and group member of an exception.

Where the engine quotes such an exception, in its own C-STORE line or a delivery error, it keeps the class
and reads `[message withheld]` with the file, line and function that raised it. pynetdicom's own
`TCP Initialisation Error: {exc}` line is different. It has no `exc_info`, so its withheld line keeps
neither the class nor the raising place, and an operator cannot tell a refused connection from a timeout or
a DNS failure from the log.

**How far it reaches.** A filter on each logger the libraries create, and a log record factory for any other
logger under those names, so a logger created later, one that does not propagate, and a host with no
`logging_setup` handler are all covered. A host that replaces the record factory without calling the one it
found leaves a logger outside the named list unscreened until the next SCP start, C-STORE or SCU association puts
the factory back. A record built by hand and given straight to a handler passes neither. Neither library sets
`propagate = False` on a logger of its own. A traceback's frames and exception class names are written, since
they are code. An `Exception` raised while the screen reads a line withholds that line, and one raised while it
renders the traceback withholds the traceback. Matching is linear in the line's length.

A delivery error raised while the SCU stores an object holds, on its chain, at most an engine exception that
names the library exception's class, with none of its text.

**A failed association release does not change the outcome.** The peer's status decides it. After a C-STORE, a
Success or Warning stays delivered and is not sent again, any other status keeps its own outcome, and a send
with no status stays a failure. After a C-ECHO, the test passes only on Success. The release failure is logged
through the screen and the association is aborted. If the abort raises too, that is logged the same way and
the engine makes no further attempt to end the association.

**The screen assumes a library exception's class behaves as ordinary Python.** A class with hostile attribute,
`__str__` or metaclass code is outside it and can still get text past it, and an ordinary class's name is
written, so a name carrying a value would be written too.

**A library exception the SCU does not wrap keeps its text.** At least one raised while the SCU opens the
association does. The delivery worker logs only its class, but the text would reach the row's `last_error`
through `safe_exc`, which does not recognise a refused UID. If the worker's write of that error to the store
then fails with an error that is not a database driver's, its fault log prints the text as well. Test
Connection has the same limit: an exception raised while it opens the association or sends the C-ECHO would
reach the result's detail through `safe_exc`.

`tests/_dicom_log_census.py` scans both installed libraries' log and `warn_and_log` calls against a pinned
census, so a call it can read that a library adds or rewords fails a test until it is read: at least a
literal, an f-string, and text assigned to a local variable it then logs. A line built some other way, such as
a dataset dump's loop variable, is in the census only by that variable's name. The pin tests in
`tests/test_dicom_peer_value_logs.py` fail when either library's version changes in the environment they
run in, and when a line they read changes, so a change to the lock has to re-read the shapes. They do not
reach a site's own install: the `[dicom]` extra pins pynetdicom exactly but lets pydicom resolve to any
release from 3.0.2 below 3.1, and the tests run only the release the lock names. Known shapes not covered
yet, at least: a flagged UID that spells a name in pydicom's UID dictionary, which a dump field, the
`No presentation context for` line and the `No supported service class` line keep; and pydicom's
`Unknown VR` line, which names two bytes of an object and is written only with pydicom's own debug
switched on. The SCP reads each association
request and command set once before pynetdicom does. What that read writes on the loggers the SCP filters is
run in. They do not reach a site's own install: the `[dicom]` extra pins pynetdicom exactly but lets pydicom
resolve to any release from 3.0.2 below 3.1. Known limits, at least: a flagged UID that spells a name in pydicom's UID
dictionary is kept by a dump field, the `No presentation context for` line and the `No supported service
class` line. The SCP reads each association
request and command set once before pynetdicom does. What that read writes on the named loggers is
written only where the command set itself ends the association. Where a later PDU ends it, before
pynetdicom reads the message, that read's lines are written nowhere. A line on any other logger is written
twice. pydicom also raises each of its lines above as a `UserWarning`, which would carry the value to
stderr. A warnings filter, installed at import, at each SCP start, at each C-STORE the SCP serves and
before each SCU read and association, ignores those copies and no other pydicom warning; a host that resets
the process's warnings filters between those points brings the copy back until the next one, and the SCP's
pre-read of a command set is not one of them. Under context-aware warnings, the free-threaded default, the
filter is installed at every one of those points, which also repeats another library's once-per-location
warning. The filter also renders a codec error on these loggers
without the byte it failed on, for a host whose handlers lack the engine's log chain. The engine's
own C-STORE lines name an object's SOP class and instance UIDs only when they are conformant, and `[redacted]`
otherwise, and redact a refused value of a shape the filter knows from a library error they quote; a
library error of another shape is quoted through `safe_exc` alone.
twice, screened. pydicom also raises each of its lines as a warning, which would carry the value to
stderr. One warnings filter, scoped to pydicom's modules so that no other library's warning is silenced, is
installed at import, at each SCP start, at each C-STORE the SCP serves and before each SCU read and
association. A host that resets the process's warnings filters between those points brings the copy back
until the next one, and the SCP's pre-read of a command set is not one of them. Under context-aware warnings,
the free-threaded default, the filter is installed at every one of those points, which also repeats another
library's once-per-location warning. The engine's own C-STORE lines name an object's SOP class and instance
UIDs only when they are conformant, and `[redacted]` otherwise, and quote a library error only through the
same screen.
- **Egress is fail-closed.** A DIMSE destination is gated by `[egress].allowed_tcp`; a DICOMweb destination by
`[egress].allowed_http` — both enforced at load/reload/start.

Expand Down
15 changes: 8 additions & 7 deletions docs/PHI.md
Original file line number Diff line number Diff line change
Expand Up @@ -362,15 +362,16 @@ path** (no separate at-rest tier):
- **DICOM objects `[BUILT]` (ADR 0025).** A received DICOM object is **PHI** — the header carries
PatientName / MRN / DOB — and is stored through the store cipher like any other body, never logged at
INFO+, egress-allowlisted, and TLS off-loopback. Logs/errors carry only **routing-safe identifiers**
(SOPClassUID / Modality / UIDs / AE title), never the dataset or element values. That rule covers
(SOPClassUID / Modality / UIDs / AE title), never the dataset or element values, except as
[DICOM.md](DICOM.md) section 5's limits state. That rule covers
third-party library loggers too, such as pynetdicom's and pydicom's, and a peer-sent value either
library refuses or flags as non-conformant must never be logged verbatim (owner ruling 2026-11-03,
BACKLOG #5081). The DICOM transport applies that rule through a log filter that redacts the value
from at least a list of known pynetdicom and pydicom line shapes, so it meets the rule only for
those shapes. A line of a new shape, such as a library upgrade could add, passes whole until it is
added. The pin tests fail when either library's version changes in the environment they run in,
which is not a site's own install. The list, and what it does not cover, is in
[DICOM.md](DICOM.md) section 5. (Pixel data can carry
BACKLOG #5081). The DICOM transport applies that rule by default-deny on those libraries' loggers
(BACKLOG #6637): a line that is neither a pinned value-free line nor a full match of a pinned
template is withheld.
The pin tests fail when either library's version changes in the environment they run in,
which is not a site's own install. What a withheld library line keeps, what stays, what an
operator loses and the limits are in [DICOM.md](DICOM.md) section 5. (Pixel data can carry
*burned-in* PHI, but **pixel-data handling is out of scope.**)
- **Base64-carried binary bodies `[BUILT]` (ADR 0028).** A base64-encoded body is **still PHI** —
encoding is not obfuscation — so the never-log rules (§7) apply unchanged. Base64 inflates size by
Expand Down
Loading