diff --git a/internal/handlers/auth.go b/internal/handlers/auth.go index aa5fefe..90be78e 100644 --- a/internal/handlers/auth.go +++ b/internal/handlers/auth.go @@ -18,13 +18,9 @@ import ( const cookieName = "buhapp_at" -// setAuthCookie — кладём access-token в HttpOnly cookie (CORS-friendly, без preflight) +// setAuthCookie — кладём access-token в HttpOnly cookie +// Same-origin через nginx /api proxy: cookie host-only, SameSite=Lax func setAuthCookie(c *fiber.Ctx, token string, ttl time.Duration) { - // SameSite=Lax работает только same-site (subdomain.co → api.subdomain.co) - // Cross-site нужен SameSite=None + Secure - // buhapp.mygoodservice.ru → api.buhapp.mygoodservice.ru — same-site в браузерной семантике - // Но Safari трактует cookie strictly — Lax достаточно для top-level navigation, не для fetch - // Поэтому: SameSite=None + Secure (обязательно для Safari кросс-поддомен) c.Cookie(&fiber.Cookie{ Name: cookieName, Value: token, @@ -32,7 +28,7 @@ func setAuthCookie(c *fiber.Ctx, token string, ttl time.Duration) { MaxAge: int(ttl.Seconds()), HTTPOnly: true, Secure: true, - SameSite: "None", + SameSite: "Lax", }) }