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(agent-vault): stop the refusal message naming actors from other organizations
Scott Wilson81e1780ac72f
diff --git a/backend/src/ee/services/agent-vault-member/agent-vault-membership-service.test.ts b/backend/src/ee/services/agent-vault-member/agent-vault-membership-service.test.tsindex 9c458066df..22b3e50f8b 100644--- a/backend/src/ee/services/agent-vault-member/agent-vault-membership-service.test.ts+++ b/backend/src/ee/services/agent-vault-member/agent-vault-membership-service.test.ts@@ -273,6 +273,62 @@ describe("agentVaultMembership guards", () => {expect(deps.membershipDAL.insertMany).not.toHaveBeenCalled();});+ // The name lookup is not org-scoped, so resolving an outsider would hand back another tenant's email and+ // tell a real id apart from a made-up one. Only the deactivated, who are in this org, get a name.+ test("never names an actor from outside the organization", async () => {+ const { service, deps } = buildService();+ deps.membershipDAL.find.mockResolvedValue([]);+ deps.userDAL.find.mockResolvedValue([{ id: OTHER_USER_ID, username: "[email protected]" }]);++ const refusal = service.addProductMembers({+ projectId: PROJECT_ID,+ userIds: [OTHER_USER_ID],+ machineIdentityIds: [],+ groupIds: [],+ emails: [],+ role: ProjectMembershipRole.Member,+ ctx+ });++ await expect(refusal).rejects.toThrow(`'${OTHER_USER_ID}' is not a member of this organization`);+ await expect(refusal).rejects.not.toThrow("[email protected]");+ });++ test("names a deactivated member, who is in this organization", async () => {+ const { service, deps } = buildService();+ deps.membershipDAL.find.mockResolvedValue([{ id: "org-mem", actorUserId: OTHER_USER_ID, isActive: false }]);+ deps.userDAL.find.mockResolvedValue([{ id: OTHER_USER_ID, username: "[email protected]" }]);++ await expect(+ service.addProductMembers({+ projectId: PROJECT_ID,+ userIds: [OTHER_USER_ID],+ machineIdentityIds: [],+ groupIds: [],+ emails: [],+ role: ProjectMembershipRole.Member,+ ctx+ })+ ).rejects.toThrow("'[email protected]' is deactivated in this organization");+ });++ test("reads correctly for several outsiders", async () => {+ const { service, deps } = buildService();+ deps.membershipDAL.find.mockResolvedValue([]);++ await expect(+ service.addProductMembers({+ projectId: PROJECT_ID,+ userIds: [OTHER_USER_ID, THIRD_USER_ID],+ machineIdentityIds: [],+ groupIds: [],+ emails: [],+ role: ProjectMembershipRole.Member,+ ctx+ })+ ).rejects.toThrow("are not members of this organization. Invite them to the organization first.");+ });+// A group whose organization membership was deactivated must not be restorable by adding it again.test("refuses a group whose organization membership is deactivated", async () => {const { service, deps } = buildService();diff --git a/backend/src/ee/services/agent-vault-member/agent-vault-membership-service.ts b/backend/src/ee/services/agent-vault-member/agent-vault-membership-service.tsindex 6884fed9f6..4e5de153c3 100644--- a/backend/src/ee/services/agent-vault-member/agent-vault-membership-service.ts+++ b/backend/src/ee/services/agent-vault-member/agent-vault-membership-service.ts@@ -416,28 +416,28 @@ export const agentVaultMembershipServiceFactory = ({});if (deactivated.length || strangers.length) {- // Only on the refusal path: the happy path has no use for the names.- const nameByKey = await resolveActorNames([...deactivated, ...strangers]);+ // Names only for the deactivated, who are in this org. The lookup is not org-scoped, so resolving a+ // stranger would hand back another tenant's email, and tell a real id apart from a made-up one.+ const nameByKey = await resolveActorNames(deactivated);const listOf = (refused: TAgentVaultNamedActor[]) =>refused.map((actor) => `'${nameByKey.get(actorKey(actor)) ?? actor.identifier}'`).join(", ");- const verb = (refused: TAgentVaultNamedActor[]) => (refused.length === 1 ? "is" : "are");- const them = (refused: TAgentVaultNamedActor[]) => (refused.length === 1 ? "them" : "those members");// Both, when a batch holds both: fixing one and retrying to discover the other is a wasted round// trip, and a bulk change is where that hurts.const reasons: string[] = [];if (deactivated.length) {+ const one = deactivated.length === 1;reasons.push(- `${listOf(deactivated)} ${verb(deactivated)} deactivated in this organization. Reactivate ${them(- deactivated- )} before changing their Agent Vault access.`+ `${listOf(deactivated)} ${one ? "is" : "are"} deactivated in this organization. Reactivate ${+ one ? "them" : "those members"+ } before changing their Agent Vault access.`);}if (strangers.length) {reasons.push(- `${listOf(strangers)} ${verb(strangers)} not a member of this organization. Invite ${them(- strangers- )} to the organization first.`+ `${listOf(strangers)} ${+ strangers.length === 1 ? "is not a member" : "are not members"+ } of this organization. Invite them to the organization first.`);}diff --git a/frontend/src/pages/agent-vault/AgentVaultAccessControlPage/components/InviteMembersDialog.tsx b/frontend/src/pages/agent-vault/AgentVaultAccessControlPage/components/InviteMembersDialog.tsxindex 7a10b66e4f..82d13397c7 100644--- a/frontend/src/pages/agent-vault/AgentVaultAccessControlPage/components/InviteMembersDialog.tsx+++ b/frontend/src/pages/agent-vault/AgentVaultAccessControlPage/components/InviteMembersDialog.tsx@@ -173,7 +173,6 @@ export const InviteMembersDialog = ({ isOpen, onOpenChange }: Props) => {onSearchChange={setSearch}getOptionValue={(option) => option.value}getOptionLabel={(option) => option.label}- getOptionKeywords={(option) => [option.email]}placeholder="Pick users"searchPlaceholder="Search by name or email..."searchAriaLabel="Search users"