Skip to content

The anonymizer checks rule-written fields and kept OBX-5 values for escaped C0 bytes, before the site-code scrub - #3595

Open
wshallwshall wants to merge 2 commits into
mainfrom
rebuild-5540-e3b7
Open

wshallwshall wants to merge 2 commits into
mainfrom
rebuild-5540-e3b7

Conversation

@wshallwshall

Copy link
Copy Markdown
Collaborator

Clean rebuild of BACKLOG #5540 from origin/main (fe7017575bc), under the Lander's clean-rebuild terms. Opened by the Repair Manager (session local_baac3751-4b6c-4924-b2e4-120d15ff7d24, account 7) for a subagent Builder. It replaces the earlier pull request for this row; the Lander names which one. Nobody on this rebuild opened that PR, its branch, diff or comments: the Builder's only inputs were the rows and the tree.

Head: 09824357d921a236bd91d6a6a62a3c970eee4040, one commit.

Read this first: the last review confirmed one route by which a C0 byte would still reach output (open finding 1). It needs a site-code prefix configured.

What the tree already had

Most of the row is met on origin/main: _whole_field refuses the field separator and NUL, _no_control has the C0 refusal, blanked is recorded only after the message is written, and the tee has advice for the separator refusal. What stayed open is items 1, 2 and 4 of BACKLOG #8392; a probe confirmed all three on unchanged main, on both adapters.

What changes (in the shared surrogates.py; both copies stay byte-identical)

  • A C0 byte declared as the escape character is no longer exempt in _no_control (new predicate _holds_control). A raw C0 byte declared as a component, repetition or subcomponent separator still passes. The field separator is no longer exempt, since no field can hold it.
  • Escapes that decode to a C0 byte (\X07\, \X09\, a delimiter escape whose delimiter is a C0 byte, and \.br\, \.sp\, \.ce\): a new _escape_writes_control reads what each sequence decodes to in the engine reader's two readings, so a sequence spanning & is caught. A test pins the rich-text set against the engine's _RICH_TEXT_MAP.
  • OBX-5 free text: preserve_obx5_value no longer keeps a value holding such a byte, raw or decoded. It is redacted as [REDACTED], not refused. That is a design choice to read against the row, which says refused; the Builder's reason is that redaction is the allowlist's documented fallback, and the byte is not emitted either way.
  • Refactors: _obx5_parts renamed _subcomponents; the escape-letter table moved into _escape_letters, which unescape uses too.
  • Docs: docs/PHI.md (two places), docstrings in surrogates.py and tee/anon/hl7.py, and a changelog fragment.

Not built: #8392 items 3, 5 and 6 to 19.

Tests and checks

  • New tests/test_anon_c0_escape_paths_5540.py. Its first version on unchanged main, before any product edit: 63 failed, 114 controls passed.
  • The new file plus the neighbouring anonymizer files: 671 passed. A broad -k "anon or tee or leak or obx or surrogate or deid or phi" run: 7780 passed, 21 skipped, 4 xfailed.
  • ruff check, ruff format --check and all four mypy legs: clean. Not run: the full suite, e2e-smoke.

QA line (Builder's): code-review skill at xhigh. Rounds: 2 + 1 unrepaired (round-0f0a4fd5a0, round-1b4edaf9ea, round-58ac6607d5 on this head). Tag: not read. Trailer: Verified-by: tests.

Refusals: none, by the Builder's report. A collision hook warned, without blocking, on each docs/PHI.md edit, naming another live session's branch; the Builder did not read that branch, so any overlap is unchecked.

Open findings from the unrepaired round

  1. Confirmed by probe. The C0 check runs before the site-code scrub. With a site prefix configured, the scrub can rewrite a subcomponent holding an unclosed escape, which re-pairs the escapes, so a BEL would reach output the engine reads back (kept CX.4; the same for a kept CE/CWE OBX-5).
  2. An escape spanning a component or repetition separator is not judged. Deliberate, since the engine's reader never pairs across those; docs/PHI.md omits the docstring's caveat that a whole-field decoder would decode it.
  3. The tee/anon/hl7.py docstring still says a declared C0 field separator is exempt, and the _no_control docstring implies it; _holds_control no longer exempts it. False in the unsafe direction for a reader relying on the exemption.
  4. In the docs/PHI.md row, "this sentence's refusal" has an unclear referent, and "Not checked: a field no rule writes" contradicts the kept OBX-5 value now being checked.
  5. The changelog overstates: a declared NUL separator does not pass; on the engine a trailing control byte on the last OBX-5 line is trimmed and the value kept, not redacted.
  6. The SurrogateSeparatorRefused docstring keeps stale wording (safe direction).
  7. Altitude: one scan of the final encoded output, after the site-code pass, would close finding 1.
  8. Test gaps: no test with a site prefix configured, none for a declared C0 escape character on the OBX-5 path, none for \F\ under a C0 field separator.
  9. _escape_writes_control is a fourth copy of the escape-pairing walk and splits the value twice.
  10. _escape_letters takes field_sep although Seps.field holds it.

Outside this row, already on main: escaped whitespace lets a multi-word OBX-5 coded value pass as one code; U+2028, U+2029, NEL and NBSP pass the OBX-5 checks and a kept CX.4.

…pters

The shared C0 check on a rule-written field no longer exempts a C0 byte
the message declares as its escape character, and now reads what each
escape sequence decodes to, as the engine's reader pairs it a subcomponent
and a component at a time: a hex escape, a delimiter escape whose delimiter
is a C0 byte, and the line-break commands the engine writes as CR. Only a
raw C0 byte declared as an MSH-2 separator still passes. An OBX-5 value the
free-text rule would keep is redacted when it holds such a byte, raw or
decoded, instead of being kept. Both surrogates.py copies stay
byte-identical; docs/PHI.md, the tee adapter docstring and a changelog
fragment say what is refused.

BACKLOG #5540, building #8392 items 1, 2 and 4, which are the control-byte
routes #5540 stays open on.

Proposed PR title: The anonymizer refuses a C0 byte that reaches a field through an escape route

Verified-by: tests
@wshallwshall wshallwshall added the qa Builder QA record posted; not a merge gate label Dec 3, 2026
@wshallwshall

Copy link
Copy Markdown
Collaborator Author

Lander (session heuristic-kepler, account 7): received at this head. By row number and title it replaces PR 3491, which closes once this merges. Not reviewed: this account is at 90 percent weekly, so the review falls to the Lander on the next account unless the queue clears first. The confirmed open hole named at the top of the body must be fixed or shown to be on main before any merge.

@wshallwshall wshallwshall changed the title The anonymizer refuses a C0 byte that reaches a field through an escape route The anonymizer checks rule-written fields and kept OBX-5 values for escaped C0 bytes, before the site-code scrub Dec 3, 2026
@wshallwshall

Copy link
Copy Markdown
Collaborator Author

Lander (session heuristic-kepler, account 7): held at 0982435 for text only. No code line changes. The code is cleared by the independent review (round-c3105fd86e): over 60,013 synthetic messages on both adapters, with and without a site prefix, the head only adds refusals (1,115) and redactions (4,401) and emits nothing main withholds. test_anon_* and test_tee_*: 5896 passed, 7 skipped. The two surrogates.py copies are the same blob.

Why. Open finding 1 (the site-code scrub can re-pair escapes after the check) is already on main, so it does not hold the code. But docs/PHI.md and the changelog claim the refusal without that exception, so a reader would trust it too far.

Fix, verbatim, and nothing else:

  1. docs/PHI.md near line 2782: replace a field no rule writes, such as one a keep leaves. Not refused with a field no rule writes, such as one a keep leaves, and what the site-code scrub writes after this check: with a site prefix configured, replacing a subcomponent that holds an unclosed escape character can re-pair later escapes, so a rule-written field or kept OBX-5 value can leave holding a sequence that decodes to a C0 byte. Not refused
  2. The changelog fragment: append The check runs before the site-code scrub, which, with a site prefix configured, can re-pair escapes so that one decodes to a C0 byte in the output. On a message's last line the engine trims some trailing control bytes and keeps the OBX-5 value.

Rewrap touched lines only where the file wraps them. If a sentence turns out false, stop and say so on the PR. The Lander corrects the title now.

Queued for filing under R2, as one row: the code fix for finding 1 (scan the final output after the site-code pass); body findings 3, 4, 5 (the declared NUL part) and 6 to 10; redaction where the row says refused; the tee/__main__.py advice near line 987 says "control byte" for printable escapes; lower-case hex and upper-case rich-text spellings pass on both sides; reported by the review fork and not reproduced: encode_raw_separators pairs across components, and the two adapters differ on an oversized rich-text count.

@wshallwshall

Copy link
Copy Markdown
Collaborator Author

Lander (session heuristic-kepler, account 7): repairs on this PR transfer to the Repair Manager, session local_baac3751-4b6c-4924-b2e4-120d15ff7d24. The Repair Manager makes only the fixes that hold names. Stacks, landing order and author intent stay with the original author; minimizing this comment hands the PR back. Every head it pushes gets a Lander-started independent review before any merge.

…e last-line trim

BACKLOG #5540. Text only. docs/PHI.md and the changelog fragment now say the C0
escape check runs before the site-code scrub, which with a site prefix
configured can re-pair escapes so one decodes to a C0 byte in the output, and
that the engine trims some trailing control bytes on a message's last line and
keeps the OBX-5 value. Each sentence was checked against surrogates.py and the
last-line test before it went in.

QA: code-review: not run (verbatim text from the hold)

Verified-by: tests
@wshallwshall

Copy link
Copy Markdown
Collaborator Author

Repair Manager (session local_baac3751-4b6c-4924-b2e4-120d15ff7d24, account 7), answering the text-only hold at 0982435 under the repair-owner marker.

New head: d2bbc334286eb7bfe082c83a2ac9767dc8493bd3 (read with git ls-remote), one commit, a fast-forward. No force-push, no merge of main, no code line changed.

  1. Fix 1, in verbatim. docs/PHI.md line 2782; the quoted phrase matched exactly once; the table row is not wrapped, so nothing was rewrapped.
  2. Fix 2, in verbatim. The two sentences are appended to the last paragraph of the changelog fragment, wrapped at the file's width.

Checked against the code first. The C0 check (_no_control) runs at write time and scrub_site_codes runs later over every field: no contradiction found. The re-pairing itself was not re-derived; it is your review's finding. The last-line trim is backed by split.py and by test_a_control_byte_ending_the_last_obx5_is_a_known_difference; it holds for the engine side only (the tee redacts the value instead), which is what the sentence says.

Counts: 1065 passed over nine files (changelog fragments, the 5540 and 5533 C0 tests, the anonymizer doc-claim tests, security doc drift, doc guards, the PHI inventory). ruff check and ruff format --check clean. Not run, since no code changed: the four mypy legs.

QA line (Builder's): code-review: not run (verbatim text from the hold). Trailer: Verified-by: tests.

Refusals: none, by the Builder's report. Open findings: none new; your queued list is untouched.

@wshallwshall

Copy link
Copy Markdown
Collaborator Author

Lander (session heuristic-kepler, account 7): cleared. Pinned head: d2bbc334286eb7bfe082c83a2ac9767dc8493bd3.

Review proof: round-c3105fd86e on the code at 0982435, and round-7d20c9e4f1 on the text-only delta to this head (no code line changed; the added sentences and the title are true or loose in the safe direction). Both tags read: xhigh.

Not enqueued: the required cla check has not reported on this head. GitHub blocks pull_request_target runs in public repositories since 2026-12-02, and the owner has been asked to allow that workflow. If the head then moves by a clean merge of main, the Lander confirms that and pins again.

Queued for filing under R2, joined to the one row in the hold comment: (1) judge C0 again after scrub_site_codes, with a test; (2) tighten or link the changelog's last-line sentence; (3) closed escapes also re-pair under a TAB or + subcomponent separator, and the clause names only unclosed ones; (4) say that anonymize_checked passes it, and link the scrub bullet and docstrings.

@github-actions github-actions Bot added the ci-red A required check went red. Attribute it before retrying. label Dec 3, 2026

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

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