Skip to the page

Errors and releases that break pages · mid

Cookies: SameSite and domain changes that cause loops

Login loops and payment redirect loops often come from cookie rules. SameSite decides which cross-site requests carry the cookie, and a cookie with the same name but another Domain can hide beside the old one.

The notes

What you must know

  • Trace the redirect chain with a HAR file or DevTools "Preserve log", and check which cookies arrive with each request.
  • Return from a payment gateway is a cross-site POST. Lax cookies are sent on cross-site top-level GET navigations but not on a cross-site POST, so the callback arrives with no session.
  • Cause here: the release removed SameSite=None, so Chrome treats the cookie as Lax. Chrome lets very new cookies (about 2 minutes old) go with top-level POSTs, so a quick test passes. Safari and Firefox do not default to Lax, which is why only Chromium users loop.
  • Proper design: the callback does not need the session. The server verifies the gateway signature, finds the order by id, then redirects (303) to an order-status page. The server webhook is the source of truth, never the browser "success".
  • Keep SameSite=Lax (it helps against CSRF) and fix the flow. Do not weaken security.
  • Right now for payments: reconcile with the gateway (webhooks or its payments API) before creating orders or refunds.
  • Login loop after a Domain change: two cookies named session, an old host-only one and a new one with Domain=.example.com. The server reads the first, which is the old invalid session. Cookies with the same name and different Domain or Path live side by side, with no promised order.
  • Fix: delete the old cookie on purpose (same name, old scope, Max-Age=0), rename the cookie (or use the __Host- prefix for host-only), make every service set the same scope, and test with the old cookie already in the browser.

The red pen

Common traps: mistake → fix

  • Mistake: Removing SameSite=None is a harmless cleanup

    Fix: it can break cross-site POST returns.

  • Mistake: The browser success page proves the payment worked

    Fix: only the server and webhook confirm it.

  • Mistake: Setting the cookie again overwrites the old one

    Fix: a different Domain or Path makes a second cookie.

Easy to hard

Questions interviewers ask, easy to hard

  1. After a release, payments loop back to login. How do you debug it?
  2. Why does it fail only in some browsers?
  3. After a cookie domain change, some users cannot log in. What do you check?
  4. How would you design the payment return to avoid depending on the session cookie?

Explain it out loud

Explain it out loud to an AI interviewer that follows up, and see where your answer is thin.

Practise by voice

Your first interview is free

Sign up and start with a 15-minute interview with the full report, and an English conversation. No card needed.

Start your free interview