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
scope to org id
Thiago Araujo da Silvae6025ba770fb
diff --git a/backend/AGENTS.md b/backend/AGENTS.mdindex e0640115e3..4541976375 100644--- a/backend/AGENTS.md+++ b/backend/AGENTS.md@@ -305,13 +305,17 @@ per login with `matchIdpMfaSignal` (`services/auth/idp-mfa-signal.ts`): the OIDC`oidc_configs.mfaClaimName` contains `mfa`, the SAML `AuthnContextClassRef` is a two-factor class, or theattribute named by `saml_configs.mfaSignalAttribute` contains `mfa`. Both names default to `amr`, and theper-config allowlists extend the built-in values rather than replace them. The verdict travels on the org-less-session token as `idpMfaVerified`, and `selectOrganization` (`auth-login-service.ts`) applies it through-`isIdpMfaTrusted` (`auth-fns.ts`), the only reader of the setting. Rules that must hold:+session token as `idpMfaOrgId`, the root org whose SSO config produced it (absent when the IdP did not signal+MFA), and `selectOrganization` (`auth-login-service.ts`) applies it through `isIdpMfaTrusted` (`auth-fns.ts`),+the only reader of the setting. Rules that must hold:- Enforcement is decided once per selection against the root org (`actorRootOrgId`), so moving between a rootorg and its sub-orgs never re-prompts.- `isIdpMfaTrusted` refuses every non-SSO auth method, so password, Google and LDAP logins (break-glassaccounts) always get the Infisical challenge.+- The proof only counts for the root org whose IdP produced it. A user in two orgs could otherwise tune one+ org's allowlist to accept a single factor and carry that verdict into the other, so the token stores the org+ id rather than a boolean and selection requires it to equal the selected root org.- The trust only applies while `enforceMfa` is on. A user's own account-level MFA is still prompted. Thesetting can be stored before enforcement is turned on; `updateOrg` refuses any value but `none` only whilethe org has no active SAML or OIDC config.diff --git a/backend/e2e-test/routes/v3/auth-idp.spec.ts b/backend/e2e-test/routes/v3/auth-idp.spec.tsindex 93f2eb1d1d..f063293c6a 100644--- a/backend/e2e-test/routes/v3/auth-idp.spec.ts+++ b/backend/e2e-test/routes/v3/auth-idp.spec.ts@@ -94,9 +94,9 @@ describe("Auth IdP Service-Level Tests", () => {idpMfa});- expect(sessionClaims(await login({ verified: true, evidence: ["amr=mfa"] })).idpMfaVerified).toBe(true);- expect(sessionClaims(await login({ verified: false, evidence: [] })).idpMfaVerified).toBeUndefined();- expect(sessionClaims(await login()).idpMfaVerified).toBeUndefined();+ expect(sessionClaims(await login({ verified: true, evidence: ["amr=mfa"] })).idpMfaOrgId).toBe(TEST_ORG_ID);+ expect(sessionClaims(await login({ verified: false, evidence: [] })).idpMfaOrgId).toBeUndefined();+ expect(sessionClaims(await login()).idpMfaOrgId).toBeUndefined();});test("an OIDC login carries the verdict on its session, and only when the IdP signalled MFA", async () => {@@ -113,8 +113,8 @@ describe("Auth IdP Service-Level Tests", () => {idpMfa});- expect(sessionClaims(await login({ verified: true, evidence: ["mfa"] })).idpMfaVerified).toBe(true);- expect(sessionClaims(await login()).idpMfaVerified).toBeUndefined();+ expect(sessionClaims(await login({ verified: true, evidence: ["mfa"] })).idpMfaOrgId).toBe(TEST_ORG_ID);+ expect(sessionClaims(await login()).idpMfaOrgId).toBeUndefined();});});diff --git a/backend/e2e-test/routes/v3/auth-mfa.spec.ts b/backend/e2e-test/routes/v3/auth-mfa.spec.tsindex 53547d677d..a9ad646a50 100644--- a/backend/e2e-test/routes/v3/auth-mfa.spec.ts+++ b/backend/e2e-test/routes/v3/auth-mfa.spec.ts@@ -107,7 +107,7 @@ describe("Auth MFA V3", () => {const rootOrgId = seedData1.organization.id;let restoreLicense: () => void;- const signSsoSession = async (authMethod: AuthMethod, idpMfaVerified?: boolean) => {+ const signSsoSession = async (authMethod: AuthMethod, idpMfaOrgId?: string) => {const [session] = await db()(TableName.AuthTokenSession).insert({userId: seedData1.id,@@ -126,7 +126,7 @@ describe("Auth MFA V3", () => {userId: seedData1.id,tokenVersionId: session.id,accessVersion: 1,- ...(idpMfaVerified && { idpMfaVerified })+ ...(idpMfaOrgId && { idpMfaOrgId })},process.env.AUTH_SECRET as string,{ expiresIn: "1h" }@@ -158,10 +158,10 @@ describe("Auth MFA V3", () => {async (authMethod) => {await setSsoMfaTrust(SsoMfaTrust.Signal);- const { payload } = await selectOrg(await signSsoSession(authMethod, true), rootOrgId);+ const { payload } = await selectOrg(await signSsoSession(authMethod, rootOrgId), rootOrgId);expect(payload.isMfaEnabled).toBe(false);- expect(decode(payload.token)).toMatchObject({ organizationId: rootOrgId, idpMfaVerified: true });+ expect(decode(payload.token)).toMatchObject({ organizationId: rootOrgId, idpMfaOrgId: rootOrgId });});@@ -174,6 +174,41 @@ describe("Auth MFA V3", () => {expect(payload.mfaMethod).toBe(MfaMethod.EMAIL);});+ test("the root org's proof also covers its sub-organizations", async () => {+ await setSsoMfaTrust(SsoMfaTrust.Signal);+ const [subOrg] = await db()(TableName.Organization)+ .insert({+ name: `idp-mfa-${crypto.randomUUID()}`,+ slug: `idp-mfa-${crypto.randomUUID()}`,+ rootOrgId,+ parentOrgId: rootOrgId,+ enforceMfa: true+ })+ .returning("*");+ try {+ await addUserMembership({ userId: seedData1.id, orgId: subOrg.id, role: OrgMembershipRole.Member });++ const { payload } = await selectOrg(await signSsoSession(AuthMethod.OKTA_SAML, rootOrgId), subOrg.id);++ expect(payload.isMfaEnabled).toBe(false);+ expect(decode(payload.token)).toMatchObject({+ organizationId: rootOrgId,+ subOrganizationId: subOrg.id,+ idpMfaOrgId: rootOrgId+ });+ } finally {+ await db()(TableName.Organization).where({ id: subOrg.id }).del();+ }+ });++ test("a proof produced by another organization's IdP still gets the prompt", async () => {+ await setSsoMfaTrust(SsoMfaTrust.Signal);++ const { payload } = await selectOrg(await signSsoSession(AuthMethod.OKTA_SAML, crypto.randomUUID()), rootOrgId);++ expect(payload.isMfaEnabled).toBe(true);+ });+test("a password session on the same org still gets the prompt", async () => {await setSsoMfaTrust(SsoMfaTrust.Signal);const { accessToken } = await loginUser(seedData1.email, seedData1.password);@@ -186,7 +221,7 @@ describe("Auth MFA V3", () => {test("the signal is ignored while the org requires Infisical MFA", async () => {await setSsoMfaTrust(SsoMfaTrust.None);- const { payload } = await selectOrg(await signSsoSession(AuthMethod.OKTA_SAML, true), rootOrgId);+ const { payload } = await selectOrg(await signSsoSession(AuthMethod.OKTA_SAML, rootOrgId), rootOrgId);expect(payload.isMfaEnabled).toBe(true);});@@ -203,7 +238,7 @@ describe("Auth MFA V3", () => {await db()(TableName.Organization).where({ id: rootOrgId }).update({ enforceMfa: false });await db()(TableName.Users).where({ id: seedData1.id }).update({ isMfaEnabled: true });try {- const { payload } = await selectOrg(await signSsoSession(AuthMethod.OKTA_SAML, true), rootOrgId);+ const { payload } = await selectOrg(await signSsoSession(AuthMethod.OKTA_SAML, rootOrgId), rootOrgId);expect(payload.isMfaEnabled).toBe(true);} finally {diff --git a/backend/src/server/plugins/auth/inject-identity.ts b/backend/src/server/plugins/auth/inject-identity.tsindex 49d73a1b03..fc45333350 100644--- a/backend/src/server/plugins/auth/inject-identity.ts+++ b/backend/src/server/plugins/auth/inject-identity.ts@@ -40,7 +40,7 @@ export type TAuthMode =authMethod: AuthMethod;isMfaVerified?: boolean;mfaMethod?: MfaMethod;- idpMfaVerified?: boolean;+ idpMfaOrgId?: string;oauthClientId?: string;token: AuthModeJwtTokenPayload;}@@ -340,7 +340,7 @@ export const injectIdentity = fp(isMfaVerified: token.isMfaVerified,token,mfaMethod: token.mfaMethod,- idpMfaVerified: token.idpMfaVerified+ idpMfaOrgId: token.idpMfaOrgId};fireIdentifyForUser(user);break;diff --git a/backend/src/server/routes/v1/auth-router.ts b/backend/src/server/routes/v1/auth-router.tsindex 999ffc3e3f..05f384f678 100644--- a/backend/src/server/routes/v1/auth-router.ts+++ b/backend/src/server/routes/v1/auth-router.ts@@ -155,7 +155,7 @@ export const registerAuthRoutes = async (server: FastifyZodProvider) => {...(decodedToken.subOrganizationId && { subOrganizationId: decodedToken.subOrganizationId }),isMfaVerified: decodedToken.isMfaVerified,mfaMethod: decodedToken.mfaMethod,- idpMfaVerified: decodedToken.idpMfaVerified+ idpMfaOrgId: decodedToken.idpMfaOrgId},appCfg.AUTH_SECRET,{ expiresIn }diff --git a/backend/src/server/routes/v3/login-router.ts b/backend/src/server/routes/v3/login-router.tsindex 641c53a439..98972c416e 100644--- a/backend/src/server/routes/v3/login-router.ts+++ b/backend/src/server/routes/v3/login-router.ts@@ -79,7 +79,7 @@ export const registerLoginRouter = async (server: FastifyZodProvider) => {actorRootOrgId: req.auth.rootOrgId,isMfaVerified: req.auth.isMfaVerified,mfaMethod: req.auth.mfaMethod,- idpMfaVerified: req.auth.idpMfaVerified+ idpMfaOrgId: req.auth.idpMfaOrgId});if (tokens.isMfaEnabled) {diff --git a/backend/src/services/auth-token/auth-token-service.ts b/backend/src/services/auth-token/auth-token-service.tsindex 60afc10768..244f3829db 100644--- a/backend/src/services/auth-token/auth-token-service.ts+++ b/backend/src/services/auth-token/auth-token-service.ts@@ -350,7 +350,7 @@ export const tokenServiceFactory = ({ tokenDAL, userDAL, orgDAL, keyStore }: TAu...(decodedToken.subOrganizationId && { subOrganizationId: decodedToken.subOrganizationId }),isMfaVerified: decodedToken.isMfaVerified,mfaMethod: decodedToken.mfaMethod,- idpMfaVerified: decodedToken.idpMfaVerified+ idpMfaOrgId: decodedToken.idpMfaOrgId},appCfg.AUTH_SECRET,{ expiresIn: refreshTokenExpiresIn }diff --git a/backend/src/services/auth/auth-fns.test.ts b/backend/src/services/auth/auth-fns.test.tsindex 979f6ada86..2efa9d6375 100644--- a/backend/src/services/auth/auth-fns.test.ts+++ b/backend/src/services/auth/auth-fns.test.ts@@ -15,16 +15,24 @@ describe("OAuth login method policy", () => {[AuthMethod.GITLAB, LoginMethod.GITLAB]] as const)("allows %s when it is enabled", (authMethod, loginMethod) => {expect(isOAuthLoginMethodDisabled(authMethod, [loginMethod])).toBe(false);- expect(() => assertOAuthLoginMethodEnabled({ authMethod, enabledLoginMethods: [loginMethod] })).not.toThrow();+ expect(() =>+ assertOAuthLoginMethodEnabled({+ authMethod,+ enabledLoginMethods: [loginMethod]+ })+ ).not.toThrow();});test.each([AuthMethod.GOOGLE, AuthMethod.GITHUB, AuthMethod.GITLAB] as const)("rejects disabled %s login before a user exists",(authMethod) => {expect(isOAuthLoginMethodDisabled(authMethod, [LoginMethod.EMAIL])).toBe(true);- expect(() => assertOAuthLoginMethodEnabled({ authMethod, enabledLoginMethods: [LoginMethod.EMAIL] })).toThrow(- /disabled by administrator/- );+ expect(() =>+ assertOAuthLoginMethodEnabled({+ authMethod,+ enabledLoginMethods: [LoginMethod.EMAIL]+ })+ ).toThrow(/disabled by administrator/);});@@ -40,7 +48,10 @@ describe("OAuth login method policy", () => {test("treats an unset allowlist as all methods enabled", () => {expect(() =>- assertOAuthLoginMethodEnabled({ authMethod: AuthMethod.GOOGLE, enabledLoginMethods: null })+ assertOAuthLoginMethodEnabled({+ authMethod: AuthMethod.GOOGLE,+ enabledLoginMethods: null+ })).not.toThrow();});});@@ -65,28 +76,65 @@ describe("isMfaProofAccepted", () => {});describe("isIdpMfaTrusted", () => {+ const rootOrgId = "org-a";+test.each([AuthMethod.OKTA_SAML, AuthMethod.AZURE_SAML, AuthMethod.OIDC] as const)("trusts a signalled %s login when the org trusts the signal",(authMethod) => {- expect(isIdpMfaTrusted({ ssoMfaTrust: SsoMfaTrust.Signal, authMethod, idpMfaVerified: true })).toBe(true);+ expect(+ isIdpMfaTrusted({+ ssoMfaTrust: SsoMfaTrust.Signal,+ authMethod,+ rootOrgId,+ idpMfaOrgId: rootOrgId+ })+ ).toBe(true);});test("never trusts a login that carried no signal", () => {- expect(isIdpMfaTrusted({ ssoMfaTrust: SsoMfaTrust.Signal, authMethod: AuthMethod.OKTA_SAML })).toBe(false);expect(- isIdpMfaTrusted({ ssoMfaTrust: SsoMfaTrust.Signal, authMethod: AuthMethod.OIDC, idpMfaVerified: false })+ isIdpMfaTrusted({+ ssoMfaTrust: SsoMfaTrust.Signal,+ authMethod: AuthMethod.OKTA_SAML,+ rootOrgId+ })+ ).toBe(false);+ });++ test("never trusts a signal produced by another organization's IdP", () => {+ expect(+ isIdpMfaTrusted({+ ssoMfaTrust: SsoMfaTrust.Signal,+ authMethod: AuthMethod.OIDC,+ rootOrgId,+ idpMfaOrgId: "org-b"+ })).toBe(false);});test.each([AuthMethod.EMAIL, AuthMethod.GOOGLE, AuthMethod.GITHUB, AuthMethod.LDAP] as const)("never trusts a %s login, so break-glass accounts keep the Infisical challenge",(authMethod) => {- expect(isIdpMfaTrusted({ ssoMfaTrust: SsoMfaTrust.Signal, authMethod, idpMfaVerified: true })).toBe(false);+ expect(+ isIdpMfaTrusted({+ ssoMfaTrust: SsoMfaTrust.Signal,+ authMethod,+ rootOrgId,+ idpMfaOrgId: rootOrgId+ })+ ).toBe(false);});test.each([SsoMfaTrust.None, undefined, null, "delegate"])("ignores the signal when the setting is %s", (mode) => {- expect(isIdpMfaTrusted({ ssoMfaTrust: mode, authMethod: AuthMethod.OIDC, idpMfaVerified: true })).toBe(false);+ expect(+ isIdpMfaTrusted({+ ssoMfaTrust: mode,+ authMethod: AuthMethod.OIDC,+ rootOrgId,+ idpMfaOrgId: rootOrgId+ })+ ).toBe(false);});});diff --git a/backend/src/services/auth/auth-fns.ts b/backend/src/services/auth/auth-fns.tsindex f4315e7143..59a72090ec 100644--- a/backend/src/services/auth/auth-fns.ts+++ b/backend/src/services/auth/auth-fns.ts@@ -74,18 +74,21 @@ export const getRequiredMfaMethod = (};// Only SAML and OIDC carry a signed IdP signal. Password, Google and LDAP never qualify, so break-glass-// accounts always get the Infisical challenge.+// accounts always get the Infisical challenge. The proof names the org whose IdP produced it: a user in two+// orgs could otherwise tune one org's allowlist to accept a single factor and carry that verdict into the other.export const isIdpMfaTrusted = ({ssoMfaTrust,authMethod,- idpMfaVerified+ rootOrgId,+ idpMfaOrgId}: {ssoMfaTrust?: string | null;authMethod: AuthMethod;- idpMfaVerified?: boolean;+ rootOrgId: string;+ idpMfaOrgId?: string;}): boolean => {if (!isAuthMethodSaml(authMethod) && authMethod !== AuthMethod.OIDC) return false;- return ssoMfaTrust === SsoMfaTrust.Signal && Boolean(idpMfaVerified);+ return ssoMfaTrust === SsoMfaTrust.Signal && idpMfaOrgId === rootOrgId;};export const RECOVERY_CODE_MFA_ASSURANCE = "recovery-code";@@ -96,11 +99,15 @@ export const isMfaProofAccepted = (proven: string | null | undefined, acceptedMeexport const extractBearerToken = (token?: string): string => {if (!token) {- throw new UnauthorizedError({ message: "Missing Authorization Header in the request header." });+ throw new UnauthorizedError({+ message: "Missing Authorization Header in the request header."+ });}const [authTokenType, authTokenValue] = token.split(" ", 2) as [string, string];if (!authTokenType) {- throw new UnauthorizedError({ message: "Missing Authorization Header in the request header." });+ throw new UnauthorizedError({+ message: "Missing Authorization Header in the request header."+ });}if (authTokenType.toLowerCase() !== "bearer") {throw new UnauthorizedError({diff --git a/backend/src/services/auth/auth-login-service.ts b/backend/src/services/auth/auth-login-service.tsindex 97bc6aa7b0..54dda8bb51 100644--- a/backend/src/services/auth/auth-login-service.ts+++ b/backend/src/services/auth/auth-login-service.ts@@ -190,14 +190,14 @@ export const authLoginServiceFactory = ({authMethod,organizationId,requiredMfaMethod,- idpMfaVerified+ idpMfaOrgId}: {userId: string;email?: string | null;authMethod: AuthMethod;organizationId?: string;requiredMfaMethod: MfaMethod;- idpMfaVerified?: boolean;+ idpMfaOrgId?: string;}) => {const appCfg = getConfig();@@ -209,7 +209,7 @@ export const authLoginServiceFactory = ({organizationId,email,requiredMfaMethod,- idpMfaVerified+ idpMfaOrgId},appCfg.AUTH_SECRET,{ expiresIn: appCfg.JWT_MFA_LIFETIME }@@ -238,7 +238,7 @@ export const authLoginServiceFactory = ({authMethod,isMfaVerified,mfaMethod,- idpMfaVerified+ idpMfaOrgId}: {userId: string;ip: string;@@ -248,7 +248,7 @@ export const authLoginServiceFactory = ({authMethod: AuthMethod;isMfaVerified?: boolean;mfaMethod?: MfaMethod;- idpMfaVerified?: boolean;+ idpMfaOrgId?: string;},tx?: Knex) => {@@ -297,7 +297,7 @@ export const authLoginServiceFactory = ({subOrganizationId,isMfaVerified,mfaMethod,- idpMfaVerified+ idpMfaOrgId},cfg.AUTH_SECRET,{ expiresIn: tokenSessionExpiresIn }@@ -314,7 +314,7 @@ export const authLoginServiceFactory = ({subOrganizationId,isMfaVerified,mfaMethod,- idpMfaVerified+ idpMfaOrgId},cfg.AUTH_SECRET,{ expiresIn: refreshTokenExpiresIn }@@ -363,7 +363,7 @@ export const authLoginServiceFactory = ({ip,userAgent,authMethod,- idpMfaVerified: idpMfa?.verified || undefined+ idpMfaOrgId: idpMfa?.verified ? organizationId : undefined});if (organizationId) {@@ -775,7 +775,7 @@ export const authLoginServiceFactory = ({authMethod: decodedToken.authMethod,isMfaVerified: true,mfaMethod,- idpMfaVerified: decodedToken.idpMfaVerified+ idpMfaOrgId: decodedToken.idpMfaOrgId});// Open the grace window for THIS session only (the one that just proved MFA), so@@ -1192,7 +1192,7 @@ export const authLoginServiceFactory = ({actorRootOrgId,isMfaVerified,mfaMethod,- idpMfaVerified+ idpMfaOrgId}: {userAgent: string | undefined;ipAddress: string;@@ -1202,7 +1202,7 @@ export const authLoginServiceFactory = ({actorRootOrgId?: string;isMfaVerified?: boolean;mfaMethod?: MfaMethod;- idpMfaVerified?: boolean;+ idpMfaOrgId?: string;}) => {const cfg = getConfig();if (!userAgent) throw new UnauthorizedError({ name: "User-Agent header is required" });@@ -1336,7 +1336,8 @@ export const authLoginServiceFactory = ({isIdpMfaTrusted({ssoMfaTrust: rootOrg.ssoMfaTrust,authMethod: userAuthMethod,- idpMfaVerified+ rootOrgId: rootOrg.id,+ idpMfaOrgId});const shouldTriggerMfa =isMfaRequired && !isMfaSatisfiedByIdp && (!isMfaVerified || hasMfaMethodChanged || hasOrganizationChanged);@@ -1350,7 +1351,7 @@ export const authLoginServiceFactory = ({authMethod: userAuthMethod,requiredMfaMethod,organizationId: rootOrg.id,- idpMfaVerified+ idpMfaOrgId});return { isMfaEnabled: true, mfa: mfaToken, mfaMethod: requiredMfaMethod } as const;@@ -1367,7 +1368,7 @@ export const authLoginServiceFactory = ({subOrganizationId: isSubOrganization ? organizationId : undefined,isMfaVerified,mfaMethod,- idpMfaVerified+ idpMfaOrgId});let mfaSatisfiedBy: "not-required" | "infisical" | "idp" = "infisical";diff --git a/backend/src/services/auth/auth-type.ts b/backend/src/services/auth/auth-type.tsindex d5ced74aa1..d0f0b07922 100644--- a/backend/src/services/auth/auth-type.ts+++ b/backend/src/services/auth/auth-type.ts@@ -118,7 +118,7 @@ export type AuthModeJwtTokenPayload = {subOrganizationId?: string;isMfaVerified?: boolean;mfaMethod?: MfaMethod;- idpMfaVerified?: boolean;+ idpMfaOrgId?: string;// Present only on delegated OAuth 2.0 access tokens. Its presence marks the token as// AuthMode.OAUTH so the default JWT middleware will not accept it as a first-party session.oauthClientId?: string;@@ -136,7 +136,7 @@ export type AuthModeMfaJwtTokenPayload = {userId: string;organizationId?: string;requiredMfaMethod: MfaMethod;- idpMfaVerified?: boolean;+ idpMfaOrgId?: string;};export type AuthModeRefreshJwtTokenPayload = {@@ -150,7 +150,7 @@ export type AuthModeRefreshJwtTokenPayload = {subOrganizationId?: string;isMfaVerified?: boolean;mfaMethod?: MfaMethod;- idpMfaVerified?: boolean;+ idpMfaOrgId?: string;oauthClientId?: string;scopes?: string[];};