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
dont reset connection when mfa grant is changed
Thiago Araujo da Silvadaa3acf80257
diff --git a/backend/AGENTS.md b/backend/AGENTS.mdindex cd4552c05e..6b59da5f76 100644--- a/backend/AGENTS.md+++ b/backend/AGENTS.md@@ -328,6 +328,10 @@ through `isIdpMfaTrusted` (`auth-fns.ts`), the only reader of the setting. Rules(`mfa-step-up-fns.ts`) and PAM MFA are unaffected. OAuth consent (`authorizeConsent`) re-derives the MFArequirement for the client's org and applies the same `isIdpMfaTrusted` waiver, so a session that skippedthe login prompt is not refused when authorizing an application.+- Updating a SAML or OIDC config resets the org's `authEnforced` and `scimEnabled`, except when the update+ carries only the MFA signal fields (`mfaSignalAttribute` / `mfaAuthnContexts`, `mfaClaimName` /+ `mfaAmrValues`), which cannot break a login. The SSO modals send only those fields when nothing else changed,+ so tuning an allowlist on a live, enforced setup does not turn enforcement off.- The callback writes a `USER_LOGIN` audit event with the `idpMfa` verdict: `evidence` is what matched and`received` is every value the IdP sent in the fields that were read, so a rejected login shows which valueto add to the allowlist. `SELECT_ORGANIZATION` records `mfaSatisfiedBy`, so an admin can see why a login wasdiff --git a/backend/e2e-test/routes/v3/auth-idp.spec.ts b/backend/e2e-test/routes/v3/auth-idp.spec.tsindex 20010a5d12..f43e794f80 100644--- a/backend/e2e-test/routes/v3/auth-idp.spec.ts+++ b/backend/e2e-test/routes/v3/auth-idp.spec.ts@@ -5,7 +5,7 @@ import { Knex } from "knex";import { AccessScope, OrgMembershipRole, TableName } from "@app/db/schemas";import { seedData1 } from "@app/db/seed-data";-import { AuthMethod, ProviderAuthResult } from "@app/services/auth/auth-type";+import { ActorType, AuthMethod, ProviderAuthResult } from "@app/services/auth/auth-type";import { UserAliasType } from "@app/services/user-alias/user-alias-types";import { cleanupEmailDomains, seedVerifiedEmailDomain } from "../../testUtils/email-domains";@@ -125,6 +125,86 @@ describe("Auth IdP Service-Level Tests", () => {});});+ describe("SSO config updates", () => {+ const actor = {+ actor: ActorType.USER,+ actorId: seedData1.id,+ actorOrgId: TEST_ORG_ID,+ actorAuthMethod: AuthMethod.OKTA_SAML+ };++ const enforceSsoAndScim = () =>+ getDb()(TableName.Organization).where({ id: TEST_ORG_ID }).update({ authEnforced: true, scimEnabled: true });++ const orgFlags = () =>+ getDb()(TableName.Organization).where({ id: TEST_ORG_ID }).first("authEnforced", "scimEnabled");++ afterEach(async () => {+ await getDb()(TableName.SamlConfig).where({ orgId: TEST_ORG_ID }).del();+ await getDb()(TableName.OidcConfig).where({ orgId: TEST_ORG_ID }).del();+ await getDb()(TableName.Organization)+ .where({ id: TEST_ORG_ID })+ .update({ authEnforced: false, scimEnabled: false });+ });++ test("editing only the SAML MFA signal keeps SSO enforcement, SCIM and the active config", async () => {+ await getDb()(TableName.SamlConfig).insert({+ orgId: TEST_ORG_ID,+ authProvider: AuthMethod.OKTA_SAML,+ isActive: true,+ lastUsed: new Date(),+ encryptedSamlEntryPoint: Buffer.from("entry-point"),+ encryptedSamlIssuer: Buffer.from("issuer"),+ encryptedSamlCertificate: Buffer.from("cert")+ });+ await enforceSsoAndScim();++ await getServices().saml.updateSamlCfg({+ ...actor,+ orgId: TEST_ORG_ID,+ mfaSignalAttribute: "session_amr",+ mfaAuthnContexts: ["urn:example:mfa"]+ });++ expect(await orgFlags()).toEqual({ authEnforced: true, scimEnabled: true });+ const cfg = await getDb()(TableName.SamlConfig).where({ orgId: TEST_ORG_ID }).first();+ expect(cfg).toMatchObject({ isActive: true, mfaSignalAttribute: "session_amr" });+ expect(cfg?.lastUsed).not.toBeNull();++ await getServices().saml.updateSamlCfg({ ...actor, orgId: TEST_ORG_ID, isActive: false });++ expect(await orgFlags()).toEqual({ authEnforced: false, scimEnabled: false });+ });++ test("editing only the OIDC MFA signal keeps SSO enforcement and SCIM", async () => {+ await getDb()(TableName.OidcConfig).insert({+ orgId: TEST_ORG_ID,+ configurationType: "discoveryURL",+ isActive: true,+ lastUsed: new Date(),+ encryptedOidcClientId: Buffer.from("client-id"),+ encryptedOidcClientSecret: Buffer.from("client-secret")+ });+ await enforceSsoAndScim();++ await getServices().oidc.updateOidcCfg({+ ...actor,+ organizationId: TEST_ORG_ID,+ mfaClaimName: "acr",+ mfaAmrValues: ["phr"]+ });++ expect(await orgFlags()).toEqual({ authEnforced: true, scimEnabled: true });+ const cfg = await getDb()(TableName.OidcConfig).where({ orgId: TEST_ORG_ID }).first();+ expect(cfg).toMatchObject({ isActive: true, mfaClaimName: "acr", mfaAmrValues: ["phr"] });+ expect(cfg?.lastUsed).not.toBeNull();++ await getServices().oidc.updateOidcCfg({ ...actor, organizationId: TEST_ORG_ID, allowedEmailDomains: "" });++ expect(await orgFlags()).toEqual({ authEnforced: false, scimEnabled: false });+ });+ });+describe("SAML Login", () => {test("Creates new user + alias + membership as Invited", async () => {const externalId = `saml-ext-${crypto.randomUUID()}`;diff --git a/backend/src/ee/services/oidc/oidc-config-service.ts b/backend/src/ee/services/oidc/oidc-config-service.tsindex 37f5608383..ddceb44bf7 100644--- a/backend/src/ee/services/oidc/oidc-config-service.ts+++ b/backend/src/ee/services/oidc/oidc-config-service.ts@@ -695,6 +695,22 @@ export const oidcConfigServiceFactory = ({await blockLocalAndPrivateIpAddresses(userinfoEndpoint);}+ const isMfaSignalOnlyUpdate = [+ allowedEmailDomains,+ configurationType,+ discoveryURL,+ issuer,+ authorizationEndpoint,+ tokenEndpoint,+ userinfoEndpoint,+ jwksUri,+ isActive,+ clientId,+ clientSecret,+ manageGroupMemberships,+ jwtSignatureAlgorithm+ ].every((value) => value === undefined);+const updateQuery: TOidcConfigsUpdate = {allowedEmailDomains,configurationType,@@ -705,7 +721,7 @@ export const oidcConfigServiceFactory = ({userinfoEndpoint,jwksUri,isActive,- lastUsed: null,+ ...(!isMfaSignalOnlyUpdate && { lastUsed: null }),manageGroupMemberships,jwtSignatureAlgorithm,mfaClaimName,@@ -721,7 +737,9 @@ export const oidcConfigServiceFactory = ({}const [ssoConfig] = await oidcConfigDAL.update({ orgId: org.id }, updateQuery);- await orgDAL.updateById(org.id, { authEnforced: false, scimEnabled: false });+ if (!isMfaSignalOnlyUpdate) {+ await orgDAL.updateById(org.id, { authEnforced: false, scimEnabled: false });+ }recordSsoConfigChangeMetric({ provider: SsoProvider.Oidc, action: SsoConfigAction.Update, orgId: org.id });return ssoConfig;};diff --git a/backend/src/ee/services/saml-config/saml-config-service.ts b/backend/src/ee/services/saml-config/saml-config-service.tsindex 92d830d7cb..c0d73ef519 100644--- a/backend/src/ee/services/saml-config/saml-config-service.ts+++ b/backend/src/ee/services/saml-config/saml-config-service.ts@@ -422,10 +422,14 @@ export const samlConfigServiceFactory = ({});}+ const isMfaSignalOnlyUpdate = [authProvider, isActive, entryPoint, issuer, idpCert, enableGroupSync].every(+ (value) => value === undefined+ );+const updateQuery: TSamlConfigsUpdate = {authProvider,isActive,- lastUsed: null+ ...(!isMfaSignalOnlyUpdate && { lastUsed: null })};if (enableGroupSync !== undefined) {@@ -455,7 +459,9 @@ export const samlConfigServiceFactory = ({}const [ssoConfig] = await samlConfigDAL.update({ orgId }, updateQuery);- await orgDAL.updateById(orgId, { authEnforced: false, scimEnabled: false });+ if (!isMfaSignalOnlyUpdate) {+ await orgDAL.updateById(orgId, { authEnforced: false, scimEnabled: false });+ }recordSsoConfigChangeMetric({ provider: SsoProvider.Saml, action: SsoConfigAction.Update, orgId });diff --git a/frontend/src/pages/organization/SettingsPage/components/OrgSsoTab/OIDCModal.tsx b/frontend/src/pages/organization/SettingsPage/components/OrgSsoTab/OIDCModal.tsxindex 2d2e0f1525..831c7f4ba4 100644--- a/frontend/src/pages/organization/SettingsPage/components/OrgSsoTab/OIDCModal.tsx+++ b/frontend/src/pages/organization/SettingsPage/components/OrgSsoTab/OIDCModal.tsx@@ -220,6 +220,10 @@ export const OIDCModal = ({ popUp, handlePopUpClose, handlePopUpToggle, hideDele}: OIDCFormData) => {if (!currentOrg) return;+ const mfaSignal = {+ mfaClaimName,+ mfaAmrValues: mfaAmrValues && mfaAmrValues.length > 0 ? mfaAmrValues : null+ };const payload = {issuer,configurationType,@@ -233,10 +237,23 @@ export const OIDCModal = ({ popUp, handlePopUpClose, handlePopUpToggle, hideDeleisActive: true,organizationId: currentOrg.id,jwtSignatureAlgorithm,- mfaClaimName,- mfaAmrValues: mfaAmrValues && mfaAmrValues.length > 0 ? mfaAmrValues : null+ ...mfaSignal};+ const isConnectionUnchanged =+ data?.isActive &&+ !clientSecret &&+ configurationType === data.configurationType &&+ (issuer ?? "") === (data.issuer ?? "") &&+ (discoveryURL ?? "") === (data.discoveryURL ?? "") &&+ (authorizationEndpoint ?? "") === (data.authorizationEndpoint ?? "") &&+ (jwksUri ?? "") === (data.jwksUri ?? "") &&+ (tokenEndpoint ?? "") === (data.tokenEndpoint ?? "") &&+ (userinfoEndpoint ?? "") === (data.userinfoEndpoint ?? "") &&+ (allowedEmailDomains ?? "") === (data.allowedEmailDomains ?? "") &&+ clientId === data.clientId &&+ jwtSignatureAlgorithm === data.jwtSignatureAlgorithm;+// Switching providers keeps the row but blanks its secret, so an existing row is not proof one is stored.if (!hasStoredSecret && !clientSecret) {setError("clientSecret", { message: "Client Secret is required" });@@ -245,6 +262,8 @@ export const OIDCModal = ({ popUp, handlePopUpClose, handlePopUpToggle, hideDeleif (!data) {await createMutateAsync({ ...payload, clientSecret: clientSecret as string });+ } else if (isConnectionUnchanged) {+ await updateMutateAsync({ organizationId: currentOrg.id, ...mfaSignal });} else {await updateMutateAsync({ ...payload, ...(clientSecret ? { clientSecret } : {}) });}diff --git a/frontend/src/pages/organization/SettingsPage/components/OrgSsoTab/SSOModal.tsx b/frontend/src/pages/organization/SettingsPage/components/OrgSsoTab/SSOModal.tsxindex d26af2bc6f..d84c02dd6c 100644--- a/frontend/src/pages/organization/SettingsPage/components/OrgSsoTab/SSOModal.tsx+++ b/frontend/src/pages/organization/SettingsPage/components/OrgSsoTab/SSOModal.tsx@@ -248,6 +248,10 @@ export const SSOModal = ({ popUp, handlePopUpClose, handlePopUpToggle, hideDelet}: AddSSOFormData) => {if (!currentOrg) return;+ const mfaSignal = {+ mfaSignalAttribute,+ mfaAuthnContexts: mfaAuthnContexts.length > 0 ? mfaAuthnContexts : null+ };const payload = {organizationId: currentOrg.id,authProvider,@@ -255,12 +259,20 @@ export const SSOModal = ({ popUp, handlePopUpClose, handlePopUpToggle, hideDeletentryPoint,issuer,cert,- mfaSignalAttribute,- mfaAuthnContexts: mfaAuthnContexts.length > 0 ? mfaAuthnContexts : null+ ...mfaSignal};+ const isConnectionUnchanged =+ data?.isActive &&+ authProvider === data.authProvider &&+ entryPoint === data.entryPoint &&+ issuer === data.issuer &&+ cert === (data.cert ?? "");+if (!data) {await createMutateAsync(payload);+ } else if (isConnectionUnchanged) {+ await updateMutateAsync({ organizationId: currentOrg.id, ...mfaSignal });} else {await updateMutateAsync(payload);}