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 cross tenant leak
Thiago Araujo da Silva5251068292fb
diff --git a/backend/e2e-test/routes/v1/sub-org-group-link-identity.spec.ts b/backend/e2e-test/routes/v1/sub-org-group-link-identity.spec.tsindex ccf59259cb..7c65912143 100644--- a/backend/e2e-test/routes/v1/sub-org-group-link-identity.spec.ts+++ b/backend/e2e-test/routes/v1/sub-org-group-link-identity.spec.ts@@ -1,3 +1,5 @@+import crypto from "node:crypto";+import { AccessScope, OrgMembershipRole, TableName } from "@app/db/schemas";import { seedData1 } from "@app/db/seed-data";import { alphaNumericNanoId } from "@app/lib/nanoid";@@ -159,6 +161,40 @@ describe("Linking root groups to a sub-organization with a machine identity", ()expect(await subOrgLinkRows()).toHaveLength(0);});+ test("answers a group from an unrelated organization the same as a missing one", async () => {+ const suffix = alphaNumericNanoId(8).toLowerCase();+ const [otherOrg] = await testDb(TableName.Organization)+ .insert({ name: `group-link-other-${suffix}`, slug: `group-link-other-${suffix}` })+ .returning("*");+ const [otherGroup] = await testDb(TableName.Groups)+ .insert({ orgId: otherOrg.id, name: `other-grp-${suffix}`, slug: `other-grp-${suffix}` })+ .returning("*");++ try {+ const headers = { authorization: `Bearer ${adminSubOrgToken}` };+ for (const id of [otherGroup.id, crypto.randomUUID()]) {+ const url = `/api/v1/organizations/memberships/groups/${id}`;+ // eslint-disable-next-line no-await-in-loop+ const updateRes = await testServer.inject({+ method: "PATCH",+ url,+ headers,+ body: { roles: [{ role: OrgMembershipRole.Member }] }+ });+ expect(updateRes.statusCode).toBe(400);+ expect(updateRes.json().message).toBe(`Group with ID '${id}' not found`);++ // eslint-disable-next-line no-await-in-loop+ const deleteRes = await testServer.inject({ method: "DELETE", url, headers });+ expect(deleteRes.statusCode).toBe(400);+ expect(deleteRes.json().message).toBe(`Group with ID '${id}' not found`);+ }+ } finally {+ await testDb(TableName.Groups).where({ id: otherGroup.id }).del();+ await testDb(TableName.Organization).where({ id: otherOrg.id }).del();+ }+ });+test("links, updates, and unlinks a root group", async () => {const headers = { authorization: `Bearer ${adminSubOrgToken}` };diff --git a/backend/src/services/membership-group/org/org-membership-group-factory.ts b/backend/src/services/membership-group/org/org-membership-group-factory.tsindex d92817ec2e..0b66d694e1 100644--- a/backend/src/services/membership-group/org/org-membership-group-factory.ts+++ b/backend/src/services/membership-group/org/org-membership-group-factory.ts@@ -74,6 +74,14 @@ export const newOrgMembershipGroupFactory = ({);};+ const $getGroupInActorScope = async (actor: OrgServiceActor, groupId: string) => {+ const group = await groupDAL.findById(groupId);+ if (!group || (group.orgId !== actor.orgId && group.orgId !== actor.rootOrgId)) {+ throw new BadRequestError({ message: `Group with ID '${groupId}' not found` });+ }+ return group;+ };+const onCreateMembershipGroupGuard: TMembershipGroupScopeFactory["onCreateMembershipGroupGuard"] = async (dto) => {const isSubOrg = dto.permission.orgId !== dto.permission.rootOrgId;if (!isSubOrg) {@@ -132,13 +140,6 @@ export const newOrgMembershipGroupFactory = ({};const onUpdateMembershipGroupGuard: TMembershipGroupScopeFactory["onUpdateMembershipGroupGuard"] = async (dto) => {- const groupDetails = await groupDAL.findById(dto.selector.groupId);- if (!groupDetails) throw new BadRequestError({ message: "Group details not found" });-- if (isGroupLinkedFromRootOrg(dto.permission, groupDetails.orgId)) {- await $assertCanLinkRootGroup(dto.permission);- }-const { permission } = await permissionService.getOrgPermission({actor: dto.permission.type,actorId: dto.permission.id,@@ -149,6 +150,11 @@ export const newOrgMembershipGroupFactory = ({});ForbiddenError.from(permission).throwUnlessCan(OrgPermissionGroupActions.Edit, OrgPermissionSubjects.Groups);+ const groupDetails = await $getGroupInActorScope(dto.permission, dto.selector.groupId);+ if (isGroupLinkedFromRootOrg(dto.permission, groupDetails.orgId)) {+ await $assertCanLinkRootGroup(dto.permission);+ }+const permissionRoles = await permissionService.getOrgPermissionByRoles(filterRolesNeedingPrivilegeBoundary(dto.data.roles).map((el) => el.role),dto.permission.orgId@@ -201,15 +207,6 @@ export const newOrgMembershipGroupFactory = ({};const onDeleteMembershipGroupGuard: TMembershipGroupScopeFactory["onDeleteMembershipGroupGuard"] = async (dto) => {- const group = await groupDAL.findById(dto.selector.groupId);- if (!group) {- throw new BadRequestError({ message: "Group not found" });- }-- if (isGroupLinkedFromRootOrg(dto.permission, group.orgId)) {- await $assertCanLinkRootGroup(dto.permission);- }-const { permission } = await permissionService.getOrgPermission({actor: dto.permission.type,actorId: dto.permission.id,@@ -220,6 +217,11 @@ export const newOrgMembershipGroupFactory = ({});ForbiddenError.from(permission).throwUnlessCan(OrgPermissionGroupActions.Delete, OrgPermissionSubjects.Groups);+ const group = await $getGroupInActorScope(dto.permission, dto.selector.groupId);+ if (isGroupLinkedFromRootOrg(dto.permission, group.orgId)) {+ await $assertCanLinkRootGroup(dto.permission);+ }+const targetMembership = await membershipGroupDAL.getGroupById({scopeData: dto.scopeData,groupId: dto.selector.groupId