Add ALLOW_INSECURE_COOKIES env flag for HTTP access in production
Browsers drop Secure cookies on plain-http origins, so logging into the admin over a LAN/VPN IP (e.g. during server migration, before TLS is in front) silently failed every authenticated request. Setting ALLOW_INSECURE_COOKIES=true omits the Secure flag; default behavior in production is unchanged. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
+10
-2
@@ -505,10 +505,18 @@ export function hasVisitorConsent(req) {
|
||||
return cookies['vbn_analytics_consent'] === 'yes'
|
||||
}
|
||||
|
||||
// Secure cookies are required in production unless explicitly disabled with
|
||||
// ALLOW_INSECURE_COOKIES=true — needed when the app is reached over plain
|
||||
// HTTP (e.g. by LAN/VPN IP during a server migration, before TLS is set up),
|
||||
// because browsers silently drop Secure cookies on http:// origins.
|
||||
export function cookieSecureFlag() {
|
||||
if (process.env.ALLOW_INSECURE_COOKIES === 'true') return ''
|
||||
return process.env.NODE_ENV === 'production' ? '; Secure' : ''
|
||||
}
|
||||
|
||||
export function setConsentCookie(res, consent) {
|
||||
const value = consent ? 'yes' : 'no'
|
||||
const secureFlag = process.env.NODE_ENV === 'production' ? '; Secure' : ''
|
||||
res.append('Set-Cookie', `vbn_analytics_consent=${value}; Max-Age=31536000; Path=/; SameSite=Lax${secureFlag}`)
|
||||
res.append('Set-Cookie', `vbn_analytics_consent=${value}; Max-Age=31536000; Path=/; SameSite=Lax${cookieSecureFlag()}`)
|
||||
}
|
||||
|
||||
export function isPrivateOrLocalIp(ip) {
|
||||
|
||||
Reference in New Issue
Block a user