Skip to content

feat(server): session/auth/CSRF/guard primitives + graduate toward Stable (#131, #132) - #153

Merged
JosunLP merged 1 commit into
devfrom
feat/server-stable-131-132
Jun 28, 2026
Merged

feat(server): session/auth/CSRF/guard primitives + graduate toward Stable (#131, #132)#153
JosunLP merged 1 commit into
devfrom
feat/server-stable-131-132

Conversation

@JosunLP

@JosunLP JosunLP commented Jun 28, 2026

Copy link
Copy Markdown
Collaborator

Collected work for the two open server tickets, landed in one branch and targeting dev.

Closes #131. Closes #132.

#132 — session, auth, and middleware primitives

  • session() + memoryStore() — HMAC-signed session-id cookie (Web Crypto, cross-runtime), payload in a pluggable SessionStore (in-memory default; bring-your-own Redis/DB without bundling a client). ctx.session is a Proxy: payload via plain props, lifecycle via $id / $isNew / $data / $regenerate / $destroy / $clear. Includes secret rotation, rolling sessions, prototype-pollution filtering, and session-fixation defense.
  • csrf() + csrfToken() — OWASP double-submit cookie (signed when a secret is supplied); token via x-csrf-token header or _csrf body field. Composes with the security module (integrity vs. output).
  • guard() — predicate route guard mirroring the router's guard ergonomics.
  • basicAuth() / bearerAuth()Authorization parsing with a verify() hook; resolved user on ctx.state.
  • Signing utilitiessignValue / unsignValue / timingSafeEqual / randomToken / randomId / base64Url*, all on globalThis.crypto.subtle (no node:crypto).
  • Shared cookie helpers extracted to src/server/cookies.ts (+ appendSetCookie); no behavioral change to existing ctx.setCookie.

#131 — promote server toward Stable

  • Guide Stability section: exit-criteria checklist, frozen ctx/app surface, per-runtime support matrix; intro + README notes; version history.
  • app.listen() now supports Deno via Deno.serve (Node/Bun/Deno covered).
  • ctx.session is additive/optional — no breaking changes to the 1.14 surface.
  • New exports wired through server/index.ts and the /full bundle.

Zero-dependency & secure-by-default

No runtime dependencies added; each primitive is independently importable/tree-shakeable. Sessions default to httpOnly + SameSite=Lax; signing is HMAC-SHA-256; comparisons are constant-time.

Verification

  • Full suite 2785 pass / 0 fail (42 new in tests/server-stable.test.ts: sessions, CSRF, guards, auth, crypto — incl. secret rotation, rolling, $destroy-revive, immutable-response cookies).
  • Cross-runtime smoke extended for server (sign/verify, session, CSRF) — passes on Node + Bun locally; Deno in CI.
  • tsc, eslint, bun run build, check:full-bundle (in sync), check:doc-exports (server 23/23) all green.

Review

Ran an adversarial multi-agent review of the diff; applied the confirmed hardening: don't cache a rejected HMAC key-import, guard timingSafeEqual against empty input, revive a session written-to after $destroy(), simplify the Deno listen() address resolution, and strengthened tests/docs.

🤖 Generated with Claude Code

…te toward Stable (#131, #132)

Collected work to land the two open `server` tickets in one branch.

#132 — session, auth, and middleware primitives:
- session() + memoryStore(): HMAC-signed session-id cookie (Web Crypto,
  cross-runtime), payload in a pluggable SessionStore (in-memory default,
  bring-your-own without bundling a client). `ctx.session` is a Proxy —
  data via plain props, lifecycle via $id/$isNew/$data/$regenerate/$destroy/
  $clear. Secret rotation, rolling sessions, prototype-pollution filtering,
  session-fixation defense via $regenerate.
- csrf() + csrfToken(): OWASP double-submit cookie (signed when a secret is
  given); token via x-csrf-token header or _csrf body field; composes with
  the security module.
- guard(): predicate route guard mirroring the router's guard ergonomics.
- basicAuth()/bearerAuth(): Authorization parsing with a verify() hook,
  resolved user on ctx.state.
- crypto utilities: signValue/unsignValue/timingSafeEqual/randomToken/
  randomId/base64Url* built on globalThis.crypto.subtle (no node:crypto).
- Shared cookie helpers extracted to src/server/cookies.ts (+ appendSetCookie).

#131 — promote `server` toward Stable:
- Stability section in the guide: exit criteria, frozen ctx/app surface,
  per-runtime support matrix; intro + README notes; version history.
- app.listen() now supports Deno via Deno.serve.
- ctx.session is additive/optional — no breaking changes to the 1.14 surface.
- New exports wired through server/index.ts and the /full bundle.

Tests: tests/server-stable.test.ts (sessions, CSRF, guards, auth, crypto;
secret rotation, rolling, $destroy-revive, immutable-response cookies) plus
server coverage in the cross-runtime smoke. Full suite (2785), tsc, eslint,
build, full-bundle/doc-export checks, and cross-runtime (Node/Bun) pass.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@coderabbitai

coderabbitai Bot commented Jun 28, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 8d208c78-5c74-4d3e-a78f-99c6392f05e3

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/server-stable-131-132

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@github-actions github-actions Bot added docs Changes to the documentation tests Chenges to the tests server labels Jun 28, 2026
@JosunLP JosunLP self-assigned this Jun 28, 2026
@JosunLP
JosunLP merged commit 4220cb0 into dev Jun 28, 2026
9 checks passed
@JosunLP
JosunLP deleted the feat/server-stable-131-132 branch June 28, 2026 10:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Changes to the documentation server tests Chenges to the tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant