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
filter inactive org users
Thiago Araujo da Silva159e383e570d
diff --git a/backend/src/lib/logger/sanitize-url.ts b/backend/src/lib/logger/sanitize-url.tsindex 74276eae93..106111d6bb 100644--- a/backend/src/lib/logger/sanitize-url.ts+++ b/backend/src/lib/logger/sanitize-url.ts@@ -14,11 +14,7 @@ const CREDENTIAL_PATH_HOSTS = new Set(["maker.ifttt.com"]);-const CREDENTIAL_PATH_HOST_SUFFIXES = [- ".webhook.office.com",- ".logic.azure.com",- ".slack.com"-];+const CREDENTIAL_PATH_HOST_SUFFIXES = [".webhook.office.com", ".logic.azure.com", ".slack.com"];const hasScheme = new RE2(/^[a-z][a-z\d+\-.]*:\/\//i);const trailingSlashes = new RE2(/\/+$/);diff --git a/backend/src/services/alert/alert-principal-scope-fns.ts b/backend/src/services/alert/alert-principal-scope-fns.tsindex 6e8353b870..23bec67036 100644--- a/backend/src/services/alert/alert-principal-scope-fns.ts+++ b/backend/src/services/alert/alert-principal-scope-fns.ts@@ -1,3 +1,4 @@+import { OrgMembershipStatus } from "@app/db/schemas";import { TGroupDALFactory } from "@app/ee/services/group/group-dal";import { TOrgDALFactory } from "@app/services/org/org-dal";import { TProjectDALFactory } from "@app/services/project/project-dal";@@ -18,6 +19,10 @@ export type TInScopePrincipals = { userIds: Set<string>; groupIds: Set<string> }* the write path (validating an alert channel's recipients) and the send path (re-checking recipients* at delivery time), so both agree on what "in scope" means.*+ * Users must hold an active, accepted org membership in every scope — a deactivated user and a user+ * with a pending invite both keep their memberships, so the project query alone would still match+ * them and they'd receive alerts.+ ** Project scope: effective project membership, i.e. directly added or inherited via a project group.* Org scope: org membership for users. Groups are verified against the org only when `groupDAL` is* supplied — a group cannot move between orgs, so the send path skips that query and trusts the ids@@ -29,23 +34,30 @@ export const resolvePrincipalsInScope = async (): Promise<TInScopePrincipals> => {if (userIds.length === 0 && groupIds.length === 0) return { userIds: new Set(), groupIds: new Set() };+ const activeOrgUserIds = new Set<string>();+ if (userIds.length) {+ const memberships = await orgDAL.findMembership({+ $in: { actorUserId: userIds },+ scopeOrgId: orgId,+ isActive: true,+ status: OrgMembershipStatus.Accepted+ });+ memberships.forEach((membership) => {+ if (membership.actorUserId) activeOrgUserIds.add(membership.actorUserId);+ });+ }+if (projectId) {const { effectiveUserIds, effectiveGroupIds } = await projectDAL.findEffectiveProjectSubjectsMembership({orgId,projectId,- userIds,+ userIds: [...activeOrgUserIds],groupIds});return { userIds: new Set(effectiveUserIds), groupIds: new Set(effectiveGroupIds) };}- const inScopeUserIds = new Set<string>();- if (userIds.length) {- const memberships = await orgDAL.findMembership({ $in: { actorUserId: userIds }, scopeOrgId: orgId });- memberships.forEach((membership) => {- if (membership.actorUserId) inScopeUserIds.add(membership.actorUserId);- });- }+ const inScopeUserIds = activeOrgUserIds;if (!groupDAL || groupIds.length === 0) return { userIds: inScopeUserIds, groupIds: new Set(groupIds) };diff --git a/backend/src/services/alert/alert-recipient-resolver.test.ts b/backend/src/services/alert/alert-recipient-resolver.test.tsindex c9573a1b9e..643169a334 100644--- a/backend/src/services/alert/alert-recipient-resolver.test.ts+++ b/backend/src/services/alert/alert-recipient-resolver.test.ts@@ -8,7 +8,9 @@ type TUser = { id: string; email: string | null; firstName: string | null };const buildResolver = (opts: {users: TUser[];groupMembers?: Record<string, string[]>; // groupId -> userIds (current group membership)- orgUserIds?: string[]; // users currently in the org+ orgUserIds?: string[]; // users with an active, accepted org membership (defaults to every user)+ deactivatedUserIds?: string[]; // users whose org membership was deactivated+ invitedUserIds?: string[]; // users invited to the org who never acceptedeffectiveProjectUserIds?: string[]; // users currently effective in the projecteffectiveProjectGroupIds?: string[]; // groups currently holding a project membership}) => {@@ -23,8 +25,24 @@ const buildResolver = (opts: {$in.groupId.flatMap((groupId) => (opts.groupMembers?.[groupId] ?? []).map((userId) => ({ groupId, userId })))} as never,orgDAL: {- findMembership: async ({ $in }: { $in: { actorUserId: string[] } }) =>- $in.actorUserId.filter((id) => (opts.orgUserIds ?? []).includes(id)).map((actorUserId) => ({ actorUserId }))+ // Mirrors the real DAL closely enough to honour the isActive/status filters the resolver passes.+ findMembership: async (filter: { $in: { actorUserId: string[] }; isActive?: boolean; status?: string }) => {+ const activeUserIds = opts.orgUserIds ?? opts.users.map((u) => u.id);+ return filter.$in.actorUserId+ .flatMap((actorUserId) => {+ if (activeUserIds.includes(actorUserId)) return [{ actorUserId, isActive: true, status: "accepted" }];+ if ((opts.deactivatedUserIds ?? []).includes(actorUserId))+ return [{ actorUserId, isActive: false, status: "accepted" }];+ if ((opts.invitedUserIds ?? []).includes(actorUserId))+ return [{ actorUserId, isActive: true, status: "invited" }];+ return []; // no org membership at all+ })+ .filter(+ (membership) =>+ (filter.isActive === undefined || membership.isActive === filter.isActive) &&+ (filter.status === undefined || membership.status === filter.status)+ );+ }} as never,projectDAL: {findEffectiveProjectSubjectsMembership: async ({@@ -140,6 +158,59 @@ describe("alert recipient resolver — send-time scope re-check", () => {expect(emails).toEqual(["[email protected]"]);});+ test("org scope: drops a deactivated user and a user who never accepted their invite", async () => {+ const resolver = buildResolver({+ users: [user("u1"), user("u2"), user("u3")],+ orgUserIds: ["u1"],+ deactivatedUserIds: ["u2"],+ invitedUserIds: ["u3"]+ });++ const result = await resolver.resolveMany(+ new Map([+ [+ "c1",+ [+ { principalType: AlertPrincipalType.USER, principalId: "u1" },+ { principalType: AlertPrincipalType.USER, principalId: "u2" }, // deactivated+ { principalType: AlertPrincipalType.USER, principalId: "u3" } // invite pending+ ]+ ]+ ]),+ { orgId: "org-1", projectId: null }+ );++ const emails = (result.get("c1") ?? []).map((r) => r.email);+ expect(emails).toEqual(["[email protected]"]);+ });++ test("project scope: drops a deactivated user who still holds a project membership", async () => {+ const resolver = buildResolver({+ users: [user("u1"), user("u2")],+ groupMembers: { g1: ["u1", "u2"] },+ orgUserIds: ["u1"],+ deactivatedUserIds: ["u2"], // deactivating a user leaves their project membership in place+ effectiveProjectUserIds: ["u1", "u2"],+ effectiveProjectGroupIds: ["g1"]+ });++ const result = await resolver.resolveMany(+ new Map([+ [+ "c1",+ [+ { principalType: AlertPrincipalType.GROUP, principalId: "g1" },+ { principalType: AlertPrincipalType.USER, principalId: "u2" }+ ]+ ]+ ]),+ { orgId: "org-1", projectId: "proj-1" }+ );++ const emails = (result.get("c1") ?? []).map((r) => r.email);+ expect(emails).toEqual(["[email protected]"]);+ });+test("org scope: groups still expand, since a group cannot leave its own org", async () => {const resolver = buildResolver({users: [user("u1"), user("u2")],diff --git a/frontend/src/views/Alerts/ChannelRecipientsField.tsx b/frontend/src/views/Alerts/ChannelRecipientsField.tsxindex eab6af104e..e1728a0f04 100644--- a/frontend/src/views/Alerts/ChannelRecipientsField.tsx+++ b/frontend/src/views/Alerts/ChannelRecipientsField.tsx@@ -64,11 +64,14 @@ type SelectProps = {const RecipientSelect = ({options,+ labelledOptions,value,onChange,isError-}: SelectProps & { options: RecipientOption[] }) => {- const byKey = new Map(options.map((o) => [`${o.principalType}-${o.principalId}`, o]));+}: SelectProps & { options: RecipientOption[]; labelledOptions?: RecipientOption[] }) => {+ const byKey = new Map(+ (labelledOptions ?? options).map((o) => [`${o.principalType}-${o.principalId}`, o])+ );const selected = value.map((recipient): RecipientOption =>byKey.get(`${recipient.principalType}-${recipient.principalId}`) ?? {@@ -103,23 +106,47 @@ const RecipientSelect = ({);};+const canReceiveAlerts = (membership: { isActive: boolean; status: string }) =>+ membership.isActive && membership.status !== "invited";+const OrgRecipientSelect = ({ orgId, ...props }: SelectProps & { orgId: string }) => {const { data: users = [] } = useGetOrgUsers(orgId);const { data: groups = [] } = useGetOrganizationGroups(orgId);- return <RecipientSelect options={buildOptions(users, groups)} {...props} />;+ const eligibleUsers = users.filter(canReceiveAlerts);++ return (+ <RecipientSelect+ options={buildOptions(eligibleUsers, groups)}+ labelledOptions={buildOptions(users, groups)}+ {...props}+ />+ );};-const ProjectRecipientSelect = ({ projectId, ...props }: SelectProps & { projectId: string }) => {+const ProjectRecipientSelect = ({+ projectId,+ orgId,+ ...props+}: SelectProps & { projectId: string; orgId: string }) => {const { data: users = [] } = useGetWorkspaceUsers(projectId);+ const { data: orgUsers = [] } = useGetOrgUsers(orgId);const { data: groups = [] } = useListWorkspaceGroups(projectId);+ const blockedUserIds = new Set(+ orgUsers.filter((membership) => !canReceiveAlerts(membership)).map((membership) => membership.user.id)+ );+ const eligibleUsers = users.filter(+ (membership) =>+ membership.user.isOrgMembershipActive && !blockedUserIds.has(membership.user.id)+ );++ const groupOptions = groups.map((membership) => membership.group);+return (<RecipientSelect- options={buildOptions(- users,- groups.map((membership) => membership.group)- )}+ options={buildOptions(eligibleUsers, groupOptions)}+ labelledOptions={buildOptions(users, groupOptions)}{...props}/>);@@ -131,7 +158,7 @@ export const ChannelRecipientsField = ({ projectId, ...props }: Props) => {const { currentOrg } = useOrganization();return projectId ? (- <ProjectRecipientSelect projectId={projectId} {...props} />+ <ProjectRecipientSelect projectId={projectId} orgId={currentOrg.id} {...props} />) : (<OrgRecipientSelect orgId={currentOrg.id} {...props} />);