Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.
TypeScript acmeagentsai-agentscertificate-managementdevsecopsenvironment-variableskubernetesopen-sourcepampkipostgresprivate-caprivileged-access-managementsecret-managementsecret-managersecretssecrets-managementsecuritysecurity-toolsvault
conditionally set https
Maidul Islam83ddba29e2ad
diff --git a/backend/src/config/index.ts b/backend/src/config/index.tsindex 68427d078d..86b8db44e8 100644--- a/backend/src/config/index.ts+++ b/backend/src/config/index.ts@@ -48,4 +48,17 @@ export const getStripeSecretKey = () => infisical.get('STRIPE_SECRET_KEY')!;export const getStripeWebhookSecret = () => infisical.get('STRIPE_WEBHOOK_SECRET')!;export const getTelemetryEnabled = () => infisical.get('TELEMETRY_ENABLED')! !== 'false' && true;export const getLoopsApiKey = () => infisical.get('LOOPS_API_KEY')!;-export const getSmtpConfigured = () => infisical.get('SMTP_HOST') == '' || infisical.get('SMTP_HOST') == undefined ? false : true\ No newline at end of file+export const getSmtpConfigured = () => infisical.get('SMTP_HOST') == '' || infisical.get('SMTP_HOST') == undefined ? false : true+export const getHttpsEnabled = () => {+ if (getNodeEnv() != "production") {+ // no https for anything other than prod+ return false+ }++ if (infisical.get('HTTPS_ENABLED') == undefined || infisical.get('HTTPS_ENABLED') == "") {+ // default when no value present+ return true+ }++ return Boolean(infisical.get('HTTPS_ENABLED'))+}\ No newline at end of filediff --git a/backend/src/controllers/v1/authController.ts b/backend/src/controllers/v1/authController.tsindex 3c6ec523ad..84404bc74f 100644--- a/backend/src/controllers/v1/authController.ts+++ b/backend/src/controllers/v1/authController.ts@@ -15,10 +15,10 @@ import { BadRequestError } from '../../utils/errors';import { EELogService } from '../../ee/services';import { getChannelFromUserAgent } from '../../utils/posthog'; // TODO: move thisimport {- getNodeEnv,getJwtRefreshSecret,getJwtAuthLifetime,- getJwtAuthSecret+ getJwtAuthSecret,+ getHttpsEnabled} from '../../config';declare module 'jsonwebtoken' {@@ -126,21 +126,21 @@ export const login2 = async (req: Request, res: Response) => {httpOnly: true,path: '/',sameSite: 'strict',- secure: getNodeEnv() === 'production' ? true : false+ secure: getHttpsEnabled()});const loginAction = await EELogService.createAction({name: ACTION_LOGIN,userId: user._id});-+loginAction && await EELogService.createLog({userId: user._id,actions: [loginAction],channel: getChannelFromUserAgent(req.headers['user-agent']),ipAddress: req.ip});-+// return (access) token in responsereturn res.status(200).send({token: tokens.token,@@ -182,14 +182,14 @@ export const logout = async (req: Request, res: Response) => {httpOnly: true,path: '/',sameSite: 'strict',- secure: getNodeEnv() === 'production' ? true : false+ secure: getHttpsEnabled() as boolean});const logoutAction = await EELogService.createAction({name: ACTION_LOGOUT,userId: req.user._id});-+logoutAction && await EELogService.createLog({userId: req.user._id,actions: [logoutAction],diff --git a/backend/src/controllers/v2/authController.ts b/backend/src/controllers/v2/authController.tsindex 3a36d559cf..92b4a159ac 100644--- a/backend/src/controllers/v2/authController.ts+++ b/backend/src/controllers/v2/authController.ts@@ -17,9 +17,9 @@ import {} from '../../variables';import { getChannelFromUserAgent } from '../../utils/posthog'; // TODO: move thisimport {- getNodeEnv,getJwtMfaLifetime,- getJwtMfaSecret+ getJwtMfaSecret,+ getHttpsEnabled} from '../../config';declare module 'jsonwebtoken' {@@ -163,7 +163,7 @@ export const login2 = async (req: Request, res: Response) => {httpOnly: true,path: '/',sameSite: 'strict',- secure: getNodeEnv() === 'production' ? true : false+ secure: getHttpsEnabled()});// case: user does not have MFA enablgged@@ -302,7 +302,7 @@ export const verifyMfaToken = async (req: Request, res: Response) => {httpOnly: true,path: '/',sameSite: 'strict',- secure: getNodeEnv() === 'production' ? true : false+ secure: getHttpsEnabled()});interface VerifyMfaTokenRes {diff --git a/backend/src/controllers/v2/signupController.ts b/backend/src/controllers/v2/signupController.tsindex aaf055b78c..ff41aa0174 100644--- a/backend/src/controllers/v2/signupController.ts+++ b/backend/src/controllers/v2/signupController.ts@@ -8,7 +8,7 @@ import {import { issueAuthTokens } from '../../helpers/auth';import { INVITED, ACCEPTED } from '../../variables';import request from '../../config/request';-import { getNodeEnv, getLoopsApiKey } from '../../config';+import { getLoopsApiKey, getHttpsEnabled } from '../../config';/*** Complete setting up user by adding their personal and auth information as part of the@@ -24,9 +24,9 @@ export const completeAccountSignup = async (req: Request, res: Response) => {email,firstName,lastName,- protectedKey,- protectedKeyIV,- protectedKeyTag,+ protectedKey,+ protectedKeyIV,+ protectedKeyTag,publicKey,encryptedPrivateKey,encryptedPrivateKeyIV,@@ -38,9 +38,9 @@ export const completeAccountSignup = async (req: Request, res: Response) => {email: string;firstName: string;lastName: string;- protectedKey: string;- protectedKeyIV: string;- protectedKeyTag: string;+ protectedKey: string;+ protectedKeyIV: string;+ protectedKeyTag: string;publicKey: string;encryptedPrivateKey: string;encryptedPrivateKeyIV: string;@@ -48,11 +48,11 @@ export const completeAccountSignup = async (req: Request, res: Response) => {salt: string;verifier: string;organizationName: string;- } = req.body;+ } = req.body;// get useruser = await User.findOne({ email });-+if (!user || (user && user?.publicKey)) {// case 1: user doesn't exist.// case 2: user has already completed account@@ -66,10 +66,10 @@ export const completeAccountSignup = async (req: Request, res: Response) => {userId: user._id.toString(),firstName,lastName,- encryptionVersion: 2,- protectedKey,- protectedKeyIV,- protectedKeyTag,+ encryptionVersion: 2,+ protectedKey,+ protectedKeyIV,+ protectedKeyTag,publicKey,encryptedPrivateKey,encryptedPrivateKeyIV,@@ -127,7 +127,7 @@ export const completeAccountSignup = async (req: Request, res: Response) => {httpOnly: true,path: '/',sameSite: 'strict',- secure: getNodeEnv() === 'production' ? true : false+ secure: getHttpsEnabled()});} catch (err) {Sentry.setUser(null);@@ -158,9 +158,9 @@ export const completeAccountInvite = async (req: Request, res: Response) => {email,firstName,lastName,- protectedKey,- protectedKeyIV,- protectedKeyTag,+ protectedKey,+ protectedKeyIV,+ protectedKeyTag,publicKey,encryptedPrivateKey,encryptedPrivateKeyIV,@@ -192,10 +192,10 @@ export const completeAccountInvite = async (req: Request, res: Response) => {userId: user._id.toString(),firstName,lastName,- encryptionVersion: 2,- protectedKey,- protectedKeyIV,- protectedKeyTag,+ encryptionVersion: 2,+ protectedKey,+ protectedKeyIV,+ protectedKeyTag,publicKey,encryptedPrivateKey,encryptedPrivateKeyIV,@@ -232,7 +232,7 @@ export const completeAccountInvite = async (req: Request, res: Response) => {httpOnly: true,path: '/',sameSite: 'strict',- secure: getNodeEnv() === 'production' ? true : false+ secure: getHttpsEnabled()});} catch (err) {Sentry.setUser(null);@@ -241,7 +241,7 @@ export const completeAccountInvite = async (req: Request, res: Response) => {message: 'Failed to complete account setup'});}-+return res.status(200).send({message: 'Successfully set up account',user,