Repository navigation
fix: forwarding on the database session, moves into Sent and Drafts, codes used once - #58
Merged
Merged
Conversation
The route that saves a mailbox's settings needs fresh proof only when forwarding changes, and it decided on the flag the guard computed from the copy of the session cached in the cookie, which can be a minute old and still says the session is as new as when the copy was made. A route where only some requests are sensitive is now marked `sensitive` in the route table, and the guard reads its session from the database, as for `fresh` and `upgrade`. A unit test pins the one such route and holds that only its handler reads the flag. Found in review of this change and closed with it: creating a mailbox could set forwarding without fresh proof, by someone who manages the instance and may not read the mailbox; and the forwarding that was compared was a cleaned-up copy while the raw value was stored. A new mailbox never forwards, and what is stored is what was compared. Each Workers-runtime test was seen to fail without its control. Closes #14 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Madraka <8898640+Madraka@users.noreply.github.com>
…as a draft A message is in Sent because the sending service took it, and in Drafts because it is a draft, but the route that moves one message took both as a target; the tools refused them. Sent is now never a target, and Drafts takes only a message the mailbox wrote and that never left: no Message-ID, no header list, no original and not unparsed (`writtenHere`). That is the app's Undo of deleting a draft, which still works, as does a message taken back from Scheduled. A request whose place is not a string is 400 instead of reaching the mailbox. test/workerd/move.test.ts makes every message as the product does: delivered to the email handler, written through the drafts route, or sent and let leave with a send binding of the tests. Taking the guard out fails two of its tests, and weakening the test of a draft to the Message-ID alone fails the one with a received message that has none. Closes #31 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Madraka <8898640+Madraka@users.noreply.github.com>
The sign-in library accepts a code for its step and the steps on either side, about ninety seconds, and remembers none, so a code someone saw being typed could be used again. Before a code reaches the library it is now claimed for the person it is typed for, as a row of the library's own `verification` table whose primary key is an HMAC of the person and the code under the instance secret, kept for two minutes. Of two requests with the same code only one writes that row, in whatever isolate; the other is answered byte for byte as a wrong code. The claim is the last step of the hook, so a request refused for another reason uses up no code. Tests in the Workers runtime: the code that turned the app on, one that signed in another browser, and one given by two sign-ins at once each let in nobody more; the next code still signs in; the claim holds no code. All four fail with the claim taken out. The test helpers hand out each code once, since the old tests typed the same code twice. The browser test now tries the code that turned the app on, sees it refused, and signs in with the next one. Closes #12 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Madraka <8898640+Madraka@users.noreply.github.com>
docs/status.md, section 1 gets the three controls and their tests; section 3 no longer lists them as gaps. The security skill records the `sensitive` mark, the claim of a code and the rule of the move route under B3 and B4, and names workers/auth/used-codes.ts on B3. AGENTS.md and the sign-in design say that a code works once. Refs #12, #14, #31 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Madraka <8898640+Madraka@users.noreply.github.com>
4 tasks
Contributor
Author
|
audit: pass Read: every source line of the change, the names and shape of the new tests, the documents, against #12, #14 and #31. CI: all six checks green on What I checked and found to hold:
Not blocking, written down as #59: no log line when the claim's write fails for another reason; no label of purpose in what the HMAC signs; the comment "is then replaced" is true only for the same person and digits; the two minutes are not tied to the library's settings by a test. Left open as the description says: a row older than mailbox migrations 4 and 5 would count as a draft. |
2 of 10 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What and why
Three gaps on the sign-in and per-mailbox boundaries (B3, B4), one commit each, with documents in a fourth.
sensitivein the route table, and the guard reads its session from the database for it. Two related gaps came up in review and are closed here too: creating a mailbox could set forwarding without fresh proof, and the raw value was stored instead of the compared one. Nothing forwards mail yet, so neither could be used.writtenHere: no Message-ID, no header list, no original, not unparsed). That is what the app's Undo of deleting a draft needs, and it still works.verificationtable whose primary key is an HMAC of the person and the code. Of two requests with the same code only one row is written, in whatever isolate. The other is answered byte for byte as a wrong code. There is no new table and no migration.What changes for a person: someone who turned the app on a moment ago signs in with the app's next code, not the one they just typed.
Regression tests (each seen to fail without its control)
test/workerd/second-step.test.ts, "forwarding, which needs fresh proof only when it changes":test/unit/fresh.test.tspins the onesensitiveroute and holds that only its handler reads the flag, in any of five spellings.test/workerd/move.test.ts: every message is made as the product makes it (delivered, written, sent and let leave). Taking the guard out fails two of its tests. Weakening the draft test to the Message-ID alone fails the received message that has none.test/workerd/second-step.test.ts, "an authenticator code": the code that turned the app on, a code that signed in elsewhere, and a code given by two sign-ins at once. Also: the next code still works, and the claim holds no code. All four fail with the claim taken out.test/e2e/sign-in.spec.tsshows a used code refused in the browser.Runs on this branch, after the rebase on b62d6a1
pnpm check: green.pnpm test:workerd: 28 files, 644 tests.pnpm e2e: 86 passed.An earlier browser run failed in
sign-in.spec.ts: an extra wrong try in the test ran into the sign-in library's limit on second-step requests (429 at the fifth request in ten seconds, read from the trace). The test now makes one wrong try.Open, not done here
USED_CODE_SECONDS(120) fits the library's defaults (30 s period, a window of 1). It must be raised if those are ever changed.Checklist
pnpm checkandpnpm test:workerdare green.git commit -s).🤖 Generated with Claude Code