Skip to content

Commit b5a8b8c

Browse files
committed
Restore 3rd party session cookies for localhost (for Chromium & FF)
Partially reverts f292865 We want to allow 3rd party cookies (aka SameSite=none && Secured). FF & Chromium have exceptions that allow `Secured` to work with `localhost`. This restores that support when running locally. One example of this is https://studio.apollographql.com/sandbox That is hosted by a 3rd party and points to our localhost. We also want the UI to actually work. Safari does not have this exception. So when trying to establish a session in Safari, the set-cookie header is ignored because it had the Secured requirement, and we were loading it over http (localhost). So now we allow 3rd party cookies, except for Safari/localhost combo.
1 parent 421140f commit b5a8b8c

File tree

3 files changed

+14
-9
lines changed

3 files changed

+14
-9
lines changed

src/components/authentication/session.interceptor.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ export class SessionInterceptor implements NestInterceptor {
9797
}
9898

9999
private getTokenFromCookie(req: IRequest | undefined): string | null {
100-
return req?.cookies?.[this.config.sessionCookie.name] || null;
100+
return req?.cookies?.[this.config.sessionCookie(req).name] || null;
101101
}
102102

103103
getImpersonateeFromContext(

src/components/authentication/session.resolver.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,9 @@ export class SessionResolver {
7272
const userFromSession = session.anonymous ? undefined : session.userId;
7373

7474
if (browser) {
75-
const { name, expires, ...options } = this.config.sessionCookie;
75+
const { name, expires, ...options } = this.config.sessionCookie(
76+
context.request!,
77+
);
7678
if (!context.response) {
7779
throw new ServerException(
7880
'Cannot use cookie session without a response object',

src/core/config/config.service.ts

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import { ProgressReportStatus } from '../../components/progress-report/dto/progr
1717
import type { TransitionName as ProgressReportTransitionName } from '../../components/progress-report/workflow/transitions';
1818
import { DefaultTimezoneWrapper } from '../email/templates/formatted-date-time';
1919
import { FrontendUrlWrapper } from '../email/templates/frontend-url';
20-
import type { CookieOptions, CorsOptions } from '../http';
20+
import type { CookieOptions, CorsOptions, IRequest } from '../http';
2121
import { LogLevel } from '../logger/logger.interface';
2222
import { EnvironmentService } from './environment.service';
2323
import { determineRootUser } from './root-user.config';
@@ -248,10 +248,9 @@ export const makeConfig = (env: EnvironmentService) =>
248248
} satisfies CorsOptions;
249249
})();
250250

251-
sessionCookie = ((): Merge<
252-
CookieOptions,
253-
{ name: string; expires?: DurationLike }
254-
> => {
251+
sessionCookie = (
252+
req: IRequest,
253+
): Merge<CookieOptions, { name: string; expires?: DurationLike }> => {
255254
const name = env.string('SESSION_COOKIE_NAME').optional('cordsession');
256255

257256
let domain = env.string('SESSION_COOKIE_DOMAIN').optional();
@@ -261,6 +260,10 @@ export const makeConfig = (env: EnvironmentService) =>
261260
domain = '.' + domain;
262261
}
263262

263+
const userAgent = req.headers['user-agent'];
264+
const isSafari =
265+
userAgent && /^((?!chrome|android).)*safari/i.test(userAgent);
266+
264267
return {
265268
name,
266269
domain,
@@ -270,14 +273,14 @@ export const makeConfig = (env: EnvironmentService) =>
270273
httpOnly: true,
271274
// All paths, not just the current one
272275
path: '/',
273-
...(!isDev && {
276+
...(!(isSafari && isDev) && {
274277
// Require HTTPS (required for SameSite)
275278
secure: true,
276279
// Allow 3rd party (other domains)
277280
sameSite: 'none',
278281
}),
279282
};
280-
})();
283+
};
281284

282285
xray = {
283286
daemonAddress: this.jest

0 commit comments

Comments
 (0)