From 615d0390d5ed4f15b6e89dbb0e9ee0cee4135019 Mon Sep 17 00:00:00 2001 From: Rory Powell Date: Wed, 6 Oct 2021 16:50:15 +0100 Subject: [PATCH] Honour cookie domain when custom sso is enabled --- packages/worker/src/api/controllers/global/auth.js | 12 +++++++++--- packages/worker/src/environment.js | 1 + 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/packages/worker/src/api/controllers/global/auth.js b/packages/worker/src/api/controllers/global/auth.js index f3188d7777..4e5603b596 100644 --- a/packages/worker/src/api/controllers/global/auth.js +++ b/packages/worker/src/api/controllers/global/auth.js @@ -41,13 +41,19 @@ async function authInternal(ctx, user, err = null, info = null) { return ctx.throw(403, info ? info : "Unauthorized") } - // just store the user ID - ctx.cookies.set(Cookies.Auth, user.token, { + const config = { expires, path: "/", httpOnly: false, overwrite: true, - }) + } + + if (env.COOKIE_DOMAIN) { + config.domain = env.COOKIE_DOMAIN + } + + // just store the user ID + ctx.cookies.set(Cookies.Auth, user.token, config) } exports.authenticate = async (ctx, next) => { diff --git a/packages/worker/src/environment.js b/packages/worker/src/environment.js index 0ef83a327e..74bd40314c 100644 --- a/packages/worker/src/environment.js +++ b/packages/worker/src/environment.js @@ -41,6 +41,7 @@ module.exports = { SMTP_PORT: process.env.SMTP_PORT, SMTP_FROM_ADDRESS: process.env.SMTP_FROM_ADDRESS, PLATFORM_URL: process.env.PLATFORM_URL, + COOKIE_DOMAIN: process.env.COOKIE_DOMAIN, _set(key, value) { process.env[key] = value module.exports[key] = value