Reproduce both loops#
We built both loops on a local server and loaded them in Chromium.
A cookie that never sticks. /account redirected to /login when no sid cookie was present. /login answered with a redirect back to /account and Set-Cookie: sid=abc; Domain=example.com; Path=/. The page was served from localhost, so the browser rejected a cookie for another domain. Every /account request arrived without a cookie. Chromium made 20 requests and stopped with net::ERR_TOO_MANY_REDIRECTS.
Two layers that disagree. Our stand-in for a host rule sent localhost/flip to 127.0.0.1/flip and back again. With 302 responses, the server again saw 20 requests before the error.
The same loop with 301. With permanent redirects, the server saw two requests on the first attempt. On a second attempt in the same browser, it saw none: Chromium followed its cached redirects and still showed ERR_TOO_MANY_REDIRECTS.
Tell the two causes apart#
Capture the hops with Preserve log on, as the redirect chain guide describes, then read them:
| What the hops show | Cause |
|---|---|
The same two URLs repeating, a Set-Cookie on one of them, and no matching cookie on the next request | Either the browser refused the cookie, or stored it and left it out of the request. Check which before going further. |
URLs that differ only in scheme (http and https) or host (www and the apex) | Two layers rewrite in opposite directions |
| No new requests in the server log while the browser still loops | Cached permanent redirects. Retry in a fresh profile. |
To tell the two apart, look in Application > Cookies for the site. If the cookie is missing, the browser refused it, and the response's row in the Network panel's Cookies tab shows a warning and the reason, such as a domain mismatch, a Secure cookie set over plain http on a non-local host, or SameSite rules. If the cookie is stored, it was filtered out of the next request, for example by its Path, SameSite or Secure attribute; the request's Cookies tab can show filtered-out request cookies with the reason. Login succeeds, then the next request is anonymous lists the reasons and what each one means.
The scheme flip behind a proxy#
A common production loop: a TLS-terminating load balancer forwards plain http to the application. The application sees http, redirects to https, and the browser comes back through the load balancer, which forwards http again. The hops show https://example.test/ redirecting to https://example.test/ with the same Location every time, because the browser only ever sees https.
The deciding evidence is on the server side: the scheme the application thinks the request used. Most frameworks read it from X-Forwarded-Proto or the standard Forwarded header, and only when configured to trust the proxy. Log the header and the framework's computed scheme for one request. MDN: X-Forwarded-Proto · RFC 7239: Forwarded
The same shape appears for hosts: a CDN rule sends www.example.test to example.test, and the application sends example.test to www.example.test.
Worked example: a loop for one customer's domain#
This example is fictional. A SaaS product lets customers use their own domain. One customer reports ERR_TOO_MANY_REDIRECTS on app.customer.test; other custom domains work.
The customer's hops alternate between https://app.customer.test/ and https://app.customer.test/login, with Set-Cookie: session=…; Domain=.product.test on the login hop and no cookie on the next request. The application set its session cookie for its own domain, which the browser refused on a customer domain. Other customers' domains had gone through an onboarding step that configured the cookie domain; this one had been added by hand. The hops and the refused cookie's reason pointed at configuration, not code.
Questions#
Why does clearing cookies sometimes fix a loop?
A stale or oversized cookie can make the server redirect for a reason the new cookie cannot fix. Clearing removes it. If clearing does not help, the cookie is not being stored at all, or the loop does not depend on cookies.
How many redirects does Chrome allow?
In our fixture Chromium made 20 requests before showing the error. Other browsers use their own limits, and the exact number rarely matters: any loop reaches it.
Can a service worker cause a redirect loop?
Yes, if its fetch handler answers navigations with a redirect. Check for (ServiceWorker) on the hops, and see which worker controlled the page.
Return to reproducing what someone else saw for the other layers a replay needs.