Skip to content

Commit

Permalink
feat: Allow configurable cookie SameSite header (#3001)
Browse files Browse the repository at this point in the history
* Allow configurable cookie SameSite header
  • Loading branch information
lengyel-arpad85 authored Sep 27, 2024
1 parent 701bdf4 commit a45d56e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
2 changes: 2 additions & 0 deletions packages/auth/src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -345,12 +345,14 @@ export class App {

const redis = await this.container.use('redis')
const maxAgeMs = this.config.interactionExpirySeconds * 1000
const interactionSameSite = this.config.interactionCookieSameSite
koa.use(
session(
{
key: 'sessionId',
maxAge: maxAgeMs,
signed: true,
sameSite: interactionSameSite,
store: {
async get(key) {
const s = await redis.get(key)
Expand Down
16 changes: 16 additions & 0 deletions packages/auth/src/config/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,17 @@ function envBool(name: string, value: boolean): boolean {
const envValue = process.env[name]
return envValue == null ? value : envValue === 'true'
}
function envEnum<T extends string>(
name: string,
allowedValues: T[],
defaultValue: T | undefined
): T | undefined {
const envValue = process.env[name]
if (envValue && allowedValues.includes(envValue as T)) {
return envValue as T
}
return defaultValue
}
export type IAppConfig = typeof Config

dotenv.config({
Expand Down Expand Up @@ -50,6 +61,11 @@ export const Config = {
adminApiSignatureTtl: envInt('ADMIN_API_SIGNATURE_TTL_SECONDS', 30),
waitTimeSeconds: envInt('WAIT_SECONDS', 5),
cookieKey: envString('COOKIE_KEY'),
interactionCookieSameSite: envEnum(
'INTERACTION_COOKIE_SAME_SITE',
['lax', 'none'],
undefined
),
interactionExpirySeconds: envInt('INTERACTION_EXPIRY_SECONDS', 10 * 60), // Default 10 minutes
accessTokenExpirySeconds: envInt('ACCESS_TOKEN_EXPIRY_SECONDS', 10 * 60), // Default 10 minutes
databaseCleanupWorkers: envInt('DATABASE_CLEANUP_WORKERS', 1),
Expand Down

0 comments on commit a45d56e

Please sign in to comment.