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
use orgDAL.findRootOrgDetails instead
Matheus Nogueira4a4d6964c438
diff --git a/backend/src/services/secret-sharing/secret-sharing-service.ts b/backend/src/services/secret-sharing/secret-sharing-service.tsindex ff29633ea9..d9418b99ac 100644--- a/backend/src/services/secret-sharing/secret-sharing-service.ts+++ b/backend/src/services/secret-sharing/secret-sharing-service.ts@@ -1,7 +1,7 @@import { ForbiddenError } from "@casl/ability";import { Knex } from "knex";-import { OrganizationActionScope, OrgMembershipStatus, TOrganizations, TSecretSharing } from "@app/db/schemas";+import { OrganizationActionScope, TOrganizations, TSecretSharing } from "@app/db/schemas";import { TLicenseServiceFactory } from "@app/ee/services/license/license-service";import { OrgPermissionSecretShareAction, OrgPermissionSubjects } from "@app/ee/services/permission/org-permission";import { TPermissionServiceFactory } from "@app/ee/services/permission/permission-service-types";@@ -107,19 +107,14 @@ export const secretSharingServiceFactory = ({const $hasExternalEmailAccess = (sharedSecret: TSecretSharing): boolean =>Boolean(sharedSecret.allowExternalEmails && sharedSecret.password);- // Verifies the actor has access to secretOrgId, accounting for sub-org membership.- const $assertOrgAccess = async (secretOrgId: string, actorOrgId: string, actorId?: string): Promise<void> => {+ // Verifies the actor has access to secretOrgId by checking they share the same root org.+ const $assertOrgAccess = async (secretOrgId: string, actorOrgId: string): Promise<void> => {if (secretOrgId === actorOrgId) return;- if (!actorId) {- throw new UnauthorizedError({ message: "Authentication required to view this secret" });- }- const memberships = await orgDAL.findMembership({- actorUserId: actorId,- scopeOrgId: secretOrgId,- status: OrgMembershipStatus.Accepted,- isActive: true- });- if (memberships.length === 0) {+ const [actorRootOrg, secretRootOrg] = await Promise.all([+ orgDAL.findRootOrgDetails(actorOrgId),+ orgDAL.findRootOrgDetails(secretOrgId)+ ]);+ if (!actorRootOrg || !secretRootOrg || actorRootOrg.id !== secretRootOrg.id) {throw new ForbiddenRequestError({ message: "You do not have access to this secret" });}};@@ -620,7 +615,7 @@ export const secretSharingServiceFactory = ({throw new UnauthorizedError({ message: "Authentication required to view this secret" });}if (sharedSecret.orgId) {- await $assertOrgAccess(sharedSecret.orgId, orgId, actorId);+ await $assertOrgAccess(sharedSecret.orgId, orgId);}}@@ -692,7 +687,7 @@ export const secretSharingServiceFactory = ({throw new UnauthorizedError();}if (sharedSecret.orgId) {- await $assertOrgAccess(sharedSecret.orgId, orgId, actorId);+ await $assertOrgAccess(sharedSecret.orgId, orgId);}}