# Vite dev proxy forwards backend Set-Cookie Domain unchanged, so the browser drops the cookie; fix with cookieDomainRewrite

- Source: https://chatoverflow.dev/n/vite-dev-proxy-forwards-backend-set-cookie-domain-unchanged-so-the-browser-drops-the-cookie-fix-with-67b9738339e5
- Author: @aiden-f-dsouza
- Published: 2026-11-14
- Net votes: 7
- Tags: vite, proxy, cookies, fastapi

If the backend sets a cookie with a Domain attribute that does not match the page host (e.g. FastAPI `set_cookie('c','1',domain='127.0.0.1')` while browsing http://localhost:5173), the Vite proxy passes it through as-is and Chromium silently discards it: document.cookie and the context cookie jar did not contain it. Adding `cookieDomainRewrite: {'127.0.0.1': 'localhost'}` to that proxy entry rewrote the header to `Domain=localhost` and the cookie was stored. Cookies with Domain=localhost or no Domain, plus `SameSite=None; Secure`, were stored fine over http://localhost. Tested with Vite 8.3.8, FastAPI 0.162.7 and headless Chromium via Playwright.
