Skip to content

fix: ask the name grammar before the class question (#109) - #133

Closed
VendettaGamesHQ wants to merge 2 commits into
flop-labs:mainfrom
VendettaGamesHQ:fix/name-grammar-before-class-answer
Closed

VendettaGamesHQ wants to merge 2 commits into
flop-labs:mainfrom
VendettaGamesHQ:fix/name-grammar-before-class-answer

Conversation

@VendettaGamesHQ

Copy link
Copy Markdown

Closes #109.

The change

A room class is a name prefix, so room_classes reads a class marker off a string this service will never store. Both write gates asked their class question before anything read the grammar, so the correction the answer named then contradicted it:

GET /r/mb-FOO/say/bot/hi        403 … it takes signed writes only,
                                    send: GET /r/mb-FOO/say-signed/…
GET /r/mb-FOO/say-signed/…      400 bad name 'mb-FOO'

The ownership lane split the same way on the identical key: room-owners asks store.ownable first (403 "cannot be owned"), while room-allow reaches note_get, which validates (400 "bad name").

Both gates now validate first. valid_name raises StoreError, which is already mapped to the same 400 the storage layer produces, so this borrows that message rather than restating it — no new error text, and the signed lane's answer becomes every lane's answer.

Two things worth flagging rather than burying

The core cap moves by one. Folding the calls into existing statements kept it to a single added code line, which puts core/app.py at 942 and the core total at 1903. I did not golf it further: ns, key = store.valid_name(ns), store.valid_name(key) is deliberately not the shorter and form, because and short-circuits and the key would then only be validated when ns happened to be the nonce namespace — a validation that does not run, which is the bug being fixed. Happy to take a different shape if you would rather the cap held.

The tests go in tests/http/test_lane_parity.py, because that is precisely what this bug is: one logical write, several lanes, disagreeing — invisible to any single-lane test. They reuse _client's _keypair / _say_signed rather than re-implementing the signing construction.

The signed lane is really signed, and that mattered: _signer runs before the gate, so a placeholder did:key is answered on the DID and never reaches the name check. My first version did exactly that and CI caught it — the test would have asserted nothing about names while appearing to cover the lane.

There is also a mirror test: a name the grammar accepts must still get its class answer, or the whole thing would pass just as happily if the gate started refusing every mailbox.

Verification

ruff check, ruff format --check, sz.py --check and sz.py --caps pass. The pytest suite needs POSIX fcntl, which the machine I wrote this on does not have, so it was verified in CI rather than claimed here:

The d-, e- and p- parameters do not reproduce the bug (no gate fires on those classes); they are there for the consistency the file exists to assert.

Closes flop-labs#109.

A room class is a name PREFIX, so `room_classes` reads a class marker off a
string this service will never store. Both write gates asked their class
question before anything read the grammar, so a name the grammar refuses got
answered on class grounds — and the correction the answer named then
contradicted it:

    GET /r/mb-FOO/say/bot/hi     403 ... it takes signed writes only,
                                     send: GET /r/mb-FOO/say-signed/...
    GET /r/mb-FOO/say-signed/... 400 bad name 'mb-FOO'

The ownership lane split the same way on the identical key: `room-owners`
asked `store.ownable` first (403 "cannot be owned"), while `room-allow`
reached `note_get`, which validates (400 "bad name").

Both gates now validate first. `valid_name` raises `StoreError`, which is
already mapped to the same 400 the storage layer produces, so this borrows
that message rather than restating it — no new error text, and the signed
lane's answer becomes every lane's answer.

Folded into existing statements rather than added as new ones, so app.py
grows by one code line rather than three. `ns, key = valid_name(ns),
valid_name(key)` is deliberately not the shorter `and` form: `and`
short-circuits, so the key would only be validated when ns happened to be
the nonce namespace — a validation that does not run, which is the bug
being fixed.

The one line puts core/app.py at 942 and the core total at 1903, so both
caps move by exactly one. Flagging that rather than golfing it: the
readable form seemed the better trade against "no code golf ... unreadability
is a reject even when the line count goes down". Happy to take a different
shape if you would rather the cap held.

Tests go in tests/http/test_lane_parity.py because that is precisely what
this bug is: one logical write, several lanes, disagreeing. Five bad names
across four lanes, both ownership lanes on one key, and the mirror — a name
the grammar ACCEPTS must still get its class answer, or the fix would pass
just as happily by refusing every mailbox.

Verified: ruff check, ruff format --check, sz.py --check and sz.py --caps
all pass locally. The pytest suite needs POSIX `fcntl`, which this machine
does not have, so the suite is verified in CI rather than claimed here.
CI caught it: 330 passed and my 5 failed, all on the same line. The signed
lane runs _signer BEFORE the gate, so a placeholder did:key is answered on
the DID and the name check is never reached. The test would have asserted
nothing about names while appearing to cover the lane.

Reuses _client's _keypair/_say_signed rather than re-implementing the
signing construction, so the parity test agrees with the service and not
with itself.
@VendettaGamesHQ

Copy link
Copy Markdown
Author

Closing this — #108 got here first and is the better version.

Entirely my fault: I read the issue and went straight to the code without checking the open PR queue, which is a thing I should have done in a repo with sixty-odd of them. Apologies for the noise.

#108 covers the same two gates and also carries the CHANGELOG and AGENTS entries this was missing. One thing from here that may be worth folding in if you want it, and may equally not be:

  • I put the regression in tests/http/test_lane_parity.py rather than test_rooms.py, on the reasoning that this bug is a lane disagreement — one logical write, several lanes, different answers — which is exactly what that file exists to catch and what a single-lane test cannot see.
  • The mirror assertion: a name the grammar accepts must still get its class answer, so the fix cannot pass by refusing every mailbox.

Both are three lines each against #108 if useful. Happy either way — the fix is the point and it is already in a better PR.

One note for anyone hitting the same thing: the signed lane needs a real signature to reach the name check, because _signer runs before _room_write_gate. My first test used a placeholder did:key and passed through the DID validator instead, so it asserted nothing about names while appearing to cover the lane. CI caught it.

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.

A name the grammar refuses gets a class answer: mb-FOO says 403 'send a signature', say-signed then says 400

1 participant