File tree Expand file tree Collapse file tree
apps/cloudflare-workers/src Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -15,6 +15,7 @@ import {
1515 defaultGetClientIp ,
1616 type RateLimitConfig ,
1717 securityHeaders ,
18+ tokenConfig ,
1819} from "@private-landing/core" ;
1920import {
2021 type CacheClientFactory ,
@@ -132,6 +133,10 @@ const rateLimits = {
132133} satisfies Record < string , RateLimitConfig > ;
133134
134135// Global middleware
136+ app . use ( "*" , async ( ctx , next ) => {
137+ tokenConfig . cookieSecure = ctx . env . ENVIRONMENT !== "development" ;
138+ await next ( ) ;
139+ } ) ;
135140app . use ( "*" , securityHeaders ) ;
136141app . use ( "*" , serveStatic ( { cache : "key" } ) ) ;
137142
Original file line number Diff line number Diff line change 99import type { Env , Variables } from "@private-landing/types" ;
1010
1111export interface ControlBindings extends Env {
12- ENVIRONMENT ?: string ;
1312 GATEWAY_URL ?: string ;
1413 GATEWAY_TOKEN ?: string ;
1514 CONTROL_ALLOWED_IPS ?: string ;
Original file line number Diff line number Diff line change @@ -161,8 +161,8 @@ export function createCachedSessionService(
161161 await cache . srem ( userSessionsKey ( state . userId ) , sessionId ) ;
162162 }
163163
164- deleteCookie ( ctx , "access_token" , getAuthCookieSettings ( ctx ) ) ;
165- deleteCookie ( ctx , "refresh_token" , getAuthCookieSettings ( ctx ) ) ;
164+ deleteCookie ( ctx , "access_token" , getAuthCookieSettings ( ) ) ;
165+ deleteCookie ( ctx , "refresh_token" , getAuthCookieSettings ( ) ) ;
166166 } ,
167167
168168 async endAllSessionsForUser (
@@ -179,8 +179,8 @@ export function createCachedSessionService(
179179 await cache . del ( userSessionsKey ( userId ) ) ;
180180 }
181181
182- deleteCookie ( ctx , "access_token" , getAuthCookieSettings ( ctx ) ) ;
183- deleteCookie ( ctx , "refresh_token" , getAuthCookieSettings ( ctx ) ) ;
182+ deleteCookie ( ctx , "access_token" , getAuthCookieSettings ( ) ) ;
183+ deleteCookie ( ctx , "refresh_token" , getAuthCookieSettings ( ) ) ;
184184 } ,
185185 } ;
186186}
Original file line number Diff line number Diff line change @@ -309,8 +309,8 @@ export function createSessionService(
309309 args : [ sessionId ] ,
310310 } ) ;
311311
312- deleteCookie ( ctx , "access_token" , getAuthCookieSettings ( ctx ) ) ;
313- deleteCookie ( ctx , "refresh_token" , getAuthCookieSettings ( ctx ) ) ;
312+ deleteCookie ( ctx , "access_token" , getAuthCookieSettings ( ) ) ;
313+ deleteCookie ( ctx , "refresh_token" , getAuthCookieSettings ( ) ) ;
314314 } ,
315315
316316 async endAllSessionsForUser (
@@ -326,8 +326,8 @@ export function createSessionService(
326326 args : [ userId ] ,
327327 } ) ;
328328
329- deleteCookie ( ctx , "access_token" , getAuthCookieSettings ( ctx ) ) ;
330- deleteCookie ( ctx , "refresh_token" , getAuthCookieSettings ( ctx ) ) ;
329+ deleteCookie ( ctx , "access_token" , getAuthCookieSettings ( ) ) ;
330+ deleteCookie ( ctx , "refresh_token" , getAuthCookieSettings ( ) ) ;
331331 } ,
332332 } ;
333333}
Original file line number Diff line number Diff line change @@ -22,10 +22,9 @@ export function setSecureCookie(
2222 token : string ,
2323 maxAge : number ,
2424) : void {
25- const secure = ctx . env ?. ENVIRONMENT === "production" ;
2625 setCookie ( ctx , name , token , {
2726 httpOnly : true ,
28- secure,
27+ secure : tokenConfig . cookieSecure ,
2928 sameSite : tokenConfig . cookieSameSite ,
3029 path : "/" ,
3130 maxAge,
@@ -37,11 +36,10 @@ export function setSecureCookie(
3736 * Used with deleteCookie to ensure consistent security settings.
3837 * @returns Cookie options with security settings
3938 */
40- export function getAuthCookieSettings ( ctx ?: Context ) : CookieOptions {
41- const secure = ctx ?. env ?. ENVIRONMENT === "production" ;
39+ export function getAuthCookieSettings ( ) : CookieOptions {
4240 return {
4341 httpOnly : true ,
44- secure,
42+ secure : tokenConfig . cookieSecure ,
4543 sameSite : tokenConfig . cookieSameSite ,
4644 path : "/" ,
4745 } ;
Original file line number Diff line number Diff line change @@ -18,4 +18,5 @@ export interface Env {
1818 CACHE_TOKEN ?: string ;
1919 AGENT_PROVISIONING_SECRET ?: string ;
2020 WS_ALLOWED_ORIGINS ?: string ;
21+ ENVIRONMENT ?: string ;
2122}
You can’t perform that action at this time.
0 commit comments