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
save received values to audit log
Thiago Araujo da Silva608ac03e40d5
diff --git a/backend/AGENTS.md b/backend/AGENTS.mdindex 56ba594174..ca53b77b5b 100644--- a/backend/AGENTS.md+++ b/backend/AGENTS.md@@ -327,8 +327,10 @@ the only reader of the setting. Rules that must hold:(`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.-- The callback writes a `USER_LOGIN` audit event with the raw `idpMfa` evidence, and `SELECT_ORGANIZATION`- records `mfaSatisfiedBy`, so an admin can see why a login was or wasn't prompted.+- 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 value+ to add to the allowlist. `SELECT_ORGANIZATION` records `mfaSatisfiedBy`, so an admin can see why a login was+ or wasn't prompted.#### Delegated OAuth tokensdiff --git a/backend/e2e-test/routes/v3/auth-idp.spec.ts b/backend/e2e-test/routes/v3/auth-idp.spec.tsindex f063293c6a..20010a5d12 100644--- a/backend/e2e-test/routes/v3/auth-idp.spec.ts+++ b/backend/e2e-test/routes/v3/auth-idp.spec.ts@@ -81,7 +81,7 @@ describe("Auth IdP Service-Level Tests", () => {test("a SAML login carries the verdict on its session, and only when the IdP signalled MFA", async () => {const { externalId, email } = await makeAcceptedSsoUser(UserAliasType.SAML);- const login = (idpMfa?: { verified: boolean; evidence: string[] }) =>+ const login = (idpMfa?: { verified: boolean; evidence: string[]; received: string[] }) =>getServices().saml.samlLogin({externalId,email,@@ -94,14 +94,19 @@ describe("Auth IdP Service-Level Tests", () => {idpMfa});- 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({ verified: true, evidence: ["amr=mfa"], received: ["amr=pwd", "amr=mfa"] }))+ .idpMfaOrgId+ ).toBe(TEST_ORG_ID);+ expect(+ sessionClaims(await login({ verified: false, evidence: [], received: ["amr=pwd"] })).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 () => {const { externalId, email } = await makeAcceptedSsoUser(UserAliasType.OIDC);- const login = (idpMfa?: { verified: boolean; evidence: string[] }) =>+ const login = (idpMfa?: { verified: boolean; evidence: string[]; received: string[] }) =>getServices().oidc.oidcLogin({externalId,email,@@ -113,7 +118,9 @@ describe("Auth IdP Service-Level Tests", () => {idpMfa});- expect(sessionClaims(await login({ verified: true, evidence: ["mfa"] })).idpMfaOrgId).toBe(TEST_ORG_ID);+ expect(+ sessionClaims(await login({ verified: true, evidence: ["mfa"], received: ["pwd", "mfa"] })).idpMfaOrgId+ ).toBe(TEST_ORG_ID);expect(sessionClaims(await login()).idpMfaOrgId).toBeUndefined();});});diff --git a/backend/src/services/auth/idp-mfa-signal.test.ts b/backend/src/services/auth/idp-mfa-signal.test.tsindex c9dffe164c..fb3cf98ca3 100644--- a/backend/src/services/auth/idp-mfa-signal.test.ts+++ b/backend/src/services/auth/idp-mfa-signal.test.ts@@ -13,7 +13,7 @@ describe("matchIdpMfaSignal for OIDC", () => {["Auth0 after an MFA challenge", ["mfa"]],["Google with a hardware key", ["pwd", "hwk", "mfa"]]])("accepts %s", (_, amr) => {- expect(oidc({ sub: "u1", amr })).toEqual({ verified: true, evidence: ["mfa"] });+ expect(oidc({ sub: "u1", amr })).toMatchObject({ verified: true, evidence: ["mfa"] });});test.each([@@ -23,11 +23,11 @@ describe("matchIdpMfaSignal for OIDC", () => {["claim of the wrong type", 42],["mfa embedded in another word", ["pwd", "nomfa"]]])("rejects %s", (_, amr) => {- expect(oidc({ sub: "u1", amr })).toEqual({ verified: false, evidence: [] });+ expect(oidc({ sub: "u1", amr })).toMatchObject({ verified: false, evidence: [] });});test("ignores case and surrounding whitespace", () => {- expect(oidc({ amr: [" MFA "] })).toEqual({ verified: true, evidence: ["MFA"] });+ expect(oidc({ amr: [" MFA "] })).toMatchObject({ verified: true, evidence: ["MFA"] });});test("reads amr when the configuration carries no claim name", () => {@@ -38,7 +38,7 @@ describe("matchIdpMfaSignal for OIDC", () => {test("reads the configured claim instead of amr", () => {const config = { mfaClaimName: "authentication_methods" };expect(oidc({ amr: ["mfa"], authentication_methods: ["pwd"] }, config).verified).toBe(false);- expect(oidc({ amr: ["pwd"], authentication_methods: ["mfa"] }, config)).toEqual({+ expect(oidc({ amr: ["pwd"], authentication_methods: ["mfa"] }, config)).toMatchObject({verified: true,evidence: ["mfa"]});@@ -46,7 +46,7 @@ describe("matchIdpMfaSignal for OIDC", () => {test("accepts extra values from the configuration on top of the defaults", () => {const config = { mfaAmrValues: ["otp"] };- expect(oidc({ amr: ["pwd", "otp"] }, config)).toEqual({ verified: true, evidence: ["otp"] });+ expect(oidc({ amr: ["pwd", "otp"] }, config)).toMatchObject({ verified: true, evidence: ["otp"] });expect(oidc({ amr: ["mfa"] }, config).verified).toBe(true);});});@@ -65,7 +65,7 @@ describe("matchIdpMfaSignal for SAML", () => {["REFEDS MFA profile", "https://refeds.org/profile/mfa"],["Entra ID multipleauthn context", MULTIPLEAUTHN]])("accepts the %s context class", (_, classRef) => {- expect(saml([classRef])).toEqual({ verified: true, evidence: [classRef] });+ expect(saml([classRef])).toMatchObject({ verified: true, evidence: [classRef] });});test.each([@@ -79,11 +79,14 @@ describe("matchIdpMfaSignal for SAML", () => {test("accepts an Okta amr attribute statement built from session.amr", () => {const passwordOnly = "urn:oasis:names:tc:SAML:2.0:ac:classes:PasswordProtectedTransport";- expect(saml([passwordOnly], { amr: ["pwd", "mfa", "swk"] })).toEqual({ verified: true, evidence: ["amr=mfa"] });+ expect(saml([passwordOnly], { amr: ["pwd", "mfa", "swk"] })).toMatchObject({+ verified: true,+ evidence: ["amr=mfa"]+ });});test("reads a single-valued attribute as a string, whatever its case", () => {- expect(saml([], { AMR: "mfa" })).toEqual({ verified: true, evidence: ["AMR=mfa"] });+ expect(saml([], { AMR: "mfa" })).toMatchObject({ verified: true, evidence: ["AMR=mfa"] });});test("reads the Entra ID authnmethodsreferences attribute when the configuration names it", () => {@@ -95,7 +98,7 @@ describe("matchIdpMfaSignal for SAML", () => {};const passwordClass = "urn:oasis:names:tc:SAML:2.0:ac:classes:Password";expect(saml([passwordClass], attributes).verified).toBe(false);- expect(saml([passwordClass], attributes, { mfaSignalAttribute: AUTHN_METHODS_REFERENCES })).toEqual({+ expect(saml([passwordClass], attributes, { mfaSignalAttribute: AUTHN_METHODS_REFERENCES })).toMatchObject({verified: true,evidence: [`${AUTHN_METHODS_REFERENCES}=${MULTIPLEAUTHN}`]});@@ -109,18 +112,43 @@ describe("matchIdpMfaSignal for SAML", () => {test("accepts extra context classes from the configuration on top of the defaults", () => {const custom = "urn:example:ac:classes:HardwareToken";expect(saml([custom]).verified).toBe(false);- expect(saml([custom], undefined, { mfaAuthnContexts: [custom] })).toEqual({ verified: true, evidence: [custom] });+ expect(saml([custom], undefined, { mfaAuthnContexts: [custom] })).toMatchObject({+ verified: true,+ evidence: [custom]+ });});test("rejects a password-only assertion with unrelated attributes", () => {const passwordOnly = "urn:oasis:names:tc:SAML:2.0:ac:classes:PasswordProtectedTransport";- expect(saml([passwordOnly], { email: "[email protected]", groups: ["admins"], amr: ["pwd"] })).toEqual({+ expect(saml([passwordOnly], { email: "[email protected]", groups: ["admins"], amr: ["pwd"] })).toMatchObject({verified: false,evidence: []});});});+describe("matchIdpMfaSignal received values", () => {+ test("keeps every value the OIDC claim carried, matched or not", () => {+ expect(oidc({ amr: ["pwd", "otp"] })).toEqual({ verified: false, evidence: [], received: ["pwd", "otp"] });+ expect(oidc({ amr: ["pwd", "mfa"] }).received).toEqual(["pwd", "mfa"]);+ expect(oidc({ sub: "u1" }).received).toEqual([]);+ });++ test("keeps the SAML context classes and the attribute values that were read", () => {+ const passwordOnly = "urn:oasis:names:tc:SAML:2.0:ac:classes:PasswordProtectedTransport";+ expect(saml([passwordOnly], { amr: ["pwd", "swk"], groups: ["admins"] })).toEqual({+ verified: false,+ evidence: [],+ received: [passwordOnly, "amr=pwd", "amr=swk"]+ });+ });++ test("bounds the received list like the matched one", () => {+ const amr = Array.from({ length: 60 }, (_, index) => `method-${index}`);+ expect(oidc({ amr }).received).toHaveLength(50);+ });+});+describe("extractSamlAuthnContextClassRefs", () => {const classRef = "urn:oasis:names:tc:SAML:2.0:ac:classes:TimeSyncToken";diff --git a/backend/src/services/auth/idp-mfa-signal.ts b/backend/src/services/auth/idp-mfa-signal.tsindex 53f4c309d1..41c08abe87 100644--- a/backend/src/services/auth/idp-mfa-signal.ts+++ b/backend/src/services/auth/idp-mfa-signal.ts@@ -23,9 +23,12 @@ const SAML_MFA_ATTRIBUTE_VALUES = ["mfa", "http://schemas.microsoft.com/claims/mconst MAX_SIGNAL_VALUES = 50;const MAX_SIGNAL_VALUE_LENGTH = 512;+// `evidence` is what matched the accepted values and decided `verified`; `received` is everything the IdP sent in+// the fields that were read, so an admin can see why a login was not trusted and which value to accept.export type TIdpMfaSignal = {verified: boolean;evidence: string[];+ received: string[];};export type TSamlMfaSignalConfig = {@@ -75,23 +78,29 @@ export const matchIdpMfaSignal = (input: TIdpMfaSignalInput): TIdpMfaSignal => {const claimName = input.config?.mfaClaimName?.trim() || DEFAULT_MFA_CLAIM_NAME;const claimKey = findKey(input.claims, claimName);const accepted = [...DEFAULT_OIDC_MFA_CLAIM_VALUES, ...(input.config?.mfaAmrValues ?? [])];- const evidence = claimKey ? matchingValues(toStringList(input.claims[claimKey]), accepted) : [];- return { verified: evidence.length > 0, evidence };+ const received = claimKey ? toStringList(input.claims[claimKey]) : [];+ const evidence = matchingValues(received, accepted);+ return { verified: evidence.length > 0, evidence, received };}const acceptedContexts = [...DEFAULT_SAML_MFA_AUTHN_CONTEXTS, ...(input.config?.mfaAuthnContexts ?? [])];- const evidence = matchingValues(toStringList(input.authnContextClassRefs), acceptedContexts);+ const receivedContexts = toStringList(input.authnContextClassRefs);+ const evidence = matchingValues(receivedContexts, acceptedContexts);const attributes = input.attributes ?? {};const attributeName = input.config?.mfaSignalAttribute?.trim() || DEFAULT_MFA_CLAIM_NAME;const attributeKey = findKey(attributes, attributeName);- if (attributeKey) {- matchingValues(toStringList(attributes[attributeKey]), SAML_MFA_ATTRIBUTE_VALUES).forEach((value) => {- evidence.push(`${attributeKey}=${value}`);- });- }+ const receivedAttributeValues = attributeKey ? toStringList(attributes[attributeKey]) : [];+ matchingValues(receivedAttributeValues, SAML_MFA_ATTRIBUTE_VALUES).forEach((value) => {+ evidence.push(`${attributeKey}=${value}`);+ });++ const received = [...receivedContexts, ...receivedAttributeValues.map((value) => `${attributeKey}=${value}`)].slice(+ 0,+ MAX_SIGNAL_VALUES+ );- return { verified: evidence.length > 0, evidence };+ return { verified: evidence.length > 0, evidence, received };};// node-saml parses with xml2js explicitArray and explicitCharkey: every child is an array, a text node is