Skip to content

middleware: csrf token for first requests, verified auth, 0.5.0 - #67

Merged
carlrafting merged 1 commit into
devfrom
claude/middleware-open-issues
Nov 23, 2026
Merged

carlrafting merged 1 commit into
devfrom
claude/middleware-open-issues

Conversation

@carlrafting

Copy link
Copy Markdown
Owner

Summary

Resolves the limitations left open after #66. Stacked on #66, which sits on #65 and #64, so the diff here is one commit. Merge #64, then #65, then #66, then this; each should retarget to dev as the branch below it is deleted.

  • csrf: new csrfToken(request) helper so a handler can embed the token in a form or page, including on a visitor's first request, before the httpOnly cookie has reached the browser. The middleware now issues the token before running the handler and records it against the Request object. Call it with the same Request the middleware received.
  • auth: verify(value, request) is now required and decides whether the cookie value is acceptable, instead of trusting that a cookie named authenticated exists. The cookie name is configurable (cookie, default authenticated). Requests to the sign-in path still bypass the check; verify is only called when the cookie is present.
  • Readme: the code samples are complete, so deno check --doc readme.md passes. The two that cannot stand alone (the compose signature and the serve.ts file that needs a main.ts) are marked ignore.
  • Versions: @stewpot/middleware 0.4.1 to 0.5.0, since the helper return values and the csrf and auth behavior changed. @stewpot/routes now depends on ^0.5.0; ^0.4.1 would no longer match the workspace member, which would bring back the "workspace member was not used" warning.

Things to know

  • auth's new required option breaks the old call shape. The module is not exported and nothing in the repo imports it.
  • JSR currently has middleware 0.4.1 and routes 0.1.4, so routes 0.1.5 is still unpublished and needs no further bump.
  • auth, csrf and session are still not in the package exports. Exporting them would add real public API, so that is left for a separate decision.
  • The repo-wide lint and format findings in the other packages are untouched; that is why the advisory format, lint and doc lint (feeds) checks stay red.

Test plan

  • deno fmt --check, deno lint, deno doc --lint (entry points), deno check, deno check --doc readme.md and deno task test pass in middleware/ (57 tests)
  • Workspace-wide deno check, plus the routes and manage tests, pass; no "workspace member" warning for routes
  • CI is green: test legs and type check blocking; format and lint should report nothing for middleware/ (other packages may still fail them, advisory)

🤖 Generated with Claude Code

@carlrafting
carlrafting added this pull request to stack #68 November 22, 2026 20:49
@carlrafting
carlrafting force-pushed the claude/middleware-open-issues branch 3 times, most recently from 30271eb to 9aa8d79 Compare November 23, 2026 08:33
Base automatically changed from claude/middleware-fixes to dev November 23, 2026 08:34
Resolve the limitations left open after the previous fixes.

- csrf: add csrfToken(request) so a handler can embed the token in a form
  or page, including on a visitor's first request, when the cookie has not
  reached the browser yet. The middleware now issues the token before
  running the handler and records it against the request.
- auth: `verify` is now required and decides whether the cookie value is
  acceptable, instead of trusting that a cookie named `authenticated`
  exists. The cookie name is configurable. Requests to the sign-in path
  still bypass the check. This is a breaking change to a module that is
  not exported and not imported elsewhere in the repo.
- readme: make the code samples complete so `deno check --doc readme.md`
  passes, and mark the two that cannot stand alone (the compose signature
  and the serve.ts file that needs a main.ts) as ignored.
- Bump @stewpot/middleware to 0.5.0, since the stack helper return values
  and the csrf and auth behavior changed in 0.x. Point @stewpot/routes at
  ^0.5.0 so it keeps resolving the workspace member. routes 0.1.5 is
  unpublished (JSR has 0.1.4), so it needs no further bump.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@carlrafting
carlrafting force-pushed the claude/middleware-open-issues branch from 9aa8d79 to 773af38 Compare November 23, 2026 08:34
@carlrafting
carlrafting merged commit 194f7fe into dev Nov 23, 2026
12 checks passed
@carlrafting
carlrafting deleted the claude/middleware-open-issues branch November 23, 2026 08:36
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.

1 participant