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
fix(oidc): use group ID for "already member" check in group sync
Scott Wilson583fb0755947
diff --git a/backend/src/ee/services/oidc/oidc-config-fns.test.ts b/backend/src/ee/services/oidc/oidc-config-fns.test.tsindex 13b0fe2fb5..e507ce562b 100644--- a/backend/src/ee/services/oidc/oidc-config-fns.test.ts+++ b/backend/src/ee/services/oidc/oidc-config-fns.test.ts@@ -49,6 +49,18 @@ describe("resolveOidcGroupMembershipChanges", () => {expect(groupsToAddUserTo.map((g) => g.id).sort()).toEqual(["1", "2"]);});+ test("adds the user to a case-variant they have not joined even when already in another variant", () => {+ // User is in "Engineering" (id 1) but not "engineering" (id 2). A name-based "already member"+ // check would wrongly skip id 2; keying on group ID adds them to the variant they actually lack.+ const { groupsToAddUserTo } = resolveOidcGroupMembershipChanges({+ idpGroups: ["engineering"],+ userGroupMemberships: [makeMembership("1", "Engineering")],+ orgGroups: [makeGroup("1", "Engineering"), makeGroup("2", "engineering")]+ });++ expect(groupsToAddUserTo.map((g) => g.id)).toEqual(["2"]);+ });+test("only removes groups the user is actually a member of, even when a case-variant exists", () => {// The user is a member of "Engineering" (id 1); a case-variant "engineering" (id 2) also exists// but the user never joined it, so it must not be queued for removal.diff --git a/backend/src/ee/services/oidc/oidc-config-fns.ts b/backend/src/ee/services/oidc/oidc-config-fns.tsindex 9e76a96770..3b04164ca2 100644--- a/backend/src/ee/services/oidc/oidc-config-fns.ts+++ b/backend/src/ee/services/oidc/oidc-config-fns.ts@@ -27,10 +27,13 @@ export const resolveOidcGroupMembershipChanges = <TGroup extends { id: string; ngroupsToRemoveUserFrom: TGroup[];} => {const idpGroupNames = new Set(idpGroups.map((groupName) => groupName.toLowerCase()));- const userGroupNames = new Set(userGroupMemberships.map((membership) => membership.groupName.toLowerCase()));+ // Track current memberships by group ID (not name): when an org holds case-variant groups, the+ // user must still be added to every matching variant they are not actually a member of. Keying on+ // ID also keeps this consistent with how the removal path below is constructed.+ const userGroupIds = new Set(userGroupMemberships.map((membership) => membership.groupId));const groupsToAddUserTo = orgGroups.filter(- (group) => idpGroupNames.has(group.name.toLowerCase()) && !userGroupNames.has(group.name.toLowerCase())+ (group) => idpGroupNames.has(group.name.toLowerCase()) && !userGroupIds.has(group.id));const groupIdsToRemoveUserFrom = new Set(