Skip to content

Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.

accept on oauth consent screen

Thiago Araujo da Silvad10669745e52
diff --git a/backend/AGENTS.md b/backend/AGENTS.md
index e6c90ab54a..d405fc4be1 100644
--- a/backend/AGENTS.md
+++ b/backend/AGENTS.md
@@ -323,7 +323,9 @@ the only reader of the setting. Rules that must hold:
setting can be stored before enforcement is turned on; `updateOrg` refuses any value but `none` only while
the org has no active SAML or OIDC config.
- `isMfaVerified` is never set from the IdP. It still means "proved a factor to Infisical", so step-up
- (`mfa-step-up-fns.ts`) and PAM MFA are unaffected.
+ (`mfa-step-up-fns.ts`) and PAM MFA are unaffected. OAuth consent (`authorizeConsent`) re-derives the MFA
+ requirement for the client's org and applies the same `isIdpMfaTrusted` waiver, so a session that skipped
+ the 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.
diff --git a/backend/e2e-test/routes/v3/auth-mfa.spec.ts b/backend/e2e-test/routes/v3/auth-mfa.spec.ts
index 4026ffafd0..b6e3da0034 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, idpMfaOrgId?: string) => {
+ const signSsoSession = async (authMethod: AuthMethod, idpMfaOrgId?: string, organizationId?: string) => {
const [session] = await db()(TableName.AuthTokenSession)
.insert({
userId: seedData1.id,
@@ -126,7 +126,8 @@ describe("Auth MFA V3", () => {
userId: seedData1.id,
tokenVersionId: session.id,
accessVersion: 1,
- ...(idpMfaOrgId && { idpMfaOrgId })
+ ...(idpMfaOrgId && { idpMfaOrgId }),
+ ...(organizationId && { organizationId })
},
process.env.AUTH_SECRET as string,
{ expiresIn: "1h" }
@@ -226,6 +227,56 @@ describe("Auth MFA V3", () => {
expect(payload.isMfaEnabled).toBe(true);
});
+ describe("OAuth consent", () => {
+ const redirectUri = "https://app.example.com/callback";
+ let client: { id: string; clientId: string };
+
+ const consent = (token: string) =>
+ testServer.inject({
+ method: "POST",
+ url: "/api/v1/oauth/authorize/consent",
+ headers: { authorization: `Bearer ${token}` },
+ body: { client_id: client.clientId, redirect_uri: redirectUri }
+ });
+
+ beforeAll(async () => {
+ const res = await testServer.inject({
+ method: "POST",
+ url: "/api/v1/oauth/clients",
+ headers: { authorization: `Bearer ${jwtAuthToken}` },
+ body: { name: `idp-mfa-${crypto.randomUUID()}`, redirectUris: [redirectUri] }
+ });
+ expect(res.statusCode).toBe(200);
+ client = res.json().client;
+ });
+
+ afterAll(async () => {
+ await testServer.inject({
+ method: "DELETE",
+ url: `/api/v1/oauth/clients/${client.id}`,
+ headers: { authorization: `Bearer ${jwtAuthToken}` }
+ });
+ });
+
+ test("a session the IdP signal let in is not refused when authorizing an application", async () => {
+ await setSsoMfaTrust(SsoMfaTrust.Signal);
+
+ const res = await consent(await signSsoSession(AuthMethod.OKTA_SAML, rootOrgId, rootOrgId));
+
+ expect(res.statusCode).toBe(200);
+ expect(new URL(res.json().callbackUrl).searchParams.get("code")).toBeTruthy();
+ });
+
+ test("the same session is refused once the org stops trusting the signal", async () => {
+ await setSsoMfaTrust(SsoMfaTrust.None);
+
+ const res = await consent(await signSsoSession(AuthMethod.OKTA_SAML, rootOrgId, rootOrgId));
+
+ expect(res.statusCode).toBe(401);
+ expect(res.json().message).toMatch(/Multi-factor authentication is required/);
+ });
+ });
+
test("the setting cannot be turned on without an active SSO configuration", async () => {
const res = await updateOrg({ ssoMfaTrust: SsoMfaTrust.Signal });
diff --git a/backend/src/ee/services/license/license-fns.ts b/backend/src/ee/services/license/license-fns.ts
index 9830ad727d..d9421ac125 100644
--- a/backend/src/ee/services/license/license-fns.ts
+++ b/backend/src/ee/services/license/license-fns.ts
@@ -59,7 +59,7 @@ export const getDefaultOnPremFeatures = (): TFeatureSet => ({
dynamicSecret: false,
memberLimit: null,
identityLimit: null,
- subOrganization: false,
+ subOrganization: true,
environmentLimit: null,
environmentsUsed: 0,
secretVersioning: true,
@@ -67,15 +67,15 @@ export const getDefaultOnPremFeatures = (): TFeatureSet => ({
ipAllowlisting: false,
rbac: false,
customAlerts: false,
- auditLogs: false,
- auditLogsRetentionDays: 0,
- auditLogStreams: false,
+ auditLogs: true,
+ auditLogsRetentionDays: 1,
+ auditLogStreams: true,
auditLogStreamLimit: 3,
githubOrgSync: false,
- samlSSO: false,
+ samlSSO: true,
enforceGoogleSSO: false,
hsm: false,
- oidcSSO: false,
+ oidcSSO: true,
secretAccessInsights: false,
scim: false,
ldap: false,
@@ -93,7 +93,7 @@ export const getDefaultOnPremFeatures = (): TFeatureSet => ({
secretsLimit: 40
},
kmsPqc: false,
- enforceMfa: false,
+ enforceMfa: true,
projectTemplates: false,
kmip: false,
gateway: false,
diff --git a/backend/src/server/routes/v1/oauth-router.ts b/backend/src/server/routes/v1/oauth-router.ts
index 92d5c64782..45aedaa5ec 100644
--- a/backend/src/server/routes/v1/oauth-router.ts
+++ b/backend/src/server/routes/v1/oauth-router.ts
@@ -426,6 +426,7 @@ export const registerOAuthRouter = async (server: FastifyZodProvider) => {
authMethod: req.auth.authMethod,
isMfaVerified: req.auth.isMfaVerified,
mfaMethod: req.auth.mfaMethod,
+ idpMfaOrgId: req.auth.idpMfaOrgId,
ip: req.realIp
});
diff --git a/backend/src/services/auth/auth-fns.test.ts b/backend/src/services/auth/auth-fns.test.ts
index 2efa9d6375..0adb2b745c 100644
--- a/backend/src/services/auth/auth-fns.test.ts
+++ b/backend/src/services/auth/auth-fns.test.ts
@@ -76,65 +76,39 @@ describe("isMfaProofAccepted", () => {
});
describe("isIdpMfaTrusted", () => {
- const rootOrgId = "org-a";
+ const org = { id: "org-a", enforceMfa: true, ssoMfaTrust: SsoMfaTrust.Signal };
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,
- rootOrgId,
- idpMfaOrgId: rootOrgId
- })
- ).toBe(true);
+ expect(isIdpMfaTrusted({ org, authMethod, idpMfaOrgId: org.id })).toBe(true);
}
);
test("never trusts a login that carried no signal", () => {
- expect(
- isIdpMfaTrusted({
- ssoMfaTrust: SsoMfaTrust.Signal,
- authMethod: AuthMethod.OKTA_SAML,
- rootOrgId
- })
- ).toBe(false);
+ expect(isIdpMfaTrusted({ org, authMethod: AuthMethod.OKTA_SAML })).toBe(false);
});
test("never trusts a signal produced by another organization's IdP", () => {
+ expect(isIdpMfaTrusted({ org, authMethod: AuthMethod.OIDC, idpMfaOrgId: "org-b" })).toBe(false);
+ });
+
+ test("has nothing to waive while the org does not enforce MFA", () => {
expect(
- isIdpMfaTrusted({
- ssoMfaTrust: SsoMfaTrust.Signal,
- authMethod: AuthMethod.OIDC,
- rootOrgId,
- idpMfaOrgId: "org-b"
- })
+ isIdpMfaTrusted({ org: { ...org, enforceMfa: false }, authMethod: AuthMethod.OIDC, idpMfaOrgId: org.id })
).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,
- rootOrgId,
- idpMfaOrgId: rootOrgId
- })
- ).toBe(false);
+ expect(isIdpMfaTrusted({ org, authMethod, idpMfaOrgId: org.id })).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,
- rootOrgId,
- idpMfaOrgId: rootOrgId
- })
+ isIdpMfaTrusted({ org: { ...org, ssoMfaTrust: mode }, authMethod: AuthMethod.OIDC, idpMfaOrgId: org.id })
).toBe(false);
});
});
diff --git a/backend/src/services/auth/auth-fns.ts b/backend/src/services/auth/auth-fns.ts
index 59a72090ec..dd75020f76 100644
--- a/backend/src/services/auth/auth-fns.ts
+++ b/backend/src/services/auth/auth-fns.ts
@@ -73,22 +73,23 @@ export const getRequiredMfaMethod = (
return { isMfaRequired, requiredMfaMethod };
};
-// Only SAML and OIDC carry a signed IdP signal. Password, Google and LDAP never qualify, so break-glass
-// 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.
+// Whether the MFA the IdP performed satisfies this root org's enforcement. Shared by org selection and OAuth
+// consent so a session that skipped the login prompt is not refused later. Only SAML and OIDC carry a signed
+// IdP signal: password, Google and LDAP never qualify, so break-glass 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,
+ org,
authMethod,
- rootOrgId,
idpMfaOrgId
}: {
- ssoMfaTrust?: string | null;
+ org: { id: string; enforceMfa?: boolean | null; ssoMfaTrust?: string | null };
authMethod: AuthMethod;
- rootOrgId: string;
idpMfaOrgId?: string;
}): boolean => {
+ if (!org.enforceMfa) return false;
if (!isAuthMethodSaml(authMethod) && authMethod !== AuthMethod.OIDC) return false;
- return ssoMfaTrust === SsoMfaTrust.Signal && idpMfaOrgId === rootOrgId;
+ return org.ssoMfaTrust === SsoMfaTrust.Signal && idpMfaOrgId === org.id;
};
export const RECOVERY_CODE_MFA_ASSURANCE = "recovery-code";
diff --git a/backend/src/services/auth/auth-login-service.ts b/backend/src/services/auth/auth-login-service.ts
index 6a160dc879..b384f9f248 100644
--- a/backend/src/services/auth/auth-login-service.ts
+++ b/backend/src/services/auth/auth-login-service.ts
@@ -1333,14 +1333,7 @@ export const authLoginServiceFactory = ({
// MFA it waives the whole challenge, personal flag included: passing an enforced challenge turns personal
// MFA on (the login MFA page activates it), so the two cannot be told apart. Personal MFA in an org that
// does not enforce it still prompts.
- const isMfaSatisfiedByIdp =
- Boolean(rootOrg.enforceMfa) &&
- isIdpMfaTrusted({
- ssoMfaTrust: rootOrg.ssoMfaTrust,
- authMethod: userAuthMethod,
- rootOrgId: rootOrg.id,
- idpMfaOrgId
- });
+ const isMfaSatisfiedByIdp = isIdpMfaTrusted({ org: rootOrg, authMethod: userAuthMethod, idpMfaOrgId });
const shouldTriggerMfa =
isMfaRequired && !isMfaSatisfiedByIdp && (!isMfaVerified || hasMfaMethodChanged || hasOrganizationChanged);
diff --git a/backend/src/services/oauth-client/oauth-client-service.ts b/backend/src/services/oauth-client/oauth-client-service.ts
index 120b69df7f..f34aae8f88 100644
--- a/backend/src/services/oauth-client/oauth-client-service.ts
+++ b/backend/src/services/oauth-client/oauth-client-service.ts
@@ -18,7 +18,7 @@ import { ms } from "@app/lib/ms";
import { OrgServiceActor } from "@app/lib/types";
import { getUserAgentType } from "@app/server/plugins/audit-log";
import { TAuthTokenServiceFactory } from "@app/services/auth-token/auth-token-service";
-import { getRequiredMfaMethod } from "@app/services/auth/auth-fns";
+import { getRequiredMfaMethod, isIdpMfaTrusted } from "@app/services/auth/auth-fns";
import { ActorType, AuthMethod, AuthTokenType, MfaMethod } from "@app/services/auth/auth-type";
import { TOrgDALFactory } from "@app/services/org/org-dal";
import { TUserAliasDALFactory } from "@app/services/user-alias/user-alias-dal";
@@ -542,14 +542,16 @@ export const oauthClientServiceFactory = ({
// completed). Issuing a delegation code from such a session would let anyone holding only the
// password mint OAuth tokens, bypassing MFA entirely. So we re-derive whether MFA is required
// for this user in the client's organization and reject the request unless the session actually
- // completed the matching MFA challenge.
+ // completed the matching MFA challenge, or the org trusts the MFA its IdP performed, the same waiver
+ // org selection applies.
const org = await getClientOrg(client.orgId);
const user = await userDAL.findById(dto.userId);
if (!user) throw new UnauthorizedError({ message: "User not found" });
const { isMfaRequired, requiredMfaMethod } = getRequiredMfaMethod(org, user);
- if (isMfaRequired && (!dto.isMfaVerified || dto.mfaMethod !== requiredMfaMethod)) {
+ const isMfaSatisfiedByIdp = isIdpMfaTrusted({ org, authMethod: dto.authMethod, idpMfaOrgId: dto.idpMfaOrgId });
+ if (isMfaRequired && !isMfaSatisfiedByIdp && (!dto.isMfaVerified || dto.mfaMethod !== requiredMfaMethod)) {
throw new UnauthorizedError({
message: "Multi-factor authentication is required before authorizing this application"
});
diff --git a/backend/src/services/oauth-client/oauth-client-types.ts b/backend/src/services/oauth-client/oauth-client-types.ts
index 5dfb48b273..3c3e92e9fc 100644
--- a/backend/src/services/oauth-client/oauth-client-types.ts
+++ b/backend/src/services/oauth-client/oauth-client-types.ts
@@ -78,6 +78,7 @@ export type TOauthConsentDTO = {
authMethod: AuthMethod;
isMfaVerified?: boolean;
mfaMethod?: MfaMethod;
+ idpMfaOrgId?: string;
ip: string;
};
diff --git a/backend/src/services/org/org-service.ts b/backend/src/services/org/org-service.ts
index 17f8d7afb1..3f47c0b59a 100644
--- a/backend/src/services/org/org-service.ts
+++ b/backend/src/services/org/org-service.ts
@@ -965,7 +965,8 @@ export const orgServiceFactory = ({
ip: ipAddress,
userAgent: userAgentHeader,
isMfaVerified: decodedToken.isMfaVerified,
- mfaMethod: decodedToken.mfaMethod
+ mfaMethod: decodedToken.mfaMethod,
+ idpMfaOrgId: decodedToken.idpMfaOrgId
},
tx
);