Skip to content

Strict validation compares MSH-9.2 before a same-code borrow keeps the any-segment exemption; batch delivery reads the head's MSH-10 without a full parse (BACKLOG #5920, #5919) - #3194

Merged
wshallwshall merged 7 commits into
mainfrom
w9-5920
Nov 23, 2026

Conversation

@wshallwshall

Copy link
Copy Markdown
Collaborator

Strict validation (_exempts_defined_segments, messagefoundry/parsing/validate.py) now checks MSH-9.2 against a same-code MSH-9.3 borrow before keeping the any-segment exemption: a message naming its own structure (event normalized with strip/upper), a Z event with no hl7apy structure of its own, or an event in the version's table 0003 with no structure of that name keeps it; MFN^M02^MFN_M01, MFN^M05^MFN_M01, empty or made-up events, and QBP^Z73^QBP_Q15 in 2.5 (hl7apy has QBP_Z73) are refused. That last one is a deliberate tightening against main (Manager accepts it: Z73 is an HL7-defined query with its own structure). Batch delivery reads the head's MSH-10 from its first line (head_control_id, parsing/split.py) where that gives the same result as a full parse, with one local edit in wiring_runner.py. The changelog reads as a consistency check: a sender controls all of MSH-9.

Rows and proposed banners

Row Banner
#5920 PARTIAL. Step 1 built: MSH-9.2 checked against a same-code borrow; own event (normalized), Z events without their own structure, and table 0003 events keep the exemption; version-keyed cache. Step 2 met by PR 3032. Step 3 (nested-slot grouping, PRR_PC5, PPV_PCA) is design, not built. Open: a table 0354 event-to-structure map would replace the table 0003 fallback.
#5919 PARTIAL. Step 1 built: head_control_id reads MSH-10 from the first line with the same result as a parse (5000-head parity test). Step 2 (escape budget on non-head members: refuse one or the batch) not built; the row does not settle the scope.

Review proof

Code-review skill at xhigh; each tag reads xhigh effort -> 10 inline angles -> dedup (no verify) -> sweep -> <=15 findings, review_tag.py exit 0. round-24501671, round-80adcf52, round-d8c5e777, round-cfcd7160 (1983d8e..79033af, repaired), round-a28aed3e (..9168542, unrepaired); c565c82 after it is docstring and doc text only.

Open findings (for one R2 row)

  1. Any Z-led MSH-9.2 passes (MFN^Zebra^MFN_M01); the Z test reads the raw value while own is normalized (MFN^Z44 ^MFN_M01 kept, MFN^z44 refused, PGL^PC7 ^PGL_PC6 refused). 2. Table 0003's Varies placeholder passes. 3. The table fallback accepts an event from any family (MFN^A01^MFN_M01, pinned as a known limit). 4. Mixed-case hl7apy names (MFN_Znn, RSP_Znn) never match the upper-cased own. 5. A test name covers more than it says. 6. Batch side: _SHORT_LATER_HEADER copies the parser rule by hand; first-line span logic in three places; test_encode_batch refusals lack a positive control; the escape budget is scanned twice; transports/mllp.py _outgoing_control_id is a second MSH-10 reader.

Hosted legs to read

Full pytest leg, the four mypy legs, test_security_static.

…e any-segment exemption

BACKLOG #5920 step 1. A structure borrowed through MSH-9.3 under the
message's own code (MFN^M02^MFN_M01) kept the any-HL7-segment exemption.
It now keeps it only where the structure is <MSH-9.1>_<MSH-9.2>, or where
MSH-9.2 is a non-empty trigger event hl7apy's tables give no structure of
its own (PGL^PC7^PGL_PC6). MFN^M02, MFN^M05 and an empty MSH-9.2 borrow are
now refused.
…l parse

BACKLOG #5919 step 1. The batch caller ran Message.parse on the whole head
member to read MSH-10 for BHS-11. head_control_id in parsing/split.py
checks the escape budget on the whole text, as the parse does first, and
parses the first line alone where that reads MSH-10 as the full parse
does; every other head is parsed in full, so it reads or raises as before.
wiring_runner.py changes only the read at the batch head.
…cache

