Let installed apps sign in over https again
The __Host- session cookie name now goes to browsers only. Native clients (no Origin or fetch metadata), including app builds from before the change, get the plain cookie name, still Secure over https, so they find their session after signing in.
This commit is contained in:
+11
-1
@@ -12,8 +12,18 @@ export function isHttps(req) {
|
||||
return forwarded === "https" || Boolean(req.socket?.encrypted);
|
||||
}
|
||||
|
||||
/** Whether the request comes from a browser (they send fetch metadata or an
|
||||
* Origin on a form POST); the native app, curl and peer proxies send neither. */
|
||||
export function isBrowserRequest(req) {
|
||||
return Boolean(req.headers["sec-fetch-site"] || req.headers.origin);
|
||||
}
|
||||
|
||||
/** Browsers over https get the host-locked `__Host-` cookie. Native clients
|
||||
* keep the plain name (still Secure over https): installed app builds from
|
||||
* before the `__Host-` cookie only read that name, and a native client has no
|
||||
* other site sharing its cookie jar, which is what `__Host-` guards against. */
|
||||
export function sessionCookieName(req) {
|
||||
return isHttps(req) ? HOST_SESSION_COOKIE : SESSION_COOKIE;
|
||||
return isHttps(req) && isBrowserRequest(req) ? HOST_SESSION_COOKIE : SESSION_COOKIE;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user