Enhanced ChatGPT Clone: Features Agents, MCP, Skills, DeepSeek, Anthropic, AWS, OpenAI, Responses API, Azure, Groq, o1, GPT-5, Mistral, OpenRouter, Vertex AI, Gemini, Artifacts, AI model switching, message search, Code Interpreter, langchain, DALL-E-3, OpenAPI Actions, Functions, Secure Multi-User Auth, Presets, open-source for self-hosting. Active
TypeScript aianthropicartifactsawsazurechatgptchatgpt-cloneclaudeclonedeepseekgeminigooglegpt-5librechatmcpo1openairesponses-apivisionwebui
🍪 refactor: Secure Cookie Setting for Localhost OAuth Sessions (#11518)
Max Sanna8c6277a281a5
diff --git a/api/server/socialLogins.js b/api/server/socialLogins.jsindex bad64eee77..cf67fa9436 100644--- a/api/server/socialLogins.js+++ b/api/server/socialLogins.js@@ -15,6 +15,38 @@ const {} = require('~/strategies');const { getLogStores } = require('~/cache');+/**+ * Determines if secure cookies should be used.+ * Only use secure cookies in production when not on localhost.+ * @returns {boolean}+ */+function shouldUseSecureCookie() {+ const isProduction = process.env.NODE_ENV === 'production';+ const domainServer = process.env.DOMAIN_SERVER || '';++ let hostname = '';+ if (domainServer) {+ try {+ const normalized = /^https?:\/\//i.test(domainServer)+ ? domainServer+ : `http://${domainServer}`;+ const url = new URL(normalized);+ hostname = (url.hostname || '').toLowerCase();+ } catch {+ // Fallback: treat DOMAIN_SERVER directly as a hostname-like string+ hostname = domainServer.toLowerCase();+ }+ }++ const isLocalhost =+ hostname === 'localhost' ||+ hostname === '127.0.0.1' ||+ hostname === '::1' ||+ hostname.endsWith('.localhost');++ return isProduction && !isLocalhost;+}+/*** Configures OpenID Connect for the application.* @param {Express.Application} app - The Express application instance.@@ -22,7 +54,6 @@ const { getLogStores } = require('~/cache');*/async function configureOpenId(app) {logger.info('Configuring OpenID Connect...');- const isProduction = process.env.NODE_ENV === 'production';const sessionExpiry = Number(process.env.SESSION_EXPIRY) || DEFAULT_SESSION_EXPIRY;const sessionOptions = {secret: process.env.OPENID_SESSION_SECRET,@@ -31,7 +62,7 @@ async function configureOpenId(app) {store: getLogStores(CacheKeys.OPENID_SESSION),cookie: {maxAge: sessionExpiry,- secure: isProduction,+ secure: shouldUseSecureCookie(),},};app.use(session(sessionOptions));@@ -88,7 +119,6 @@ const configureSocialLogins = async (app) => {process.env.SAML_SESSION_SECRET) {logger.info('Configuring SAML Connect...');- const isProduction = process.env.NODE_ENV === 'production';const sessionExpiry = Number(process.env.SESSION_EXPIRY) || DEFAULT_SESSION_EXPIRY;const sessionOptions = {secret: process.env.SAML_SESSION_SECRET,@@ -97,7 +127,7 @@ const configureSocialLogins = async (app) => {store: getLogStores(CacheKeys.SAML_SESSION),cookie: {maxAge: sessionExpiry,- secure: isProduction,+ secure: shouldUseSecureCookie(),},};app.use(session(sessionOptions));