Skip to content

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

fix comments

Thiago Araujo da Silva9f91961e5f39
diff --git a/backend/e2e-test/routes/v1/membership-downgrade-boundary.spec.ts b/backend/e2e-test/routes/v1/membership-downgrade-boundary.spec.ts
index 304e97fd3c..89ccb445a0 100644
--- a/backend/e2e-test/routes/v1/membership-downgrade-boundary.spec.ts
+++ b/backend/e2e-test/routes/v1/membership-downgrade-boundary.spec.ts
@@ -2,19 +2,18 @@
* The membership *update* guard has to bound the target's current roles, not just the roles being
* assigned.
*
- * The update guards resolve `dto.data.roles` -- the roles being ASSIGNED -- and filter NoAccess out
- * before resolution. A request of exactly [no-access] therefore resolved to an empty list, the
- * boundary loop never ran, and nothing was checked on either privilege system. Since setting a
- * member to no-access revokes their access just as a delete does, that was a way around the
- * removal boundary rather than a separate concern:
+ * The update guards resolve the roles being ASSIGNED and filter NoAccess out first, so a request of
+ * exactly [no-access] resolved to an empty list and nothing got checked on either privilege system.
+ * Setting a member to no-access revokes their access just like a delete does, so that was a way
+ * around the removal boundary:
*
- * DELETE an Admin target -> 403 (bounded)
- * PATCH that Admin -> viewer -> 403 (bounded, actor cannot assign viewer)
- * PATCH that Admin -> no-access-> 200 (unbounded) <-- the gap
+ * DELETE an Admin target -> 403 (bounded)
+ * PATCH that Admin -> viewer -> 403 (bounded, actor cannot assign viewer)
+ * PATCH that Admin -> no-access -> 200 (unbounded) <-- the gap
*
- * Removing the filter alone does not fix the legacy system: no-access grants nothing, so
- * dominating it passes trivially. The boundary has to run against the target's CURRENT roles,
- * which is what the delete guard already does.
+ * Dropping the filter alone does not fix the legacy system: no-access grants nothing, so dominating
+ * it passes trivially. The boundary has to run against the target's CURRENT roles, like the delete
+ * guard already does.
*/
import crypto from "node:crypto";
@@ -164,8 +163,7 @@ describe("Privilege boundary on project membership downgrade", () => {
url: `/api/v1/projects/${project.id}/memberships/${membershipId}`,
headers: asIdentity(actor.token)
});
- // Delete uses the privilege-system-aware boundary, so the new system permits it on the
- // strength of holding member:delete alone. That asymmetry is the documented design.
+ // The new system lets this through on member:delete alone. That asymmetry is by design.
expect(res.statusCode).toBe(newSystem ? 200 : 403);
});
@@ -213,11 +211,10 @@ describe("Privilege boundary on project membership downgrade", () => {
});
describe("Privilege boundary on org membership downgrade", () => {
- // PATCH /api/v2/organizations/:orgId/memberships/:membershipId updates a member through
- // org-service rather than through the scoped membership factory, and it only bounded the role
- // being ASSIGNED. Downgrading an Admin to no-access, or deactivating them, assigns nothing the
- // boundary could reject, so it was a way around both the update guard and the removal boundary:
- // downgrade first, then remove the now-weaker member.
+ // PATCH /api/v2/organizations/:orgId/memberships/:membershipId goes through org-service instead of
+ // the scoped membership factory, and only bounded the role being ASSIGNED. Downgrading an Admin to
+ // no-access, or deactivating them, assigns nothing the boundary could reject: downgrade first,
+ // then remove the now-weaker member.
let actor: { identityId: string; token: string };
let adminTarget: { userId: string; membershipId: string };
const targetUserIds: string[] = [];
@@ -305,10 +302,8 @@ describe("Privilege boundary on org membership downgrade", () => {
});
test("deactivating a more privileged member follows the removal boundary", async () => {
- // Deactivation keys on member:delete, so it lands where a removal lands rather than where a
- // role change does: the new system permits it on the strength of holding that action alone,
- // the legacy system still compares privilege levels. It gets its own target because it
- // succeeds on one of the two runs.
+ // Deactivation keys on member:delete, so it lands where a removal lands rather than where a role
+ // change does. Own target, because it succeeds on one of the two runs.
const target = await createAdminTarget();
const res = await patchMembership(target.membershipId, { isActive: false }, asIdentity(actor.token));
diff --git a/backend/e2e-test/routes/v1/privilege-boundary-removal.spec.ts b/backend/e2e-test/routes/v1/privilege-boundary-removal.spec.ts
index 58be9d1f9d..5a5d165327 100644
--- a/backend/e2e-test/routes/v1/privilege-boundary-removal.spec.ts
+++ b/backend/e2e-test/routes/v1/privilege-boundary-removal.spec.ts
@@ -1,15 +1,11 @@
/**
- * E2E tests for the privilege boundary on membership removal and role assignment.
- *
* The gap these cover: the create and update guards in every membership scope factory ran a
* privilege-boundary check, and the delete guards did not. A default project Member holds
- * `identity:delete`, so it could remove an Admin-role identity's membership -- a privilege change
- * on a principal it does not dominate.
- *
- * Each test drives the reach as a *machine identity* actor rather than the seeded admin user, so
- * the actor's role is exactly what the assertion is about.
+ * `identity:delete`, so it could remove an Admin-role identity's membership, a privilege change on a
+ * principal it does not dominate.
*
- * Prerequisites (handled by vitest-environment-knex.ts): testServer, jwtAuthToken, testDb.
+ * Every test drives the reach as a machine identity rather than the seeded admin user, so the
+ * actor's role is exactly what the assertion is about.
*/
import crypto from "node:crypto";
@@ -22,7 +18,7 @@ import { seedData1 } from "@app/db/seed-data";
const adminHeaders = () => ({ authorization: `Bearer ${jwtAuthToken}` });
const asIdentity = (token: string) => ({ authorization: `Bearer ${token}` });
-/** Create an org-Member identity with Universal Auth attached, and log it in. */
+/** Org-Member identity with Universal Auth attached, logged in. */
const createActorIdentity = async (name: string) => {
const createRes = await testServer.inject({
method: "POST",
@@ -61,7 +57,7 @@ const createActorIdentity = async (name: string) => {
return { identityId, token: loginRes.json().accessToken as string };
};
-/** Create a bare org-level identity, with no auth method. Used as a removal target. */
+/** Bare org-level identity with no auth method, for use as a removal target. */
const createTargetIdentity = async (name: string, role: OrgMembershipRole) => {
const res = await testServer.inject({
method: "POST",
@@ -99,9 +95,8 @@ const removeIdentityFromProject = (projectId: string, identityId: string, header
});
/**
- * organizations.shouldUseNewPrivilegeSystem decides which of the two boundary semantics applies:
- * false => the actor must dominate the target's privileges; true => holding the action suffices.
- * It defaults to true, so both branches have to be exercised explicitly.
+ * Picks the boundary semantics: false => the actor must dominate the target's privileges, true =>
+ * holding the action is enough. Defaults to true, so both branches need exercising explicitly.
*/
const setNewPrivilegeSystem = async (enabled: boolean) => {
await testDb(TableName.Organization)
@@ -145,7 +140,7 @@ describe("Privilege boundary on project identity membership removal", () => {
});
test("the actor does hold identity:delete, so the reach is real", async () => {
- // Removing an equal-privilege target succeeds. This is what makes the assertions below
+ // Removing an equal-privilege target succeeds, which is what makes the assertions below
// boundary checks rather than plain missing-permission rejections.
const res = await removeIdentityFromProject(project.id, memberTarget, asIdentity(actor.token));
expect(res.statusCode).toBe(200);
@@ -172,12 +167,9 @@ describe("Privilege boundary on project identity membership removal", () => {
});
describe("on the new privilege system", () => {
- // Documents the deliberate scope of the fix rather than an oversight. Under the new privilege
- // system, holding the action IS the authorization -- validatePrivilegeChangeOperation returns
- // valid as soon as the actor can perform Delete on the subject, ignoring the target's roles.
- // Narrowing this is done with conditions on the Delete action, not with a privilege comparison.
- // NOTE: organizations.shouldUseNewPrivilegeSystem defaults to true, so this is the path most
- // orgs are on, and the removal boundary is inert for them.
+ // Deliberate, not an oversight: under the new system holding the action IS the authorization, so
+ // Delete passes regardless of the target's roles. You narrow it with conditions on the action,
+ // not with a privilege comparison. This is the default, so most orgs get an inert boundary here.
test("a project Member can remove an Admin-role identity", async () => {
const res = await removeIdentityFromProject(project.id, adminTarget, asIdentity(actor.token));
expect(res.statusCode).toBe(200);
@@ -188,10 +180,9 @@ describe("Privilege boundary on project identity membership removal", () => {
});
describe("Privilege boundary on the deprecated v1 add-user-to-project route", () => {
- // POST /api/v1/workspace/:projectId/memberships hardcodes the built-in Member role, so the
- // boundary only bites for an actor holding member:create with LESS than Member's privileges --
- // i.e. a custom role. What is asserted here is the regression guard: the added boundary must not
- // break an admin using the route.
+ // POST /api/v1/workspace/:projectId/memberships hardcodes the built-in Member role, so the boundary
+ // only bites for a custom role holding member:create with less than Member's privileges. All this
+ // asserts is the regression guard: the added boundary must not break an admin using the route.
let project: { id: string };
beforeAll(async () => {
@@ -234,22 +225,20 @@ describe("Privilege boundary on the deprecated v1 add-user-to-project route", ()
}
});
- // The project creator is already a member, so the duplicate check is what rejects this -- which
- // is downstream of the boundary, so reaching it proves the boundary let an admin through.
+ // The project creator is already a member, so the duplicate check rejects this. That check is
+ // downstream of the boundary, so reaching it proves the boundary let an admin through.
expect(res.statusCode).toBe(400);
expect(res.json().message).toContain("already part of project");
});
});
/**
- * A custom role holding only the removal action. This is the actor shape the boundary is about: a
- * principal that legitimately holds `member:delete` yet is weaker than the member it is removing.
- * The built-in org and project Member roles do not hold `member:delete` at all, so they would be
+ * The actor shape the boundary is about: legitimately holds `member:delete`, yet is weaker than the
+ * member it is removing. The built-in Member roles do not hold `member:delete` at all, so they get
* rejected by the plain permission check and never reach the boundary.
*
- * The role is written straight to the table because the e2e license mock reports `rbac: false`, so
- * the custom-role routes refuse to create one. That gate is not what these tests are about, and the
- * boundary resolves roles out of these same columns however they were written.
+ * Written straight to the table because the e2e license mock reports `rbac: false` and the
+ * custom-role routes refuse to create one. The boundary reads these same columns either way.
*/
const insertMemberRemoverRole = async (slug: string, scope: { orgId: string } | { projectId: string }) => {
const [role] = await testDb(TableName.Role)
@@ -285,9 +274,8 @@ const findIdentityMembershipId = async (identityId: string, projectId?: string)
};
/**
- * The seed carries exactly one user, and every removal path here targets a *user* membership. The
- * routes only need a non-ghost Users row joined to a Membership, never a login, so the target is
- * inserted directly rather than driven through the signup and SRP flow.
+ * The seed carries exactly one user and every removal path here targets a user membership. The routes
+ * only need a non-ghost Users row joined to a Membership, never a login, so skip signup and SRP.
*/
const createTargetUser = async (label: string) => {
const username = `${label}-${crypto.randomUUID()}@localhost.local`;
@@ -327,9 +315,8 @@ const dropUser = async (userId: string) => {
};
describe("Privilege boundary on org membership removal", () => {
- // These are the v2 organization routes, which remove a member through org-service rather than
- // through the scoped membership factory. They carry the same reach as the scoped delete and so
- // need the same boundary; without it they are a way around it.
+ // The v2 org routes remove a member through org-service rather than the scoped membership factory.
+ // Same reach as the scoped delete, so without the same boundary they are a way around it.
let actor: { identityId: string; token: string };
let adminTarget: { userId: string; membershipId: string };
diff --git a/backend/src/ee/services/access-approval-request/access-approval-request-fns.test.ts b/backend/src/ee/services/access-approval-request/access-approval-request-fns.test.ts
index c0957aee6b..0be515c5f1 100644
--- a/backend/src/ee/services/access-approval-request/access-approval-request-fns.test.ts
+++ b/backend/src/ee/services/access-approval-request/access-approval-request-fns.test.ts
@@ -271,8 +271,8 @@ describe("verifyRequestedPermissions input hardening", () => {
test("rejects a padded environment rather than trimming it", () => {
// The service persists the request body verbatim and copies it into the granted privilege, so a
- // value this schema normalized would be validated as "dev" and granted as " dev ": the request
- // would be approved and the privilege would match no environment at all.
+ // value normalized here would be validated as "dev" but granted as " dev ": approved, and
+ // matching no environment at all.
const permissions = packRules([makeRule(" dev ", "/apps/*")]);
expect(() => verifyRequestedPermissions({ permissions })).toThrow(BadRequestError);
expect(() => verifyRequestedPermissions({ permissions })).toThrow(/is not allowed/);
diff --git a/backend/src/ee/services/access-approval-request/access-approval-request-fns.ts b/backend/src/ee/services/access-approval-request/access-approval-request-fns.ts
index de1e174014..c43770aa00 100644
--- a/backend/src/ee/services/access-approval-request/access-approval-request-fns.ts
+++ b/backend/src/ee/services/access-approval-request/access-approval-request-fns.ts
@@ -43,8 +43,8 @@ type TUnpackedAccessApprovalRequestRule = {
// { environment: data.environmentSlug, secretPath: { $glob: data.secretPath } }.
// .strict() at both levels so no other operator ($in/$eq/...) or key
// (secretName, secretTags, connectionId, metadata, ...) can be smuggled in.
-// The $glob value reuses the same validator as every other permission surface, bounded here rather
-// than on the shared schema so the tightening cannot affect the other permission surfaces.
+// The $glob value reuses the same validator as every other permission surface, with the length cap
+// added here rather than on the shared schema so the tightening stays local.
const AccessApprovalRequestConditionsSchema = z
.object({
environment: slugSchema({ max: 64, field: "Environment slug", trim: false }),
diff --git a/backend/src/ee/services/group/group-service.ts b/backend/src/ee/services/group/group-service.ts
index acd0342a62..3dcb84a6fd 100644
--- a/backend/src/ee/services/group/group-service.ts
+++ b/backend/src/ee/services/group/group-service.ts
@@ -1063,7 +1063,6 @@ export const groupServiceFactory = ({
orgDAL.findById(actorOrgId)
);
- // check if user has broader or equal to privileges than every role the group holds
assertRoleSetBoundary({
shouldUseNewPrivilegeSystem,
opActions: OrgPermissionGroupActions.AddMembers,
@@ -1161,7 +1160,6 @@ export const groupServiceFactory = ({
orgDAL.findById(actorOrgId)
);
- // check if user has broader or equal to privileges than every role the group holds
assertRoleSetBoundary({
shouldUseNewPrivilegeSystem,
opActions: OrgPermissionGroupActions.AddIdentities,
@@ -1256,7 +1254,6 @@ export const groupServiceFactory = ({
orgDAL.findById(actorOrgId)
);
- // check if user has broader or equal to privileges than every role the group holds
assertRoleSetBoundary({
shouldUseNewPrivilegeSystem,
opActions: OrgPermissionGroupActions.RemoveMembers,
@@ -1333,7 +1330,6 @@ export const groupServiceFactory = ({
orgDAL.findById(actorOrgId)
);
- // check if user has broader or equal to privileges than every role the group holds
assertRoleSetBoundary({
shouldUseNewPrivilegeSystem,
opActions: OrgPermissionGroupActions.RemoveIdentities,
diff --git a/backend/src/ee/services/permission/permission-by-roles.test.ts b/backend/src/ee/services/permission/permission-by-roles.test.ts
index bfd75bb73a..7a10934cac 100644
--- a/backend/src/ee/services/permission/permission-by-roles.test.ts
+++ b/backend/src/ee/services/permission/permission-by-roles.test.ts
@@ -7,11 +7,10 @@ import { OrgPermissionMemberActions, OrgPermissionSubjects } from "./org-permiss
import { permissionServiceFactory } from "./permission-service";
import { ProjectPermissionActions, ProjectPermissionSub } from "./project-permission";
-// A membership row can outlive the role slug it points at: a product gets removed and its slugs stop
-// resolving, while the rows that reference them stay. buildProjectPermissionRules already tolerates
-// that (unknown slug -> no rules). These cover the same tolerance on the by-roles lookups, which the
-// privilege-boundary guards use to measure roles a principal already holds -- without it, a member
-// carrying a stale slug could not be removed at all, because the boundary check 404s first.
+// A membership row can outlive the role slug it points at, e.g. a product gets removed and its slugs
+// stop resolving. buildProjectPermissionRules already tolerates that (unknown slug -> no rules); the
+// by-roles lookups need the same tolerance, or a member carrying a stale slug can never be removed
+// because the privilege-boundary check 404s first.
const CUSTOM_ROLE_SLUG = "release-manager";
diff --git a/backend/src/services/membership-identity/membership-identity-service.test.ts b/backend/src/services/membership-identity/membership-identity-service.test.ts
index 8ce5bf8214..83c7be4238 100644
--- a/backend/src/services/membership-identity/membership-identity-service.test.ts
+++ b/backend/src/services/membership-identity/membership-identity-service.test.ts
@@ -49,9 +49,8 @@ const createService = ({
const membershipIdentityDAL = {
findOne: vi.fn().mockResolvedValue(existingMembership),
- // The delete guards resolve the target's current roles to bound the removal against them.
- // "no-access" is filtered out before resolution, so the target resolves to no roles and the
- // boundary check falls back to an empty ability.
+ // The delete guards bound the removal against the target's current roles. "no-access" is filtered
+ // out before resolution, so the target resolves to no roles and the boundary sees an empty ability.
getIdentityById: vi.fn().mockResolvedValue({ roles: [{ role: "no-access" }] }),
findByIdForUpdate: vi.fn().mockResolvedValue(existingMembership),
find: vi.fn().mockResolvedValue([]),
@@ -76,8 +75,7 @@ const createService = ({
.fn()
.mockResolvedValue({ permission: createMongoAbility([{ action: "manage", subject: "all" }]) }),
// These tests cover revocation markers, not the privilege boundary. Built-in roles come back
- // without a `role` field, and an empty target ability satisfies the boundary under both
- // privilege systems given the `manage all` actor above. An empty slug list resolves to no roles.
+ // without a `role` field, and an empty target ability clears the boundary for the actor above.
getOrgPermissionByRoles: vi
.fn()
.mockImplementation(async (roles: string[]) => (roles.length ? [{ permission: createMongoAbility([]) }] : [])),
diff --git a/backend/src/services/membership-user/org/org-membership-user-boundary.test.ts b/backend/src/services/membership-user/org/org-membership-user-boundary.test.ts
index 436de8fc02..a52f977842 100644
--- a/backend/src/services/membership-user/org/org-membership-user-boundary.test.ts
+++ b/backend/src/services/membership-user/org/org-membership-user-boundary.test.ts
@@ -13,11 +13,10 @@ import { PermissionBoundaryError } from "@app/lib/errors";
import { newOrgMembershipUserFactory } from "./org-membership-user-factory";
-// The org update guard bounds a role change against the roles the target already holds, because a
-// downgrade strips privileges as effectively as a removal does. Both privilege systems reject, but
-// for different reasons: the legacy system compares privilege levels, while the new system asks for
-// member:grant-privileges, which is deliberately not implied by the member:edit that the guard's own
-// throwUnlessCan requires.
+// The org update guard bounds a role change against the roles the target already holds, since a
+// downgrade strips privileges as effectively as a removal does. Both systems reject, for different
+// reasons: the legacy one compares privilege levels, the new one asks for member:grant-privileges,
+// which is deliberately not implied by the member:edit the guard's own throwUnlessCan requires.
const ORG_ID = "org-id";
const TARGET_USER_ID = "target-user-id";
@@ -44,15 +43,6 @@ const memberPrivilegeGranter = createMongoAbility<MongoAbility>([
}
]);
-// Holds the action that describes changing a member's activation, but not the one for assigning
-// roles. The pair with memberPrivilegeGranter is what pins each operation to its own action.
-const memberDeleter = createMongoAbility<MongoAbility>([
- {
- action: [OrgPermissionMemberActions.Read, OrgPermissionMemberActions.Edit, OrgPermissionMemberActions.Delete],
- subject: OrgPermissionSubjects.Member
- }
-]);
-
// Exactly what the invite guard's throwUnlessCan demands, and nothing more.
const memberCreatorOnly = createMongoAbility<MongoAbility>([
{
@@ -181,9 +171,8 @@ describe("onUpdateMembershipUserGuard privilege boundary", () => {
});
test("it is the target's privileges that reject, not the actor being weak", async () => {
- // Same weak actor, but nothing on either side outranks it: no-access is filtered out of the
- // target set entirely, and grants nothing when requested. The guard has to let this through,
- // or it would block every role change a non-admin can legitimately make.
+ // Same weak actor, but nothing on either side outranks it. The guard has to let this through, or
+ // it would block every role change a non-admin can legitimately make.
const guard = createGuard({
actorPermission: memberEditorOnly,
shouldUseNewPrivilegeSystem: false,
@@ -196,12 +185,12 @@ describe("onUpdateMembershipUserGuard privilege boundary", () => {
// The guard ran one boundary keyed on member:grant-privileges for every field on the route, so a
// deactivation was gated on a role-assignment permission. Each operation now keys on the action
- // that describes it, which for metadata is still grant-privileges: it feeds ABAC.
+ // that describes it: activation is a member attribute and stays on member:edit, while metadata
+ // needs grant-privileges because it feeds ABAC.
describe("gating follows the operation being performed", () => {
test("a metadata-only edit is bounded, because metadata drives ABAC", async () => {
- // Org member metadata is the {{identity.metadata.*}} attribute source that project policies
- // interpolate, so rewriting an Admin's metadata rewrites what their roles grant. member:edit
- // alone must not reach it.
+ // Org member metadata is the {{identity.metadata.*}} source project policies interpolate, so
+ // rewriting an Admin's metadata rewrites what their roles grant. member:edit must not reach it.
const metadataOnly = { roles: [], metadata: [{ key: "team", value: "platform" }] };
await expect(
@@ -220,47 +209,38 @@ describe("onUpdateMembershipUserGuard privilege boundary", () => {
data: metadataOnly
})()
).resolves.toBeUndefined();
-
- // member:delete does not: deactivating a member and rewriting their attributes are different
- // operations gated on different actions.
- await expect(
- createGuard({ actorPermission: memberDeleter, shouldUseNewPrivilegeSystem: true, data: metadataOnly })()
- ).rejects.toThrow(PermissionBoundaryError);
});
- test("deactivation keys on member:delete, not member:grant-privileges", async () => {
+ test("deactivation keys on member:edit, so the new system asks for nothing further", async () => {
+ // Activation is a member attribute, not a privilege grant, so it stays on the action the
+ // route's own throwUnlessCan already demanded. On the new system that boundary can only pass.
const deactivate = { roles: [], isActive: false };
- // Holds grant-privileges but not delete: it can assign roles, and that says nothing about
- // being allowed to cut off an Admin's access.
await expect(
- createGuard({ actorPermission: memberPrivilegeGranter, shouldUseNewPrivilegeSystem: true, data: deactivate })()
- ).rejects.toThrow(PermissionBoundaryError);
+ createGuard({ actorPermission: memberEditorOnly, shouldUseNewPrivilegeSystem: true, data: deactivate })()
+ ).resolves.toBeUndefined();
+ // Reactivating is the same operation in the other direction, and gated the same way.
await expect(
- createGuard({ actorPermission: memberDeleter, shouldUseNewPrivilegeSystem: true, data: deactivate })()
+ createGuard({
+ actorPermission: memberEditorOnly,
+ shouldUseNewPrivilegeSystem: true,
+ data: { roles: [], isActive: true }
+ })()
).resolves.toBeUndefined();
- });
-
- test("reactivating a privileged member is bounded the same way", async () => {
- // Restoring an Admin's access is as much a privilege change as removing it, so it cannot be
- // the ungated direction of the same field.
- const reactivate = { roles: [], isActive: true };
+ // The same actor still cannot touch the target's roles.
await expect(
- createGuard({ actorPermission: memberPrivilegeGranter, shouldUseNewPrivilegeSystem: true, data: reactivate })()
+ createGuard({ actorPermission: memberEditorOnly, shouldUseNewPrivilegeSystem: true })()
).rejects.toThrow(PermissionBoundaryError);
-
- await expect(
- createGuard({ actorPermission: memberDeleter, shouldUseNewPrivilegeSystem: true, data: reactivate })()
- ).resolves.toBeUndefined();
});
test("the legacy system still compares privilege levels, whatever the operation", async () => {
- // memberDeleter holds the action, which buys it nothing here: it is still weaker than an Admin.
+ // Holding member:edit buys the actor nothing here: it is still weaker than an Admin, so it
+ // cannot cut off that Admin's access.
await expect(
createGuard({
- actorPermission: memberDeleter,
+ actorPermission: memberEditorOnly,
shouldUseNewPrivilegeSystem: false,
data: { roles: [], isActive: false }
})()
@@ -268,59 +248,48 @@ describe("onUpdateMembershipUserGuard privilege boundary", () => {
});
test("a target holding no roles is still bounded on the new system", async () => {
- // A membership whose roles have all expired resolves to an empty role set. Skipping the
- // boundary for it would let member:edit alone deactivate that member, since nothing else in
- // the guard asks for member:delete.
- const deactivate = { roles: [], isActive: false };
+ // A membership whose roles have all expired resolves to an empty role set. The boundary still
+ // runs against it, so a role change there asks for grant-privileges like any other.
+ const roleChange = { roles: [{ role: "member", isTemporary: false }] };
await expect(
createGuard({
actorPermission: memberEditorOnly,
shouldUseNewPrivilegeSystem: true,
targetRoles: [],
- data: deactivate
+ data: roleChange
})()
).rejects.toThrow(PermissionBoundaryError);
await expect(
createGuard({
- actorPermission: memberDeleter,
+ actorPermission: memberPrivilegeGranter,
shouldUseNewPrivilegeSystem: true,
targetRoles: [],
- data: deactivate
- })()
- ).resolves.toBeUndefined();
-
- // The legacy system compares privilege levels, and no target privileges means nothing to
- // out-rank, so the same weak actor passes there.
- await expect(
- createGuard({
- actorPermission: memberEditorOnly,
- shouldUseNewPrivilegeSystem: false,
- targetRoles: [],
- data: deactivate
+ data: roleChange
})()
).resolves.toBeUndefined();
});
- test("a role change and a deactivation in one request need both actions", async () => {
+ test("a role change and a deactivation in one request are gated separately", async () => {
const both = { roles: [{ role: "member", isTemporary: false }], isActive: false };
- // Each holds exactly one of the two actions, so neither can do both at once.
+ // member:edit carries the deactivation but not the role change, so the request is rejected
+ // as a whole rather than partly applied.
await expect(
- createGuard({ actorPermission: memberPrivilegeGranter, shouldUseNewPrivilegeSystem: true, data: both })()
+ createGuard({ actorPermission: memberEditorOnly, shouldUseNewPrivilegeSystem: true, data: both })()
).rejects.toThrow(PermissionBoundaryError);
await expect(
- createGuard({ actorPermission: memberDeleter, shouldUseNewPrivilegeSystem: true, data: both })()
- ).rejects.toThrow(PermissionBoundaryError);
+ createGuard({ actorPermission: memberPrivilegeGranter, shouldUseNewPrivilegeSystem: true, data: both })()
+ ).resolves.toBeUndefined();
});
});
});
-// An invite always carries a role, so create alone never gets the request through — except for
+// An invite always carries a role, so create alone never gets the request through, except for
// no-access, which confers nothing and so cannot escalate anything. Unlike the update guard, the
-// invite guard has no target to bound against, so the requested roles are the only thing it checks.
+// invite guard has no target to bound against, so the requested roles are all it checks.
describe("onCreateMembershipUserGuard privilege boundary", () => {
const createInviteGuard = ({
actorPermission,
@@ -382,9 +351,8 @@ describe("onCreateMembershipUserGuard privilege boundary", () => {
});
test("inviting with no-access is exempt on both systems", async () => {
- // no-access resolves to an empty rule set, so there is no privilege to escalate and nothing for
- // grant-privileges to be protecting. Requiring it here would block the one invite that is
- // provably harmless.
+ // no-access resolves to an empty rule set, so there is nothing to escalate and nothing for
+ // grant-privileges to protect. Requiring it would block the one invite that is provably harmless.
await expect(
createInviteGuard({
actorPermission: memberCreatorOnly,
diff --git a/backend/src/services/membership-user/org/org-membership-user-factory.ts b/backend/src/services/membership-user/org/org-membership-user-factory.ts
index 763e242a6b..361664279d 100644
--- a/backend/src/services/membership-user/org/org-membership-user-factory.ts
+++ b/backend/src/services/membership-user/org/org-membership-user-factory.ts
@@ -347,7 +347,7 @@ export const newOrgMembershipUserFactory = ({
});
if (dto.data.isActive !== undefined)
targetOps.push({
- opAction: OrgPermissionMemberActions.Delete,
+ opAction: OrgPermissionMemberActions.Edit,
baseMessage: "Failed to change the activation status of a more privileged org member"
});
diff --git a/backend/src/services/membership-user/project/project-membership-user-boundary.test.ts b/backend/src/services/membership-user/project/project-membership-user-boundary.test.ts
index 4f90b47a87..b0dde8d960 100644
--- a/backend/src/services/membership-user/project/project-membership-user-boundary.test.ts
+++ b/backend/src/services/membership-user/project/project-membership-user-boundary.test.ts
@@ -14,9 +14,8 @@ import { PermissionBoundaryError } from "@app/lib/errors";
import { newProjectMembershipUserFactory } from "./project-membership-user-factory";
// The loop that bounds the incoming roles skips NoAccess, so downgrading a privileged member to
-// no-access is the one role change it never sees. The check against the roles the target already
-// holds is what closes that, and it only holds for a condition-scoped actor if it is handed the
-// same subject fields that loop passes.
+// no-access is the one role change it never sees. Checking the roles the target already holds closes
+// that, and for a condition-scoped actor only if it gets the same subject fields that loop passes.
const ORG_ID = "org-id";
const PROJECT_ID = "project-id";
diff --git a/backend/src/services/membership/membership-fns.ts b/backend/src/services/membership/membership-fns.ts
index e07da7e580..7dfac28d6c 100644
--- a/backend/src/services/membership/membership-fns.ts
+++ b/backend/src/services/membership/membership-fns.ts
@@ -59,7 +59,6 @@ export const roleNeedsPrivilegeBoundary = (role: string) =>
export const filterRolesNeedingPrivilegeBoundary = <T extends { role: string }>(roles: T[]) =>
roles.filter((el) => roleNeedsPrivilegeBoundary(el.role));
-// Resolves membership roles into the slug list that get{Org,Project}PermissionByRoles expects.
export const resolveMembershipRoleSlugs = (roles: TMembershipRole[]) => [
...new Set(
roles
diff --git a/backend/src/services/membership/membership-role-dal.ts b/backend/src/services/membership/membership-role-dal.ts
index a73a323aad..96dc0e348c 100644
--- a/backend/src/services/membership/membership-role-dal.ts
+++ b/backend/src/services/membership/membership-role-dal.ts
@@ -18,9 +18,9 @@ type TMembershipRoleSlug = {
export const membershipRoleDALFactory = (db: TDbClient) => {
const orm = ormify(db, TableName.MembershipRole);
- // Role rows for a set of memberships, carrying the custom-role slug rather than its id so the
- // result feeds resolveMembershipRoleSlugs directly. Batched so a bulk privilege-boundary check
- // costs one query no matter how many memberships the caller is removing.
+ // Carries the custom-role slug rather than its id so the result feeds resolveMembershipRoleSlugs
+ // directly. Batched so a bulk privilege-boundary check is one query however many memberships it
+ // covers.
const findRolesByMembershipIds = async (membershipIds: string[], tx?: Knex): Promise<TMembershipRoleSlug[]> => {
if (!membershipIds.length) return [];
diff --git a/backend/src/services/org/org-service.ts b/backend/src/services/org/org-service.ts
index 12c0b616ba..4581018a37 100644
--- a/backend/src/services/org/org-service.ts
+++ b/backend/src/services/org/org-service.ts
@@ -879,7 +879,7 @@ export const orgServiceFactory = ({
});
if (isActive !== undefined)
targetOps.push({
- opAction: OrgPermissionMemberActions.Delete,
+ opAction: OrgPermissionMemberActions.Edit,
baseMessage: "Failed to change the activation status of a more privileged org member"
});
diff --git a/docs/internals/permissions/organization-permissions.mdx b/docs/internals/permissions/organization-permissions.mdx
index c7e27ee8d9..67b055f7e3 100644
--- a/docs/internals/permissions/organization-permissions.mdx
+++ b/docs/internals/permissions/organization-permissions.mdx
@@ -52,13 +52,13 @@ Below is a comprehensive list of all available organization-level subjects and t
#### Subject: `member`
-| Action | Description |
-| ------------------ | ------------------------------------------------ |
-| `read` | View organization members |
-| `create` | Add new members to the organization |
-| `edit` | Modify member details |
-| `delete` | Remove members from the organization |
-| `grant-privileges` | Change the roles held by organization members |
+| Action | Description |
+| ------------------ | ---------------------------------------------- |
+| `read` | View organization members |
+| `create` | Add new members to the organization |
+| `edit` | Modify member attributes and activation status |
+| `delete` | Remove members from the organization |
+| `grant-privileges` | Change the roles held by organization members |
#### Subject: `groups`
diff --git a/frontend/src/layouts/OrganizationLayout/components/NavBar/Navbar.tsx b/frontend/src/layouts/OrganizationLayout/components/NavBar/Navbar.tsx
index 5d8d975da3..75d0296156 100644
--- a/frontend/src/layouts/OrganizationLayout/components/NavBar/Navbar.tsx
+++ b/frontend/src/layouts/OrganizationLayout/components/NavBar/Navbar.tsx
@@ -58,7 +58,7 @@ import {
import { SidebarTrigger } from "@app/components/v3/generic/Sidebar";
import { envConfig } from "@app/config/env";
import {
- OrgPermissionActions,
+ OrgPermissionMemberActions,
OrgPermissionSubjects,
useOrganization,
useServerConfig,
@@ -607,7 +607,7 @@ export const Navbar = () => {
</Button>
)}
{!location.pathname.startsWith("/admin") && !user.superAdmin && (
- <OrgPermissionCan I={OrgPermissionActions.Create} a={OrgPermissionSubjects.Member}>
+ <OrgPermissionCan I={OrgPermissionMemberActions.Create} a={OrgPermissionSubjects.Member}>
{(isAllowed) =>
isAllowed ? (
<Button variant="outline" size="sm" className="mr-2" asChild>
@@ -709,7 +709,10 @@ export const Navbar = () => {
Personal Settings
</Link>
</DropdownMenuItem>
- <OrgPermissionCan I={OrgPermissionActions.Create} a={OrgPermissionSubjects.Member}>
+ <OrgPermissionCan
+ I={OrgPermissionMemberActions.Create}
+ a={OrgPermissionSubjects.Member}
+ >
{(isAllowed) =>
isAllowed ? (
<DropdownMenuItem asChild>
diff --git a/frontend/src/pages/organization/AccessManagementPage/components/OrgMembersTab/components/OrgMembersSection/OrgMembersSection.tsx b/frontend/src/pages/organization/AccessManagementPage/components/OrgMembersTab/components/OrgMembersSection/OrgMembersSection.tsx
index 41311b3118..51dc9c4ad1 100644
--- a/frontend/src/pages/organization/AccessManagementPage/components/OrgMembersTab/components/OrgMembersSection/OrgMembersSection.tsx
+++ b/frontend/src/pages/organization/AccessManagementPage/components/OrgMembersTab/components/OrgMembersSection/OrgMembersSection.tsx
@@ -21,7 +21,7 @@ import {
} from "@app/components/v3";
import { ROUTE_PATHS } from "@app/const/routes";
import {
- OrgPermissionActions,
+ OrgPermissionMemberActions,
OrgPermissionSubjects,
useOrganization,
useUser
@@ -137,7 +137,7 @@ export const OrgMembersSection = () => {
onClearSelection={() => setSelectedMemberIds([])}
>
<OrgPermissionCan
- I={OrgPermissionActions.Delete}
+ I={OrgPermissionMemberActions.Delete}
a={OrgPermissionSubjects.Member}
renderTooltip
>
@@ -172,7 +172,10 @@ export const OrgMembersSection = () => {
Invite and manage {isSubOrganization ? "sub-" : ""}organization users
</CardDescription>
<CardAction>
- <OrgPermissionCan I={OrgPermissionActions.Create} a={OrgPermissionSubjects.Member}>
+ <OrgPermissionCan
+ I={OrgPermissionMemberActions.Create}
+ a={OrgPermissionSubjects.Member}
+ >
{(isAllowed) => (
<Button
variant={isSubOrganization ? "sub-org" : "org"}
diff --git a/frontend/src/pages/organization/AccessManagementPage/components/OrgMembersTab/components/OrgMembersSection/OrgMembersTable.tsx b/frontend/src/pages/organization/AccessManagementPage/components/OrgMembersTab/components/OrgMembersSection/OrgMembersTable.tsx
index b7356cd4c7..64b7a90402 100644
--- a/frontend/src/pages/organization/AccessManagementPage/components/OrgMembersTab/components/OrgMembersSection/OrgMembersTable.tsx
+++ b/frontend/src/pages/organization/AccessManagementPage/components/OrgMembersTab/components/OrgMembersSection/OrgMembersTable.tsx
@@ -53,7 +53,7 @@ import {
TooltipTrigger
} from "@app/components/v3";
import {
- OrgPermissionActions,
+ OrgPermissionMemberActions,
OrgPermissionSubjects,
useOrganization,
useSubscription,
@@ -543,7 +543,7 @@ export const OrgMembersTable = ({
</TableCell>
<TableCell>
<OrgPermissionCan
- I={OrgPermissionActions.Edit}
+ I={OrgPermissionMemberActions.Edit}
a={OrgPermissionSubjects.Member}
>
{(isAllowed) => (
@@ -584,7 +584,7 @@ export const OrgMembersTable = ({
!isSubOrganization &&
serverDetails?.emailConfigured && (
<OrgPermissionCan
- I={OrgPermissionActions.Edit}
+ I={OrgPermissionMemberActions.Create}
a={OrgPermissionSubjects.Member}
>
{(isAllowed) => (
@@ -614,7 +614,7 @@ export const OrgMembersTable = ({
</DropdownMenuTrigger>
<DropdownMenuContent sideOffset={2} align="end">
<OrgPermissionCan
- I={OrgPermissionActions.Edit}
+ I={OrgPermissionMemberActions.Edit}
a={OrgPermissionSubjects.Member}
>
{(isAllowed) => (
@@ -637,7 +637,7 @@ export const OrgMembersTable = ({
)}
</OrgPermissionCan>
<OrgPermissionCan
- I={OrgPermissionActions.Delete}
+ I={OrgPermissionMemberActions.Edit}
a={OrgPermissionSubjects.Member}
>
{(isAllowed) => (
@@ -670,7 +670,7 @@ export const OrgMembersTable = ({
)}
</OrgPermissionCan>
<OrgPermissionCan
- I={OrgPermissionActions.Delete}
+ I={OrgPermissionMemberActions.Delete}
a={OrgPermissionSubjects.Member}
>
{(isAllowed) => (
diff --git a/frontend/src/pages/organization/UserDetailsByIDPage/UserDetailsByIDPage.tsx b/frontend/src/pages/organization/UserDetailsByIDPage/UserDetailsByIDPage.tsx
index 9acc7698f6..b95141c9a7 100644
--- a/frontend/src/pages/organization/UserDetailsByIDPage/UserDetailsByIDPage.tsx
+++ b/frontend/src/pages/organization/UserDetailsByIDPage/UserDetailsByIDPage.tsx
@@ -16,7 +16,6 @@ import {
} from "@app/components/v3";
import { ROUTE_PATHS } from "@app/const/routes";
import {
- OrgPermissionActions,
OrgPermissionMemberActions,
OrgPermissionSubjects,
useOrganization,
@@ -144,7 +143,7 @@ const Page = withPermission(
Copy User ID
</DropdownMenuItem>
<OrgPermissionCan
- I={OrgPermissionActions.Edit}
+ I={OrgPermissionMemberActions.Edit}
a={OrgPermissionSubjects.Member}
>
{(isAllowed) => (
@@ -164,7 +163,7 @@ const Page = withPermission(
)}
</OrgPermissionCan>
<OrgPermissionCan
- I={OrgPermissionActions.Delete}
+ I={OrgPermissionMemberActions.Edit}
a={OrgPermissionSubjects.Member}
>
{(isAllowed) => (
@@ -194,7 +193,7 @@ const Page = withPermission(
)}
</OrgPermissionCan>
<OrgPermissionCan
- I={OrgPermissionActions.Delete}
+ I={OrgPermissionMemberActions.Delete}
a={OrgPermissionSubjects.Member}
>
{(isAllowed) => (
diff --git a/frontend/src/pages/organization/UserDetailsByIDPage/components/UserDetailsSection.tsx b/frontend/src/pages/organization/UserDetailsByIDPage/components/UserDetailsSection.tsx
index 7eee66c530..727fc5ff6e 100644
--- a/frontend/src/pages/organization/UserDetailsByIDPage/components/UserDetailsSection.tsx
+++ b/frontend/src/pages/organization/UserDetailsByIDPage/components/UserDetailsSection.tsx
@@ -29,7 +29,7 @@ import {
IconButton
} from "@app/components/v3";
import {
- OrgPermissionActions,
+ OrgPermissionMemberActions,
OrgPermissionSubjects,
useOrganization,
useUser
@@ -108,7 +108,7 @@ export const UserDetailsSection = ({ membershipId, handlePopUpOpen }: Props) =>
<CardDescription>User membership details</CardDescription>
{userId !== membership.user.id && (
<CardAction>
- <OrgPermissionCan I={OrgPermissionActions.Edit} a={OrgPermissionSubjects.Member}>
+ <OrgPermissionCan I={OrgPermissionMemberActions.Edit} a={OrgPermissionSubjects.Member}>
{(isAllowed) => (
<IconButton
isDisabled={!isAllowed}
@@ -259,7 +259,10 @@ export const UserDetailsSection = ({ membershipId, handlePopUpOpen }: Props) =>
(membership.status === "invited" || membership.status === "verified") &&
membership.user.email &&
serverDetails?.emailConfigured && (
- <OrgPermissionCan I={OrgPermissionActions.Edit} a={OrgPermissionSubjects.Member}>
+ <OrgPermissionCan
+ I={OrgPermissionMemberActions.Create}
+ a={OrgPermissionSubjects.Member}
+ >
{(isAllowed) => (
<Button
isDisabled={!isAllowed}