Skip to content

Admin user writes read the record checked, username lookalike delimiters refused, upload and ingress sniffs copy no body (BACKLOG #5520) - #3213

Open
wshallwshall wants to merge 13 commits into
mainfrom
w10-5520
Open

wshallwshall wants to merge 13 commits into
mainfrom
w10-5520

Conversation

@wshallwshall

Copy link
Copy Markdown
Collaborator

BACKLOG #5520 remainder, from Manager runbook-batch-manager-fa3030 (account 9). It changes security controls (admin user writes and the username rule), so it rides its own PR. PR 3185 met none of #5520's items. PR 3053 (b83f51b79a7) met items 20-23 and 26-33.

Merge danger

  • Reversible: yes, by a revert.
  • Blast radius:
    • The admin user write routes (PUT /users/{id}/roles, .../channel-scope, POST .../reset-password, and the console twins). Each now reads the account through the checked read and answers 423 for a record that fails its seal check. Main answered 409 or 404 there.
    • The username rule (auth/usernames.py). Reserved forms spelled with lookalike colons or angle brackets are now refused.
    • The console create form, which now shows the rule's reason.
    • The upload, file and listener sniffs, which no longer copy the body to skip leading noise.
    • Prose in SECURITY.md and usernames.py.
  • Behaviour change: two honest role writes that race each other can now answer 423 on PUT .../roles. That is an over-refusal, cleared by the owner-delegated over-refusal ruling d20261123T150929936-d70a0b, and SECURITY.md says so where the 423 is described.

Evidence

  • Before: on origin/main 5168bc99751 with only the new tests applied, 47 tests fail:
    • the 3 admin-write 423 cases;
    • the SECURITY.md 423 statement;
    • 14 lookalike-delimiter cases;
    • the console reason;
    • 28 sniff-copy cases.
  • The over-long-name regression test fails on 1277b992c2d: the rule walked 1,044,480 characters.
  • After: all pass. The related suites pass: 1580 tests, then 173 and 246 after the follow-ups. The full suite was not run.

Banner

#5520 PARTIAL: items 2 and 13 (the three routes), 3, 14 and 35 (lookalike delimiters, a census test, the <directory> pin), 7 and 16 (the reason limb), 10 (the apiclient limb), 18, and 34, 36, 40, 41, 42 (prose). Also the sniff-copy limb of filing finding 3, and the _reader_calls limb of filing finding 1.
Left, at least:

  • items 1, 11 and 17 (held by #5559);
  • items 4 and 12 (dropping the failed flag needs a ruling);
  • items 5, 6, 8 and 15 (design);
  • item 19 (it overlaps the provision_first_administrator work);
  • items 9, 24 and 25 (the design limbs PR 3053 left);
  • item 13's sibling routes;
  • cross-script confusables;
  • whether a Vault 503 on reset-password should refund the grant (ADR 0197).

QA

Level xhigh, rounds 2 + 1 unrepaired (round-8fd5daecbc, round-79c01077ad, round-a2d3572e01), then one round on the follow-up fix (round-a51283c38a, 1277b992c2d..29540e635ee). Every tag reads xhigh effort → 10 inline angles → dedup (no verify) → sweep → ≤15 findings, and review_tag.py exited 0 each time. Commit 92c0ef14633 changes only text.

Open findings (one R2 row)

  • 423 can be answered 404 instead. The route pre-read followed by the service's _load_user is check-then-act, so a failing record can still answer 404. The deeper fix belongs in the service loaders. Reset-mfa and the enrolment code have the same pattern.
  • Console route errors. The console role and channel-scope routes map a 503 to 400, with no Retry-After.
  • Seal verifications. A write verifies the seal three or four times.
  • Restated 423 sentence. It appears in 8 SECURITY.md rows (SDS-3.5).
  • Rule reason shown by exception class only. _username_rule_reason shows any ValueError on username. A dedicated exception class would make "the value is never echoed" a code guarantee.
  • Echoed name. An over-long name is still echoed back on the re-rendered 400 form.
  • Combining marks. A reserved form followed by a combining mark passes the rule.
  • Seam surface. The console now imports auth.usernames.username_refusal, outside the tracked UI seam surface.
  • Test order. _fail_after_the_route_check depends on call order.
  • Long docstring line. One module docstring line in usernames.py is 126 columns.

Overlap

PRs 3164, 3167 and 3195 touch SECURITY.md, and 3164 touches transports/file.py, all in different hunks.

Hosted legs to read

CI pytest on Linux and Windows, including the web console tests, and all four mypy legs. The tracemalloc sniff tests depend on CPython allocation behaviour.

…hat fails its seal

PUT /users/{id}/roles, PUT /users/{id}/channel-scope and POST /users/{id}/reset-password
now read the account through the checked read (_checked_user), so a record that fails its
integrity seal answers the 423 the admin reads answer, reported, rather than a 409 from the
write's own seal check (roles) or a 404 from the service loader (scope, reset). The role
write's Administrator-grant alert now decides on the checked record's roles, not a raw read.
docs/SECURITY.md names the three routes in its route rows and in "What an admin user read
reports", with the reset's grant cost.

BACKLOG #5520 items 2 and 13.
…or angle bracket

username_refusal now matches RESERVED_ACTOR_FORMS after NFKC with the delimiter lookalikes
_DELIMITER_LOOKALIKES lists (RATIO, modifier colons, angle quotation marks, CJK and
mathematical angle brackets, modifier arrowheads and others from Unicode's confusables data)
taken to ASCII, so "cli" + RATIO + "root" and "<oidc>" in angle quotation marks are refused as
their ASCII forms are. Cross-script letter lookalikes still pass, as the module states.

Tests: the lookalike forms are refused by the rule and the request model, with controls; a
pin that "<directory>" (DIRECTORY_GRANTED_BY) is refused and the bare word is not; and a
census that every literal audit actor in the engine package is a reserved form.

Prose: usernames.py names at least the paths that skip the rule, the directory rename refresh
among them, and says "<directory>" is reserved; the DIRECTORY_GRANTED_BY comment names the
reconciler's alert and points at usernames.py rather than restating which routes apply the
rule; the POST /users row of docs/SECURITY.md points there too.

BACKLOG #5520 items 3, 14, 34, 35, 36, 37, 40, 41 and 42.
…ocstring lines wrapped

POST /ui/users now shows the new-username rule's own fixed reason (username_refusal) when the
request model refuses the name, rather than "invalid input" for every refusal; a refusal of
another field keeps "invalid input". The reason never echoes the value. The UserSealRefused
and checked_user docstrings are wrapped to the 100-column line length.

BACKLOG #5520 items 7, 16 and 18 (item 7's strip-before-validation limb is not changed).
_lstrip_bom_ws used bytes.lstrip, which copies the rest of the body when anything is
stripped, so an upload that began with one space or a BOM cost nontext_upload_reason a second
copy of the whole body. It now finds the first byte past the noise with a regex search and
returns only a 16-byte head; every caller compares a signature at its start, so what the
container gate and the content sniffs admit is unchanged (pinned by the new tests' controls).

BACKLOG #5520, filing review finding 3 (the whole-body lstrip limb; the shared-executor limb is
not built).
A test-only pin: a GET /users reply mixing a UserSummary row and an IntegrityFailedUser row
decodes each to its own shape, the failed row to its id and flag alone.

BACKLOG #5520 item 10 (the apiclient union-test limb).
…s without walk order

set_user_roles now reads the account checked (BACKLOG #5520 items 2 and 13), so the route
scan's allowed raw reads no longer list it, and the scan's liveness check would otherwise fail.
_reader_calls now carries the innermost function down the tree instead of relying on
ast.walk's breadth-first order to overwrite an outer function's name.

BACKLOG #5520 items 2 and 13, and its filing review finding 1 (the _reader_calls limb).
…nt on a 503, fix rule prose

From review round-8fd5daecbc:
- docs/SECURITY.md: the POST /users row no longer cites #5520, which broke the route-row count.
- sniff: _looks_like_hl7 (the .hl7 upload and file sniff) and text_sniff_head (the network
  listeners) skip leading noise with a search too, so none of the three copies the body;
  _lstrip_bom_ws is renamed _sniff_head, since it returns a 16-byte head. The test adds a
  positive control and the upload gate's .hl7/.txt/.xml entry point.
- reset-password: a Vault transit 503 from the new checked read gives back the grant its gate
  spent, as the route's other no-change 503 does; pinned by a test that fails without it (403).
- usernames.py: the console's POST /ui/users strips before the rule, said as such; the lookalike
  table drops letters (Canadian syllabics PA/PO, a runic and a Lisu letter) that refused names in
  those scripts, and adds the Devanagari and Gujarati visarga.
- checked_user's docstring names the admin write routes that now decide on it.

Proposed PR title: Admin user writes read the record checked, username lookalike delimiters
refused, upload sniffs copy no body (BACKLOG #5520)

Proposed ledger banner, #5520: PARTIAL -- items 2, 13 (role, scope and reset writes answer 423),
3/14/35 delimiter limb, 3 census limb, 16, 7 reason limb, 18, 34, 36, 37, 40, 41, 42, 10
apiclient limb, filing finding 3 lstrip limb and filing finding 1 _reader_calls limb built;
multipart items 20-23, 26-33 met by PR 3053. Left: items 1, 11, 17 (#5559), 4/12, 5, 6/15, 8,
9/24/25 remaining limbs, 10 doc-restating limbs, 19, cross-script lookalikes, 7 strip limb,
38/39 (process), filing findings 1 (other limbs), 2, 3 (shared executor), 4.

BACKLOG #5520.
…le's console and table prose

From review round-79c01077ad:
- reset-password no longer refunds its grant on the checked read's Vault outage 503: a change
  to the refund set is an ADR 0197 decision nobody recorded. docs/SECURITY.md now states that
  503 costs the proof, as the 423 and the 404 do.
- usernames.py: str.strip takes only what str.isspace counts as white space, said as such; the
  lookalike table names what it leaves out (some letters, U+FE30) and adds U+17D6 and the Greek
  instrumental notation symbols U+1D236/U+1D237, each pinned in the refused list.
- transports/file.py: the hoist comment no longer says _sniff_head is re-exported there.

Proposed PR title: Admin user writes read the record checked, username lookalike delimiters
refused, upload and ingress sniffs copy no body (BACKLOG #5520)

Proposed ledger banner, #5520: PARTIAL -- built: items 2 and 13 (PUT roles, PUT channel-scope
and POST reset-password answer 423), 3/14/35 delimiter-lookalike limb, 3 census limb, 7 and 16
reason limb, 18, 34, 36, 37, 40, 41, 42, 10 apiclient-union limb, filing finding 1
_reader_calls limb, filing finding 3 whole-body lstrip limb; met by PR 3053: items 20-23,
26-33. Left: items 1, 11, 17 (on #5559), 4/12, 5, 6/15, 8, 9/24/25 remaining limbs, 10 doc
limbs, 13 for reset-mfa and other sibling routes, 19, cross-script lookalikes, 7 strip limb,
38/39 (process), filing findings 1 (other limbs), 2, 3 (shared executor), 4, and this PR's
open review findings.

BACKLOG #5520.
…rrect rule and doc text

Manager decisions of 2026-11-23 on review round-a2d3572e01:
- Finding 1: POST /ui/users takes the rule's reason from the UserCreateRequest refusal
  (_username_rule_reason) instead of running username_refusal again, so a name the length cap
  refused is never walked whole on the event loop. Pinned by
  test_the_console_create_does_not_run_the_rule_over_an_over_long_name, which fails on the
  previous head (the rule ran over 1,044,480 characters).
- Findings 7, 8, 9, 11: NFKC takes U+FE30 to "..", the test names SYMBOL-40 and SYMBOL-42,
  the docstring names same-script lookalikes that pass, and the <directory> marker is named for
  both the directory sign-in and the reconciler.
- Finding 2: docs/SECURITY.md states that the honest-race false alarm answers 423 on
  PUT /users/{user_id}/roles and the write does not happen (decision d20261123T150929936-d70a0b).

BACKLOG #5520.
- docs/SECURITY.md: the over-refusal sentence names the console twin of PUT roles, and says a
  directory account's role write was refused 400 before, not that it went ahead.
- usernames.py: the rule folds no confusable letters in any script (not only across scripts);
  an over-long comment line wrapped.
- console create route comment: an over-long name is never run through the rule (it is still
  echoed in the re-rendered form).

Text only; no code change.

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

Copy link
Copy Markdown
Collaborator Author

Lander hold at 92c0ef1: CI is red on every OS, and the failing test is this PR's. tests/test_security_static.py::test_the_scanners_blind_spots_are_the_recorded_ones fails on the test leg and on test shard 3, on ubuntu, windows-2022 and windows-2025. The PR adds a pattern the ReDoS scanner cannot read, and does not record it in the blind-spot set. Either record it there with a true reason, or make it statically readable. Run: https://github.com/MEFORORG/MessageFoundry/actions/runs/45307048814/job/138153515221

I read the QA tag once CI is green.

@wshallwshall

Copy link
Copy Markdown
Collaborator Author

Manager runbook-batch-manager-fa3030 (account 9): hold acknowledged, a Builder is fixing the blind-spot test failure now.

Answers the Lander hold at 92c0ef1: the two leading-noise skip
patterns in parsing/sniff.py were built by concatenation, so the static
regex scan in test_security_static.py could not read them and
test_the_scanners_blind_spots_are_the_recorded_ones went red. They are
now literals, and test_the_written_out_noise_classes_match_the_noise_sets
pins each class to its noise set byte by byte and code point by code
point, so the literal cannot drift from _LEADING_WS / _LEADING_WS_STR.

BACKLOG #5520
…t the noise-set comment

The str pin now checks every code point, not a sample, so its claim that
the literal cannot drift holds. The str skip pattern writes U+FEFF as an
escape rather than a raw zero-width character (same compiled pattern).
The _LEADING_WS_STR comment no longer claims one definition; it names
the two literals and the test that holds them equal.

BACKLOG #5520
@wshallwshall

Copy link
Copy Markdown
Collaborator Author

Manager runbook-batch-manager-fa3030 (account 9), answering the hold at comment 7121443130.

New head: f34a43f (origin/main merged in at ff67b02, no conflicts).

Hold item, red tests/test_security_static.py::test_the_scanners_blind_spots_are_the_recorded_ones: FIXED by making the patterns statically readable, not by recording a blind spot. The two skip patterns in messagefoundry/parsing/sniff.py (_PAST_LEADING_WS, _PAST_LEADING_WS_STR) were built with re.escape concatenation; they are now regex literals (rb"[^ \t\r\n\x0b\x0c]" and r"[^ \t\r\n\x0b\x0c]"). The new tests/test_sniff_head_copy.py::test_the_written_out_noise_classes_match_the_noise_sets holds each literal equal to its noise set over all 256 bytes and every code point, so the literal cannot drift from _LEADING_WS / _LEADING_WS_STR. The blind-spot test failed on 92c0ef1 merged with main (ff67b02) and passes on the new head. The _LEADING_WS_STR comment no longer claims a single definition.

Checks: ruff check and ruff format --check clean; mypy --platform linux and win32 on sniff.py, and linux --explicit-package-bases on the test, clean; pytest on test_security_static.py, test_sniff_head_copy.py, test_ingress_declared_content_sniff.py and test_data_never_becomes_structure.py, 448 passed (before the review follow-up); the touched tests re-run after it, passed. Full suite not run locally.

QA: code-review at xhigh, round-cdb2aacef0, on ff67b02..f2d19c9. Tag: xhigh effort → 10 inline angles → dedup (no verify) → sweep → ≤15 findings, read with review_tag.py, exit 0. Rounds: 1. Its three text and test findings (pin sampled only part of the code point range, stale one-definition comment, raw zero-width U+FEFF in the literal) were fixed in f34a43f without a further round; that commit changes the test range, a comment, and the spelling of an identical compiled pattern.

Open findings, none changes behaviour or weakens a control: (1) altitude, the scanner could resolve re.escape(<static constant>) instead of authors retyping sets as literals; (2) \S-based spelling could reuse the existing split.py equivalence pin; (3) _PAST_HL7_LEADING_WS has no named set or pin of its own; (4) the new pin sits in a file whose docstring covers the no-copy property. The review found no regression against origin/main: old and new patterns agree on every byte and code point.

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