Skip to content

fix: CSRF protection for email auth form endpoints#122

Merged
mahata merged 2 commits intofeat/email-signupfrom
copilot/sub-pr-120-again
Mar 25, 2026
Merged

fix: CSRF protection for email auth form endpoints#122
mahata merged 2 commits intofeat/email-signupfrom
copilot/sub-pr-120-again

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Mar 25, 2026

Session cookie was set to SameSite=None in production, leaving the email login and registration POST endpoints open to CSRF/login-CSRF attacks from cross-origin form submissions.

Changes

  • hono/app.tsx
    • Hardened session cookie from SameSite=None (production) → SameSite=Lax unconditionally. Blocks cross-site form POSTs at the browser layer while preserving Google OAuth redirect flows (top-level GET navigations are unaffected by Lax).
    • Added Hono's built-in csrf() middleware as a second layer — rejects non-safe form submissions where the Origin header doesn't match the server origin. Placed after static file routes to avoid unnecessary overhead on asset requests.
// Before
sameSite: process.env.NODE_ENV === "production" ? "none" : "lax",

// After
sameSite: "lax",
app.use("/static/*", serveStatic({ root: "./hono" }));
app.use("*", csrf()); // origin-check on form POSTs
  • hono/routes/emailAuth.test.ts
    • Added Origin: "http://localhost" to all existing POST test requests to satisfy the CSRF middleware in the test environment.
    • Added tests asserting cross-origin form submissions to both /auth/login and /auth/register receive 403 Forbidden.

⌨️ Start Copilot coding agent tasks without leaving your editor — available in VS Code, Visual Studio, JetBrains IDEs and Eclipse.

Copilot AI changed the title [WIP] [WIP] Address changes based on review feedback for email authentication PR fix: CSRF protection for email auth form endpoints Mar 25, 2026
Copilot AI requested a review from mahata March 25, 2026 12:10
@mahata mahata marked this pull request as ready for review March 25, 2026 12:43
@mahata mahata merged commit 07e8cf4 into feat/email-signup Mar 25, 2026
@mahata mahata deleted the copilot/sub-pr-120-again branch March 25, 2026 12:44
mahata added a commit that referenced this pull request Mar 25, 2026
* feat(auth): implement email authentication with login and registration routes

* Apply suggestion from @Copilot

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* test(emailAuth): add unit tests for success flows and conflict paths (#121)

* Initial plan

* test(emailAuth): add unit tests for success flows and conflict paths

Co-authored-by: mahata <23497+mahata@users.noreply.github.com>
Agent-Logs-Url: https://github.com/mahata/mlack/sessions/e8292715-c961-480d-8c1a-490e2db65f9a

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: mahata <23497+mahata@users.noreply.github.com>

* fix: CSRF protection for email auth form endpoints (#122)

* Initial plan

* fix: add CSRF protection for email auth form endpoints

Co-authored-by: mahata <23497+mahata@users.noreply.github.com>
Agent-Logs-Url: https://github.com/mahata/mlack/sessions/81a07abc-5f9a-4910-8bdc-71951fdb71bb

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: mahata <23497+mahata@users.noreply.github.com>

* fix: add missing Origin header in POST tests blocked by CSRF middleware (#124)

* Initial plan

* fix: add Origin header to POST tests blocked by CSRF middleware

Co-authored-by: mahata <23497+mahata@users.noreply.github.com>
Agent-Logs-Url: https://github.com/mahata/mlack/sessions/86a80766-f33f-4962-ba8e-c5907a70e520

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: mahata <23497+mahata@users.noreply.github.com>

* Initial plan (#125)

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>

* fix: add Origin header to E2E test requests blocked by CSRF middleware (#126)

* Initial plan

* fix: add Origin header to E2E test requests blocked by CSRF middleware

Co-authored-by: mahata <23497+mahata@users.noreply.github.com>
Agent-Logs-Url: https://github.com/mahata/mlack/sessions/edbeed38-429c-4f9f-beb6-cf8d58dc7ec4

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: mahata <23497+mahata@users.noreply.github.com>

---------

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <198982749+Copilot@users.noreply.github.com>
Co-authored-by: mahata <23497+mahata@users.noreply.github.com>
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.

2 participants