You've already forked joplin
mirror of
https://github.com/laurent22/joplin.git
synced 2025-11-23 22:36:32 +02:00
Server: Use "lax" cookies when using external authentication like SAML or LDAP
This commit is contained in:
@@ -163,6 +163,10 @@ function samlConfigFromEnv(env: EnvVariables): SamlConfig {
|
||||
}
|
||||
}
|
||||
|
||||
const isUsingExternalAuth = (env: EnvVariables) => {
|
||||
return !!env.SAML_ENABLED || !!env.LDAP_1_ENABLED || !!env.LDAP_2_ENABLED;
|
||||
};
|
||||
|
||||
let config_: Config = null;
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- Old code before rule was applied
|
||||
@@ -210,6 +214,12 @@ export async function initConfig(envType: Env, env: EnvVariables, overrides: any
|
||||
supportName: env.SUPPORT_NAME || appName,
|
||||
businessEmail: env.BUSINESS_EMAIL || supportEmail,
|
||||
cookieSecure: env.COOKIES_SECURE,
|
||||
|
||||
// We need "lax" when using external auth due to the redirects from the auth provider to
|
||||
// /api/saml, which then redirects to /home. And because the "origin" is going to be the
|
||||
// auth provider URL, the cookies won't be set property. "Lax" solves this and this is what
|
||||
// most web apps use these days. It is still reasonably secure.
|
||||
cookieSameSite: isUsingExternalAuth(env) ? 'lax' : true,
|
||||
storageDriver: parseStorageDriverConnectionString(env.STORAGE_DRIVER),
|
||||
storageDriverFallback: parseStorageDriverConnectionString(env.STORAGE_DRIVER_FALLBACK),
|
||||
itemSizeHardLimit: 250000000, // Beyond this the Postgres driver will crash the app
|
||||
|
||||
@@ -5,10 +5,8 @@ export function cookieSet(ctx: AppContext, name: string, value: string) {
|
||||
ctx.cookies.set(name, value, {
|
||||
// Means that the cookies cannot be accessed from JavaScript
|
||||
httpOnly: true,
|
||||
// Can only be transferred over https
|
||||
secure: config().cookieSecure,
|
||||
// Prevent cookies from being sent in cross-site requests
|
||||
sameSite: true,
|
||||
sameSite: config().cookieSameSite,
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -183,6 +183,7 @@ export interface Config extends EnvVariables {
|
||||
businessEmail: string;
|
||||
isJoplinCloud: boolean;
|
||||
cookieSecure: boolean;
|
||||
cookieSameSite: 'strict' | 'lax' | 'none' | boolean;
|
||||
storageDriver: StorageDriverConfig;
|
||||
storageDriverFallback: StorageDriverConfig;
|
||||
itemSizeHardLimit: number;
|
||||
|
||||
Reference in New Issue
Block a user