Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable CHIPS - partitioned auth cookie for 3rd party use #3258

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/components/authentication/session.interceptor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ export class SessionInterceptor implements NestInterceptor {
}

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

getImpersonateeFromContext(
Expand Down
4 changes: 3 additions & 1 deletion src/components/authentication/session.resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,9 @@ export class SessionResolver {
const userFromSession = session.anonymous ? undefined : session.userId;

if (browser) {
const { name, expires, ...options } = this.config.sessionCookie;
const { name, expires, ...options } = this.config.sessionCookie(
context.request!,
);
if (!context.response) {
throw new ServerException(
'Cannot use cookie session without a response object',
Expand Down
20 changes: 13 additions & 7 deletions src/core/config/config.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { ProgressReportStatus } from '../../components/progress-report/dto/progr
import type { TransitionName as ProgressReportTransitionName } from '../../components/progress-report/workflow/transitions';
import { DefaultTimezoneWrapper } from '../email/templates/formatted-date-time';
import { FrontendUrlWrapper } from '../email/templates/frontend-url';
import type { CookieOptions, CorsOptions } from '../http';
import type { CookieOptions, CorsOptions, IRequest } from '../http';
import { LogLevel } from '../logger/logger.interface';
import { EnvironmentService } from './environment.service';
import { determineRootUser } from './root-user.config';
Expand Down Expand Up @@ -248,10 +248,9 @@ export const makeConfig = (env: EnvironmentService) =>
} satisfies CorsOptions;
})();

sessionCookie = ((): Merge<
CookieOptions,
{ name: string; expires?: DurationLike }
> => {
sessionCookie = (
req: IRequest,
): Merge<CookieOptions, { name: string; expires?: DurationLike }> => {
const name = env.string('SESSION_COOKIE_NAME').optional('cordsession');

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

const userAgent = req.headers['user-agent'];
const isSafari =
userAgent && /^((?!chrome|android).)*safari/i.test(userAgent);

return {
name,
domain,
Expand All @@ -270,14 +273,17 @@ export const makeConfig = (env: EnvironmentService) =>
httpOnly: true,
// All paths, not just the current one
path: '/',
...(!isDev && {
...(!(isSafari && isDev) && {
// Require HTTPS (required for SameSite)
secure: true,
// Allow 3rd party (other domains)
sameSite: 'none',
// Don't share cookie value between top level domains.
// Required for 3rd party use.
partitioned: true,
}),
};
})();
};

xray = {
daemonAddress: this.jest
Expand Down
Loading