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 Enter committing a stale option, and name both refusals at once
Scott Wilson836355d31c7f
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 0a8cc7b5b8..9c458066df 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@@ -13,6 +13,7 @@ const ACTOR_ID = "actor-1";const IDENTITY_ID = "identity-1";const GROUP_ID = "group-1";const OTHER_USER_ID = "user-2";+const THIRD_USER_ID = "user-3";const addIds = { userIds: [], groupIds: [], machineIdentityIds: [IDENTITY_ID], emails: [] };@@ -252,6 +253,26 @@ describe("agentVaultMembership guards", () => {expect(deps.membershipDAL.insertMany).not.toHaveBeenCalled();});+ // A batch holding both kinds names both, so fixing one and retrying is not how you discover the other.+ test("names the deactivated and the non-member in one refusal", async () => {+ const { service, deps } = buildService();+ deps.membershipDAL.find.mockResolvedValue([{ id: "org-mem", actorUserId: OTHER_USER_ID, isActive: false }]);++ await expect(+ service.addProductMembers({+ projectId: PROJECT_ID,+ userIds: [OTHER_USER_ID, THIRD_USER_ID],+ machineIdentityIds: [],+ groupIds: [],+ emails: [],+ role: ProjectMembershipRole.Member,+ ctx+ })+ ).rejects.toThrow(/is deactivated in this organization[\s\S]*is not a member of this organization/);++ expect(deps.membershipDAL.insertMany).not.toHaveBeenCalled();+ });+// 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 d7badbce98..6884fed9f6 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@@ -420,24 +420,28 @@ export const agentVaultMembershipServiceFactory = ({const nameByKey = await resolveActorNames([...deactivated, ...strangers]);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) {- throw new BadRequestError({- message: `${listOf(deactivated)} ${- deactivated.length === 1 ? "is" : "are"- } deactivated in this organization. Reactivate ${- deactivated.length === 1 ? "them" : "those members"- } before changing their Agent Vault access.`- });+ reasons.push(+ `${listOf(deactivated)} ${verb(deactivated)} deactivated in this organization. Reactivate ${them(+ deactivated+ )} 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.`+ );}- throw new BadRequestError({- message: `${listOf(strangers)} ${- strangers.length === 1 ? "is" : "are"- } not a member of this organization. Invite ${- strangers.length === 1 ? "them" : "those members"- } to the organization first.`- });+ throw new BadRequestError({ message: reasons.join(" ") });}};diff --git a/frontend/src/pages/agent-vault/AgentVaultAccessControlPage/components/AddGroupDialog.tsx b/frontend/src/pages/agent-vault/AgentVaultAccessControlPage/components/AddGroupDialog.tsxindex 9d0919a05a..fc9420ae49 100644--- a/frontend/src/pages/agent-vault/AgentVaultAccessControlPage/components/AddGroupDialog.tsx+++ b/frontend/src/pages/agent-vault/AgentVaultAccessControlPage/components/AddGroupDialog.tsx@@ -141,10 +141,11 @@ export const AddGroupDialog = ({ isOpen, onOpenChange }: Props) => {id="agent-vault-add-group"options={options}value={group}- shouldFilter={false}isLoading={isFetching}- includeMissingSelectedOptions- onInputValueChange={setSearch}+ // onSearchChange, not onInputValueChange: passing it is what marks the search+ // caller-owned, which turns off the local matcher and stops Enter committing a+ // highlight from the page the previous query returned while this one is in flight.+ onSearchChange={setSearch}getOptionValue={(option) => option.value}getOptionLabel={(option) => option.label}placeholder="Pick a group"diff --git a/frontend/src/pages/agent-vault/AgentVaultAccessControlPage/components/InviteMembersDialog.tsx b/frontend/src/pages/agent-vault/AgentVaultAccessControlPage/components/InviteMembersDialog.tsxindex fa04242daa..dab1ee5b1a 100644--- a/frontend/src/pages/agent-vault/AgentVaultAccessControlPage/components/InviteMembersDialog.tsx+++ b/frontend/src/pages/agent-vault/AgentVaultAccessControlPage/components/InviteMembersDialog.tsx@@ -169,12 +169,11 @@ export const InviteMembersDialog = ({ isOpen, onOpenChange }: Props) => {multipleoptions={candidates}value={selected}- // The server already matched the term, against fields the label does not show.- shouldFilter={false}isLoading={isCandidatesFetching}- // Without this a chip already picked vanishes when the next search returns a page it is not on.- includeMissingSelectedOptions- onInputValueChange={setSearch}+ // onSearchChange, not onInputValueChange: passing it is what marks the search+ // caller-owned, which turns off the local matcher and stops Enter committing a+ // highlight from the page the previous query returned while this one is in flight.+ onSearchChange={setSearch}getOptionValue={(option) => option.value}getOptionLabel={(option) => option.label}getOptionKeywords={(option) => [option.email]}