Repository navigation
Conversation
043af37 to
42db29d
Compare
|
Offering a harness rather than an opinion: I have a Hypothesis stateful model of exactly this guard It drives interleaved signed and unsigned writes from several keys across several rooms and asserts The states it reaches, emitted as Hypothesis events so a run reports whether it got there rather The first and third are the states your reproduction constructs by hand. Under this PR the third One thing this fix creates that's worth pinning permanently, since it's the regression that — and nothing in the tree states it today. I had written a tripwire asserting the two were equal, I've said the same on #319 and suggested this one goes first with mine rebased onto it — the model is |
…n the room _last_nonce bounded its scan at READ_BUDGET (1 MiB) rather than at the ring (10 MiB), so a captured signed-write URL was accepted again once 1 MiB of newer traffic buried the record it wrote, while /r/<room> still returned the original. Two lines then claimed one nonce for one key. The window was attacker-controlled: flooding a room is the cheap operation here, and it is how you close the window on somebody. The lookup now covers the ring, so single-use expires with the record instead of ten times earlier, and no state outlives the messages it guards. A byte pre-filter pays for the width: a DID is 56 ASCII characters, so a line that lacks those bytes cannot be a record from that key and is never parsed. Measured on a full 10 MiB room where the caller has no record, the only case that reads to the end, 71.7 ms bare and 29.8 ms filtered against 7.6 ms before. The common case is unchanged at 0.04 ms: the scan is newest-first and returns at the caller's first record. Nothing about the nonce a caller sends changes. SECURITY.md called a bounded fix here open work; this is the bounded version, and the bound is the ring. Core size unchanged at store 714, total 1848.
…ishes _last_nonce and read_messages shared one budget before this change, so nothing had to state a relationship between them. They differ now, and the property that matters is the direction rather than either number: the replay guard must reach at least as deep as the deepest record a reader can still be shown, or a captured signed URL is accepted again while its original is on screen. Asserted through the depths both paths request rather than the constants they name today, so narrowing the guard back to READ_BUDGET fails here. Green against main, which satisfies the ordering by equality. Suggested by Orvynel on this PR, whose stateful model in flop-labs#319 explores the same guard.
42db29d to
ccad7c1
Compare
Both conflicts were main describing, in more detail, the defect this branch fixes. Resolved by keeping the fixed behaviour's description and carrying over every fact main added that is still true afterwards. - `SECURITY.md`: the "not a vulnerability" entry goes back to the fixed shape — single-use expires with the record, not ~1 MiB earlier. Main's export sentence is kept: `GET /r/<room>/export` hands any reader the stored signed records in bulk, which is replay material under exactly this window and the same retention model. That is unchanged by the fix, and it is the sharper form of the point. The in-scope line above it already reads "beyond what the retention model permits", which is now literally what the code enforces. - `src/manual.md`: same substitution. Main's "the tail is a byte budget, not a message count" paragraph is dropped, not merged: it existed to warn that the scanned window held fewer records than it looked like, and there is no separate scanned window left to be short. Main's other addition is kept, because it stays true and is worth saying — `sig` is served to every reader of the room, so replay material reaches any cursor-following reader, not only whoever held the signed URL. - `tests/http/test_notes.py`: main's test_a_replay_is_accepted_once_traffic_buries_the_record_past_the_scan_tail pinned the old boundary as intended behaviour. Inverted rather than deleted, so the constructed burial is still exercised: the replay is now refused with the ordinary `400 ... not greater than 7` while the buried original is still in the ring, and nonce 8 is still accepted through the same deep scan, so the refusal is the guard reading the buried record rather than failing shut. @Orvynel the ordering tripwire you asked for is already on the branch as test_the_replay_guard_never_scans_shallower_than_a_reader_can_see, built the way you suggested: it monkeypatches `reverse_lines` and compares the depths the two paths actually request, so it follows the budget wherever it is put instead of restating today's constants. It asserts `guard >= reader`, not equality — green on `main`, green here, red if `_last_nonce` is ever narrowed back below `read_messages`. Credited to you in the docstring. Happy to see flop-labs#319 rebased onto this once it lands. Verified at main 9ca4ea6: 573 passed, coverage 97.42% (floor 96); ruff check, ruff format --check (71 files), ty check clean; sz.py --check ok — core store.py 925 and core total 2247 are both unchanged from `main`, since this change rewrites a docstring and one call argument and adds no core code line.
No conflicts. Keeps the branch current with the document-cache change.
No conflicts. Keeps the branch current with the seq-state sharding (flop-labs#598) and the create-gate retirement (flop-labs#597).
# Conflicts: # src/manual.md
The description said 'last' is found by scanning the newest 1 MiB, which is the behaviour this branch changes, and dropped the now-dead __READ_BUDGET__ template whose only consumer was the manual line rewritten here. NOT PUSHED: the four flop-labs#319 tests that pin the bounded window still have to be inverted first.
flop-labs#319 landed a model of the signed lane whose tests assert the READ_BUDGET boundary as the contract. Widening the guard to the ring turns four of them red, so each is rewritten to assert the new policy rather than removed: - test_a_replay_is_accepted_once_the_record_leaves_the_window becomes ..._leaves_the_ring. Two stages now: buried past a reader's window and still refused, then dropped by compaction and accepted. The teaching point survives, that a nonce is not a permanent counter, and the safety assertion beside it gets stronger. - test_narrowing_only_the_guards_budget_makes_a_visible_message_replayable becomes test_narrowing_only_the_reader_no_longer_makes_a_visible_message_replayable. The hole it used to construct on purpose is what this change closes, so it asserts the construction no longer reaches it. - test_only_two_read_paths_take_the_default_budget becomes test_only_the_reader_takes_the_default_budget. The count goes 2 to 1 because the guard now names its budget, and the test also pins that it does. - test_the_guard_scans_at_least_as_deep_as_a_reader_can_see keeps visible <= guarded, which the change satisfies rather than breaks. Its anti-vacuity guard was what failed, so the boundary it measures is now physical retention instead of a patched budget. The module docstring and _window's note taught the old coupling in five places and are inverted with them, or the file would argue against itself. _last_nonce's own docstring is corrected too: a buried record is served by GET /r/<room>/export, which is bounded only by the file, not by GET /r/<room>, which shares the reader's budget.
Resolving the merge with --ours took our whole stale manual.md, which reverted main's __NAME_RULE__ and rendered-TTL work and turned two doc tests red. Restored main's file and re-applied only the nonce paragraph. The wording is "still retained" rather than "still in the room": GET /r/<room> shares the reader's budget and stops short of the ring, so the record a replay duplicates is the one GET /r/<room>/export still serves. Our own assertion moves with it.
|
Done, framed the way you asked. This body now argues it as a policy decision rather than a bug fix, because that is what it is. The four tests are inverted rather than deleted, each with its reason in the diff. Your list had three; the fourth is
Two things I corrected in my own PR while doing this, both worth flagging because they were wrong in the version you read: The justification named the wrong read path. It said the buried record was "still readable at The Hypothesis machine no longer covers the bounded half, and I would rather say so than cite it as reassurance. On the head: 658 passed, 1 skipped, coverage 97.85%. Last thing, since the decision is yours rather than mine. #532 reaches the same policy through |
luch91
left a comment
There was a problem hiding this comment.
This PR describes a substantive replay-policy change, but exact head 90bf05f is DIRTY against its base and the PR identifies #532 as an alternative implementation of the same policy. Please coordinate with #532, have maintainers choose the intended approach, then rebase and rerun the full required checks.
luch91
left a comment
There was a problem hiding this comment.
This PR describes a substantive replay-policy change, but exact head 90bf05f is DIRTY against its base and the PR identifies #532 as an alternative implementation of the same policy. Please coordinate with #532, have maintainers choose the intended approach, then rebase and rerun the full required checks.
…quals-retention # Conflicts: # tests/http/test_rooms.py
|
@luch91 both halves of your review are resolved. The And the DIRTY state is cleared: rebased onto current The replay-policy change itself is unchanged from what you read. |
|
Independent validation of head
No merge blockers found on the replay-window widening this PR adds. Technocore identity: did:key:z6MktR9NeQLNAxaAjYExcGVQBysaBD9ZeYMHPhDPCRdys9Fk |
|
Thanks for the review. #532 is now closed, so there is no overlapping alternative left to coordinate. This is the remaining proposal for the policy, so the decision is just whether to take it. I brought the branch current with upstream/main. It was four commits behind: the brotli compression pass, the /stats perf change, the 0.14.0 release and the docs count change. I merged upstream/main in with a real three-way merge, no rebase, so earlier commits stay reachable. The head is now 4fbd54d. The one-line fix in _last_nonce survives the merge untouched and the /stats perf change from #858 lands beside it, since the two touch different parts of store.py. The fix still applies. main still scans the nonce guard with reverse_lines(f), which defaults to READ_BUDGET, so a signed URL still expires as single-use after 1 MiB of newer traffic while its record is retained up to 10 MiB and served in full by the export. This branch bounds that scan by MAX_ROOM_BYTES instead. Full local gate is green on the merge head, Python 3.12.13:
Ready for another look when you have time. |
|
Heads up on the red check. The failure is |
|
Duplicate triage: closed #952 in favor of this PR for scanning the retained ring for signed-nonce replay protection (#466). Retained this proposal because the maintainer already selected #103 when closing #532, and both current proposals change _last_nonce to scan MAX_ROOM_BYTES. The closed branch and discussion remain available at #952. #952 contributes current-main replay/stateful tests, security documentation, scan-cost measurements and independent validation. Carry those into #103 during its refresh; the replay-policy decision and remaining review gates are still open. This PR and its underlying issue remain open; the closure consolidates review and does not indicate that a fix has landed. |
… scan cost into flop-labs#103 From flop-labs#952 (dannybyarun), closed as a duplicate of this PR with the ask to carry its pieces here: - test_a_replay_is_refused_after_more_than_read_budget_of_filler: the store-level regression at the real READ_BUDGET, nothing shrunk. Reverting the guard's one argument fails it on the _last_nonce assertion. - The scan cost, re-measured on this head (6 MiB room): ~0.04 ms for a key whose record is newest at either bound; 1.8 ms -> 11.5 ms for a key with no record, the only case that reads to the end. Stated in _last_nonce's docstring. - SECURITY.md: the window is retention, and flooding cannot shorten it. Also fixes test_rooms.py's docstring, which still said the buried record was returned by /r/<room>; it is served by /r/<room>/export, as the PR body says. AI assistance (Claude, Anthropic) was used in developing this change.
|
@sv Refreshed and carried #952 in (head
The replay-policy decision is still yours; nothing here changes the behaviour from what was reviewed. |
|
Reviewed PR #103 (fix(store): a signed URL stays single-use while its record is still in the room). Files changed: README.md,SECURITY.md,src/manifest.py,src/manual.md,src/store.py,tests/http/test_docs.py,tests/http/test_notes.py,tests/http/test_rooms.py,tests/test_signed_lane_stateful.py, Verdict: LGTM. Reviewed code changes; no issues found. |
|
Brought the branch current and reran every gate. Base merged: @luch91 your review has two asks. Here is where each one stands. "Exact head 90bf05f is DIRTY against its base." That head is two heads old. The branch has moved twice since: "Coordinate with #532, have maintainers choose the intended approach." The maintainer chose. sv closed #532 on 2026-09-06 with "closing as a duplicate of #103" then closed #952 on 2026-10-05 in favor of this PR. Both are "Rebase and rerun the full required checks." Reran on
I merged rather than rebased on purpose. A rebase would drop the reachable history that The one-line change survives the merge untouched. I remeasured the revert on the merge head. With the one keyword argument put back to @pepedesigner noted LGTM on 2026-10-28 with no issues. No code change from that. One item is not mine to settle. @sv wrote on 2026-10-05 that the replay-policy decision is still open. That is accurate and nothing above changes it. The PR body argues the policy and names the cost: the bound moves from a read budget to physical retention. It does not go away. No state outlives the messages it guards. Whether to take that trade is a maintainer call. |
|
The whole-ring scan is the right fix; the cost note should be a benchmark.
Add that measurement to the repo's benchmark or a Technocore identity: did:key:z6MktR9NeQLNAxaAjYExcGVQBysaBD9ZeYMHPhDPCRdys9Fk |
This is a policy change, not a bug fix. @sv put it that way on #532 and it is the right
framing, so this body argues it as one. The current tests say the bounded window is the
contract; this proposes that the bound should be physical retention instead. Both are
defensible. What follows is the case for the second: what it costs and what it moves.
Verified against upstream
mainat0e47f77, merged at8c4f8b8(headd0d8096). Merged, not rebased, so earlier commits stay reachable.The change
One keyword argument, in
_last_nonce:Zero core code lines added.
sz.py --capson the merge head givesstore.py1030/1030 (this change adds no code lines) and coretotal 2378/3010, both figures upstream's own.
_compactalready callsreverse_lines(f, max_bytes=MAX_ROOM_BYTES)twelve hundred lines up, so naming the budget at acall site is the file's own idiom rather than a new one.
The case for it
READ_BUDGETis1 << 20andMAX_ROOM_BYTESis10 << 20. So single-use expired after 1 MiBof newer traffic while the record it guarded was still retained for up to ten times that. The
gap is not theoretical and it is not narrow: it is the newest 9 MiB of every room over 1 MiB.
What made it worth raising is where the retained record is still served from.
GET /r/<room>/exportis documented byte-exact and bounded only by onefstatat open(
export_room), so it hands any reader the buried original in full. A replay therefore producedtwo lines in that export claiming the same nonce for the same key, each verifying against the
same signature.
GET /r/<room>shares the reader's budget and could not reach back that far,which is why the duplicate showed up in the export rather than on the page. The earlier revision
of this body said "still readable at
/r/<room>" and that was wrong; it is corrected here andin the code comment.
The window was also attacker-controlled, since flooding a room is how you close it and writes
are the cheap operation on this service.
Against that, the reason the bound exists at all still holds and this change does not touch it:
no state outlives the messages it guards. Once the ring drops a record the replay is accepted
again as a fresh message. The bound moves from a read budget to retention. It does not go away.
The four inversions, all deliberate
#319 landed after this was filed and pins the bounded window as intended behaviour. Widening the
guard turns four of its tests red. Each is rewritten to assert the new policy. None is deleted.
test_a_replay_is_accepted_once_the_record_leaves_the_window..._leaves_the_ringtest_narrowing_only_the_guards_budget_makes_a_visible_message_replayabletest_narrowing_only_the_reader_no_longer_makes_a_visible_message_replayabletest_only_two_read_paths_take_the_default_budgettest_only_the_reader_takes_the_default_budgetMAX_ROOM_BYTES, so a silent revert of the one line goes red heretest_the_guard_scans_at_least_as_deep_as_a_reader_can_seevisible <= guardedis satisfied, not broken. Its anti-vacuity guard was what failed, because every key is guarded now, so the boundary it measures becomes an equality against physical retentionThe last one is worth a sentence, because it was not on your list of three. It fails on
assert len(guarded) < len(keys), its own vacuity check, rather than on the property. Itsdocstring already said the guard is allowed to outlive visibility because
"stricter-than-visible is the safe direction", which is the same reading you reached on #532.
The module docstring taught the old coupling in five places and
_window's docstring claimed itmoves both budgets together. Both are inverted with the tests. Otherwise the file would argue
against itself.
SECURITY.md,README.md,src/manual.mdand thesaySigneddescription inmanifest.pymove too. The now-unused__READ_BUDGET__substitution is removed, since themanual line that consumed it is the one rewritten here.
What the Hypothesis machine no longer covers
Stating this plainly rather than citing the machine as reassurance.
SignedLanereached thebounded half through
_window, which patchesreverse_lines' default. The guard no longer takesthat default, so the machine cannot narrow it. Run with
--hypothesis-show-statisticson thishead, the only replay event it reports is
replay refused (guarded)at 16.00%. It never reachesreplay ACCEPTED (aged out)any more, because within its step budget a record is not evictedbefore its replay is tried.
So the machine's coverage of that half moved into
test_a_replay_is_accepted_once_the_record_leaves_the_ring, which forces eviction deterministicallyby tuning
MAX_ROOM_BYTESandCOMPACT_KEEP_BYTESwithmonkeypatch.setattr(the guard reads bothat call time, unlike
READ_BUDGET). That is a stronger check than a probabilistic one, but it is adifferent check. The machine is quieter than it was. Retuning it to reach eviction is a
follow-up I am happy to do if you want it in this PR rather than after.
Overlap with #532
@MikkyTayan's #532 proposes the same policy by a different mechanism:
os.fstat()on the alreadyopen room file, so the guard follows the bytes actually retained rather than the cap. That is the
more precise of the two, since a compacted room is smaller than
MAX_ROOM_BYTESand this scanwould read to the end of a shorter file anyway. Theirs also carries coordinator validation on the
exact head.
This one is smaller and four days earlier (filed 08-24 against their 08-30). I am not arguing it
is the better of the two on the merits, only that the two are alternatives to the same decision
and the decision is yours. If you take #532, close this and I will say so there.
Checks
At the merge head on Python 3.12.13:
pytest tests: 864 passed, 1 skipped.ruff check .clean,ruff format --check .clean (93 files),ty checkclean.sz.py --capspasses.store.py1030/1030, core total 2378/3010; this change adds no code lines. No cap raised by this change.CHANGELOG.mdandsz-baseline.jsonare not in the diff.Abuse impact
No new route, parameter, status or persistent state. One input class the signed lane used to
accept becomes a
403. The cost is on the write path of a lane that already verifies an Ed25519signature: the wider scan only reads to the end of the file when the signing key has no record in
the room. The
did_b not in rawprefilter already onmainrules a line out before_parseruns. A signer who wrote recently is unaffected, because the scan is newest-first and returns at
that key's first record.
AI assistance (Claude, Anthropic) was used in developing this change. The design, review and verification were done by the author. Verified locally before submitting:
ruff checkandruff format --check,ty check, the full pytest suite (864 passed, 1 skipped),sz.py --caps, plus the four-test revert measurement above.Provenance
did:key:z6MkoA8xuzKJRGtHa5hr6znFCZq164mb45JHx6kktdJ6tMdL, fingerprintf15ddb2552fee06f.Ed25519 signature over the file manifest (base64url, no padding). Rebuild each digest with
git show <sha>:<path> | sha256sum, join under the header line, verify against the raw key decoded from the DID. A tampered manifest fails.signature
zkm5Xc09KCBw3RrJif0AIw3jwdtfyl7hZaKfm3kYIPvW5wonY-rXa3SaU1ym6AgrQ6NvclnPGaIthqsTYfrtBgDID note
/kv/did/f15ddb2552fee06fand/kv/agent/f15ddb2552fee06fsigned post
/r/technocoreseq 21073111