Skip to content

Commit 34aa6da

Browse files
committed
fix: wire cookieSecure in app.ts, revert core changes
1 parent d1cbf63 commit 34aa6da

6 files changed

Lines changed: 17 additions & 14 deletions

File tree

apps/cloudflare-workers/src/app.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import {
1515
defaultGetClientIp,
1616
type RateLimitConfig,
1717
securityHeaders,
18+
tokenConfig,
1819
} from "@private-landing/core";
1920
import {
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+
});
135140
app.use("*", securityHeaders);
136141
app.use("*", serveStatic({ cache: "key" }));
137142

packages/control/src/types.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
import type { Env, Variables } from "@private-landing/types";
1010

1111
export interface ControlBindings extends Env {
12-
ENVIRONMENT?: string;
1312
GATEWAY_URL?: string;
1413
GATEWAY_TOKEN?: string;
1514
CONTROL_ALLOWED_IPS?: string;

packages/core/src/auth/services/cached-session-service.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff 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
}

packages/core/src/auth/services/session-service.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff 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
}

packages/core/src/auth/utils/cookie.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff 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
};

packages/types/src/env.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff 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
}

0 commit comments

Comments
 (0)