Skip to content

Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.

use findEffectiveOrgMembership

Matheus Nogueira4510cc4261f7
diff --git a/backend/src/server/routes/v1/secret-sharing-router.ts b/backend/src/server/routes/v1/secret-sharing-router.ts
index 44674ab6a8..947f26625d 100644
--- a/backend/src/server/routes/v1/secret-sharing-router.ts
+++ b/backend/src/server/routes/v1/secret-sharing-router.ts
@@ -110,7 +110,8 @@ export const registerSecretSharingRouter = async (server: FastifyZodProvider) =>
return req.server.services.secretSharing.getSharedSecretById(
req.params.id,
req.permission?.orgId,
- req.permission?.id
+ req.permission?.id,
+ req.permission?.type
);
}
});
@@ -146,7 +147,8 @@ export const registerSecretSharingRouter = async (server: FastifyZodProvider) =>
sharedSecretId: req.params.id,
password: req.body.password,
orgId: req.permission?.orgId,
- actorId: req.permission?.id
+ actorId: req.permission?.id,
+ actor: req.permission?.type
});
if (sharedSecret.orgId) {
diff --git a/backend/src/services/secret-sharing/secret-sharing-service.ts b/backend/src/services/secret-sharing/secret-sharing-service.ts
index ecb7692493..422d58d301 100644
--- a/backend/src/services/secret-sharing/secret-sharing-service.ts
+++ b/backend/src/services/secret-sharing/secret-sharing-service.ts
@@ -107,8 +107,13 @@ export const secretSharingServiceFactory = ({
const $hasExternalEmailAccess = (sharedSecret: TSecretSharing): boolean =>
Boolean(sharedSecret.allowExternalEmails && sharedSecret.password);
- // Verifies the actor has access to secretOrgId: same root org family AND active membership in secretOrgId.
- const $assertOrgAccess = async (secretOrgId: string, actorOrgId: string, actorId?: string): Promise<void> => {
+ // Verifies the actor has access to secretOrgId: same root org family AND effective membership in secretOrgId.
+ const $assertOrgAccess = async (
+ secretOrgId: string,
+ actorOrgId: string,
+ actorId?: string,
+ actorType?: ActorType
+ ): Promise<void> => {
if (secretOrgId === actorOrgId) return;
const [actorRootOrg, secretRootOrg] = await Promise.all([
orgDAL.findRootOrgDetails(actorOrgId),
@@ -117,16 +122,16 @@ export const secretSharingServiceFactory = ({
if (!actorRootOrg || !secretRootOrg || actorRootOrg.id !== secretRootOrg.id) {
throw new ForbiddenRequestError({ message: "You do not have access to this secret" });
}
- if (!actorId) {
+ if (!actorId || !actorType) {
throw new UnauthorizedError({ message: "Authentication required to view this secret" });
}
- const memberships = await orgDAL.findMembership({
- actorUserId: actorId,
- scopeOrgId: secretOrgId,
- status: OrgMembershipStatus.Accepted,
- isActive: true
+ const membership = await orgDAL.findEffectiveOrgMembership({
+ actorType,
+ actorId,
+ orgId: secretOrgId,
+ status: OrgMembershipStatus.Accepted
});
- if (memberships.length === 0) {
+ if (!membership || !membership.isActive) {
throw new ForbiddenRequestError({ message: "You do not have access to this secret" });
}
};
@@ -609,7 +614,7 @@ export const secretSharingServiceFactory = ({
// Checks whether external (non-org) email access is available for this secret.
- const getSharedSecretById = async (sharedSecretId: string, orgId?: string, actorId?: string) => {
+ const getSharedSecretById = async (sharedSecretId: string, orgId?: string, actorId?: string, actor?: ActorType) => {
const sharedSecret = await secretSharingDAL.findOne({
type: SecretSharingType.Share,
identifier: Buffer.from(sharedSecretId, "base64url").toString("hex")
@@ -627,7 +632,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, actorId, actor);
}
}
@@ -674,7 +679,7 @@ export const secretSharingServiceFactory = ({
};
/** Gets password-less secret. validates all secret's requested (must be fresh). */
- const accessSharedSecret = async ({ sharedSecretId, orgId, actorId, password }: TGetActiveSharedSecretByIdDTO) => {
+ const accessSharedSecret = async ({ sharedSecretId, orgId, actorId, actor, password }: TGetActiveSharedSecretByIdDTO) => {
const result = await secretSharingDAL.transaction(async (tx) => {
await tx.raw("SELECT pg_advisory_xact_lock(?)", [PgSqlLock.AccessSharedSecret(sharedSecretId)]);
@@ -699,7 +704,7 @@ export const secretSharingServiceFactory = ({
throw new UnauthorizedError();
}
if (sharedSecret.orgId) {
- await $assertOrgAccess(sharedSecret.orgId, orgId, actorId);
+ await $assertOrgAccess(sharedSecret.orgId, orgId, actorId, actor);
}
}
diff --git a/backend/src/services/secret-sharing/secret-sharing-types.ts b/backend/src/services/secret-sharing/secret-sharing-types.ts
index 36912abad9..064425fdb2 100644
--- a/backend/src/services/secret-sharing/secret-sharing-types.ts
+++ b/backend/src/services/secret-sharing/secret-sharing-types.ts
@@ -38,6 +38,7 @@ export type TGetActiveSharedSecretByIdDTO = {
sharedSecretId: string;
orgId?: string;
actorId?: string;
+ actor?: ActorType;
password?: string;
};