BACKLOG #5920 and #5919. The structure lookup is cached by version alone,
so a sender's MSH-9.2 is never kept. A same-code borrow keeps the
exemption only for an event of three capital letters or digits, so a
lower-case, padded or blank event fails closed. The rule is stated once,
in _exempts_defined_segments; the module docstring and HL7-VALIDATION.md
point to it. PGL^PC7^PGL_PC6 is pinned in 2.5 with a 2.5.1 control.
_SHORT_LATER_HEADER is built from HEADER_IDS. The _head_separators
docstring no longer calls its budget check a second one on hydrated text.
Changelog fragment added; a stale test comment fixed.
…orrow case

BACKLOG #5920 and #5919. _SHORT_LATER_HEADER is a literal again, so the
static ReDoS scanner reads it (test_security_static was red); a test holds
its IDs to HEADER_IDS. A same-code borrow keeps the exemption only for an
MSH-9.2 in the version's HL7 table 0003 as hl7apy ships it, so a made-up
event fails closed. A message with no MSH-9.3 borrows nothing and keeps
the exemption as on origin/main. Docs, changelog and comments say what
the rule does, including the borrows that keep it.
Two regressions against origin/main in _exempts_defined_segments: a
same-code borrow naming its own structure with a padded or lower-case
MSH-9.2 (MFN^m01^MFN_M01, MFN^M01 ^MFN_M01), and a Z event borrowing a
structure (QBP^Z44^QBP_Q15 in 2.5, QBP^Z44^QBP_Q11 and RSP^Z44^RSP_K11
in 2.8), were refused. Both keep the exemption again, with a test per
case. The changelog fragment now reads as a consistency check, since a
sender controls all of MSH-9, and the docstring names at least 2.1 to
2.3 as the versions with no table 0003.

BACKLOG #5920
…tion

The Z test now runs after the own-structure lookup, so QBP^Z73^QBP_Q15
in 2.5 is refused as MFN^M02^MFN_M01 is, and the changelog's refusal
condition is true of the code. The docstring, the changelog and
docs/HL7-VALIDATION.md state the check order, the raw-value Z test, and
the known limit that an event of another family (MFN^A01^MFN_M01) keeps
the exemption. The 2.1 to 2.3 clause is dropped: hl7apy refuses an
MSH-9.3 there before this check runs.

BACKLOG #5920
Text only. hl7apy's 2.7 table 0003 lists Z73 to Z99, so the Z branch
is no longer said to exist because the table lists no Z event; the
summary line no longer says the structure must be the message's own;
and the docstring names that any Z-led value and the table's Varies
placeholder pass. The doc's QBP^Z44^QBP_Q15 example names 2.5.

BACKLOG #5920
@wshallwshall wshallwshall added the qa Builder QA record posted; not a merge gate label Nov 23, 2026
@github-actions github-actions Bot added the ci-red A required check went red. Attribute it before retrying. label Nov 23, 2026
@wshallwshall

Copy link
Copy Markdown
Collaborator Author

Lander: two windows reds on c565c82b58c, both in tests this diff does not touch. They are test_dr_passive_delivers_nothing on windows-2022 shard 2 (job 137673509258) and test_worktree_install_daily_prune on the harness windows-2025 leg (job 137673509147). I started one rerun of the failed jobs; a second red is a finding.

@wshallwshall

Copy link
Copy Markdown
Collaborator Author

Lander (session bd594600): cleared at c565c82b58c93c08f68a457e44ef703616ca5d8e; it enqueues once repo harness tests (windows-2025) is green. Review proof: my own xhigh round, round-285caabafc, read with review_tag.py (exit 0). It covers the full diff at this head. Its fork found no correctness defect, and a 200,000-head parity check of head_control_id against a full parse found no mismatch. The last commit's docstring corrections are true. Findings 1 to 6 fall under the owner-delegated over-refusal ruling of 2026-11-23 (decision d20261123T150929936-d70a0b). With the six new ordinary findings, all are queued for filing as one R2 row.

@wshallwshall

Copy link
Copy Markdown
Collaborator Author

Lander: enqueuing at c565c82b58c93c08f68a457e44ef703616ca5d8e (pinned SHA). Every required context is green; the only red is the advisory ASVS-anchors check.

@wshallwshall
wshallwshall added this pull request to the merge queue Nov 23, 2026
Merged via the queue into main with commit fd9cb4a Nov 23, 2026
94 of 98 checks passed
@wshallwshall
wshallwshall deleted the w9-5920 branch November 23, 2026 16:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci-red A required check went red. Attribute it before retrying. qa Builder QA record posted; not a merge gate

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant