Skip to content

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

switch providers clear secrets

Thiago Araujo da Silvabd6d5aaabe00
diff --git a/backend/AGENTS.md b/backend/AGENTS.md
index d405fc4be1..56ba594174 100644
--- a/backend/AGENTS.md
+++ b/backend/AGENTS.md
@@ -321,7 +321,8 @@ the only reader of the setting. Rules that must hold:
honoring it would make the trust dead for anyone who ever logged in before it was enabled. Personal MFA in an
org that does not enforce it is still prompted. The
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.
+ the org has no active SAML or OIDC config, and like `authEnforced` it needs `Sso.Edit`, not just
+ `Settings.Edit`.
- `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. OAuth consent (`authorizeConsent`) re-derives the MFA
requirement for the client's org and applies the same `isIdpMfaTrusted` waiver, so a session that skipped
diff --git a/backend/e2e-test/routes/v3/auth-mfa.spec.ts b/backend/e2e-test/routes/v3/auth-mfa.spec.ts
index b6e3da0034..6080f4fef2 100644
--- a/backend/e2e-test/routes/v3/auth-mfa.spec.ts
+++ b/backend/e2e-test/routes/v3/auth-mfa.spec.ts
@@ -1,5 +1,6 @@
import crypto from "node:crypto";
+import { packRules } from "@casl/ability/extra";
import jwt, { decode } from "jsonwebtoken";
import { OrgMembershipRole, TableName } from "@app/db/schemas";
@@ -9,7 +10,7 @@ import { AuthMethod, AuthTokenType, MfaMethod, SsoMfaTrust } from "@app/services
import { TTestSmtpService } from "../../mocks/smtp";
import { loginUser, selectOrg } from "../../testUtils/auth";
import { overrideLicenseFeatures } from "../../testUtils/license";
-import { addUserMembership } from "../../testUtils/users";
+import { addUserMembership, createUser, createUserAccessToken, deleteUsers } from "../../testUtils/users";
describe("Auth MFA V3", () => {
const smtp = () => (globalThis as unknown as { testSmtp: TTestSmtpService }).testSmtp;
@@ -277,6 +278,39 @@ describe("Auth MFA V3", () => {
});
});
+ // Written straight to the table because the e2e license mock reports `rbac: false`, so the custom-role
+ // routes refuse to create one.
+ test("changing the setting needs the SSO edit permission, not just settings edit", async () => {
+ const { userId } = await createUser("sso-mfa-trust");
+ const [role] = await db()(TableName.Role)
+ .insert({
+ name: `settings-only-${crypto.randomUUID()}`,
+ slug: `settings-only-${crypto.randomUUID()}`,
+ orgId: rootOrgId,
+ permissions: JSON.stringify(packRules([{ subject: "settings", action: ["read", "edit"] }]))
+ })
+ .returning("id");
+ try {
+ const membershipId = await addUserMembership({ userId, orgId: rootOrgId, role: OrgMembershipRole.Member });
+ await db()(TableName.MembershipRole).where({ membershipId }).delete();
+ await db()(TableName.MembershipRole).insert({ membershipId, role: "custom", customRoleId: role.id });
+ const token = await createUserAccessToken({ userId, orgId: rootOrgId });
+ const patch = (body: Record<string, unknown>) =>
+ testServer.inject({
+ method: "PATCH",
+ url: `/api/v1/organization/${rootOrgId}`,
+ headers: { authorization: `Bearer ${token}` },
+ body
+ });
+
+ expect((await patch({ name: seedData1.organization.name })).statusCode).toBe(200);
+ expect((await patch({ ssoMfaTrust: SsoMfaTrust.None })).statusCode).toBe(403);
+ } finally {
+ await deleteUsers([userId]);
+ await db()(TableName.Role).where({ id: role.id }).del();
+ }
+ });
+
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/services/org/org-service.ts b/backend/src/services/org/org-service.ts
index 3f47c0b59a..229dd4a687 100644
--- a/backend/src/services/org/org-service.ts
+++ b/backend/src/services/org/org-service.ts
@@ -589,6 +589,10 @@ export const orgServiceFactory = ({
}
}
+ if (ssoMfaTrust !== undefined) {
+ ForbiddenError.from(permission).throwUnlessCan(OrgPermissionSsoActions.Edit, OrgPermissionSubjects.Sso);
+ }
+
if (ssoMfaTrust !== undefined && ssoMfaTrust !== SsoMfaTrust.None) {
if (!plan.enforceMfa) {
throw new BadRequestError({
diff --git a/frontend/src/pages/organization/SettingsPage/components/OrgSsoTab/OIDCModal.tsx b/frontend/src/pages/organization/SettingsPage/components/OrgSsoTab/OIDCModal.tsx
index 478cb23313..54d0128067 100644
--- a/frontend/src/pages/organization/SettingsPage/components/OrgSsoTab/OIDCModal.tsx
+++ b/frontend/src/pages/organization/SettingsPage/components/OrgSsoTab/OIDCModal.tsx
@@ -235,12 +235,14 @@ export const OIDCModal = ({ popUp, handlePopUpClose, handlePopUpToggle, hideDele
mfaAmrValues: mfaAmrValues && mfaAmrValues.length > 0 ? mfaAmrValues : null
};
+ // 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" });
+ return;
+ }
+
if (!data) {
- if (!clientSecret) {
- setError("clientSecret", { message: "Client Secret is required" });
- return;
- }
- await createMutateAsync({ ...payload, clientSecret });
+ await createMutateAsync({ ...payload, clientSecret: clientSecret as string });
} else {
await updateMutateAsync({ ...payload, ...(clientSecret ? { clientSecret } : {}) });
}