Skip to content

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

fix empty role set

Thiago Araujo da Silvaaaf507176dac
diff --git a/backend/src/ee/services/permission/permission-fns.ts b/backend/src/ee/services/permission/permission-fns.ts
index 37db0a3d0f..8ccb12c98b 100644
--- a/backend/src/ee/services/permission/permission-fns.ts
+++ b/backend/src/ee/services/permission/permission-fns.ts
@@ -1,5 +1,5 @@
/* eslint-disable no-nested-ternary */
-import { ForbiddenError, MongoAbility, PureAbility, RawRuleOf, subject } from "@casl/ability";
+import { createMongoAbility, ForbiddenError, MongoAbility, PureAbility, RawRuleOf, subject } from "@casl/ability";
import handlebars from "handlebars";
import picomatch from "picomatch";
import { z } from "zod";
@@ -411,7 +411,9 @@ const assertRoleSetBoundary = ({
}: TAssertRoleSetBoundaryArg) => {
const primaryAction = Array.isArray(opActions) ? opActions[0] : opActions;
- for (const target of targetPermissions) {
+ const targets = targetPermissions.length ? targetPermissions : [{ permission: createMongoAbility([]) }];
+
+ for (const target of targets) {
const boundary = validatePrivilegeChangeOperation(
shouldUseNewPrivilegeSystem,
opActions,
diff --git a/backend/src/ee/services/permission/role-set-boundary.test.ts b/backend/src/ee/services/permission/role-set-boundary.test.ts
index fc26ffbd1e..b43d253645 100644
--- a/backend/src/ee/services/permission/role-set-boundary.test.ts
+++ b/backend/src/ee/services/permission/role-set-boundary.test.ts
@@ -45,6 +45,24 @@ describe("assertRoleSetBoundary", () => {
expect(() => runBoundary(member, [])).not.toThrow();
});
+ test("an empty target role set still requires the action under the new privilege system", () => {
+ // A no-access group resolves to zero roles, but the actor must still hold the action itself.
+ const assertNewSystem = (actorPermission: MongoAbility) =>
+ assertRoleSetBoundary({
+ shouldUseNewPrivilegeSystem: true,
+ opActions: ProjectPermissionIdentityActions.Delete,
+ opSubject: ProjectPermissionSub.Identity,
+ actorPermission,
+ targetPermissions: [],
+ baseMessage: "Failed to remove a more privileged identity from the project"
+ });
+
+ expect(() => assertNewSystem(member)).not.toThrow();
+ expect(() => assertNewSystem(createMongoAbility<MongoAbility<ProjectPermissionSet>>([]))).toThrow(
+ PermissionBoundaryError
+ );
+ });
+
test("the thrown error carries the missing permissions", () => {
try {
runBoundary(member, [{ permission: admin }]);