Skip to content

Commit 5dd16ba

Browse files
committed
fix(core): keep the managed clamp to modifyAllRecords; leave a plain allowTransfer as it was
Clearing a plain allowTransfer on every guarded object also moved the super-user wildcard admin's transfer answer, which the plugin-security parity table (map vs evaluator) does not forgive. That half goes back to the seat; this change keeps to the card: modifyAllRecords is lowered where the guard refuses edit or delete. Claude-Session: https://claude.ai/code/session_01Utp6CZUqByp4kJMhCQDWZ2 Co-authored-by: Claude <noreply@anthropic.com>
1 parent 47fe789 commit 5dd16ba

3 files changed

Lines changed: 14 additions & 24 deletions

File tree

‎.changeset/30440-managed-clamp-modify-all.md‎

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,13 @@
22
'@objectstack/core': patch
33
---
44

5-
fix(core): effective object permissions on a guarded managed object grant no edit, delete or transfer the write guard refuses, `modifyAllRecords` included
5+
fix(core): effective object permissions on a guarded managed object no longer grant edit, delete or transfer through `modifyAllRecords` where the write guard refuses them
66

77
Clause-②: yes (widening)
88
Metadata-protocol: none
99

10-
The managed write clamp behind `/auth/me/permissions` and `ISecurityService.getEffectiveObjectPermissions` cleared `allowEdit`, `allowCreate` and `allowDelete` on an object in a guarded `managedBy` bucket (`better-auth`, `engine-owned`, `append-only`) that does not opt the verb in through `userActions`, but left two grants the write guard refuses:
10+
The managed write clamp behind `/auth/me/permissions` and `ISecurityService.getEffectiveObjectPermissions` cleared `allowEdit`, `allowCreate` and `allowDelete` on an object in a guarded `managedBy` bucket (`better-auth`, `engine-owned`, `append-only`) that does not opt the verb in through `userActions`, but left `modifyAllRecords`, which grants edit, delete and transfer on its own. A permission set naming such an object with `{ modifyAllRecords: true }` therefore made `current_user.can(object, 'edit' | 'delete' | 'transfer')` answer `true` while the write guard refused each of those writes.
1111

12-
- **`modifyAllRecords`**, which grants edit, delete and transfer on its own. A permission set naming such an object with `{ modifyAllRecords: true }` made `current_user.can(object, 'edit' | 'delete' | 'transfer')` answer `true` while every one of those writes was refused. It is now lowered to `viewAllRecords` (the read it implies, so read is unchanged), and each verb the object still opts in is kept as its plain bit: an object opting `edit` in keeps edit and transfer and loses delete. An object opting both `edit` and `delete` in keeps `modifyAllRecords`.
13-
- **`allowTransfer`**, which now follows `edit`: an owner change is an update, refused unless `edit` is opted in. This also corrects a super-user wildcard admin, who was answered `can(object, 'transfer')` `true` on every guarded object.
12+
Where the guard refuses `edit` or `delete`, `modifyAllRecords` is now lowered to `viewAllRecords` (the read it implies, so read is unchanged), and each verb the object still opts in is kept as its plain bit: an object opting `edit` in (such as `sys_user`) keeps edit and transfer and loses delete; an object opting nothing in keeps read only. An object opting both `edit` and `delete` in keeps `modifyAllRecords`. The external write clamp lowers it through the same helper.
1413

1514
No write changes: the guard refused each of these before and still does. Only the served capability answer, and the console buttons that read it, now match it.

‎packages/core/src/security/effective-object-permissions.test.ts‎

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -591,30 +591,24 @@ describe('[#30440] a guarded managed object grants no verb its write guard refus
591591
expect(can(map.sys_feed_note)).toEqual({ allowRead: true, allowCreate: false, allowEdit: true, allowDelete: true, allowTransfer: true });
592592
});
593593

594-
it('an explicit allowTransfer on an object not opting edit in answers no transfer', () => {
595-
const map: any = buildEffectiveObjectPermissions([{ objects: { sys_automation_run: { allowRead: true, allowTransfer: true } } }], source);
596-
expect(objectPermissionGrants(map.sys_automation_run, 'allowTransfer')).toBe(false);
597-
expect(objectPermissionGrants(map.sys_automation_run, 'allowRead')).toBe(true);
598-
});
599-
600594
it('CONTROL: the same entry on an unguarded object keeps every verb modifyAllRecords grants', () => {
601595
const map: any = buildEffectiveObjectPermissions([{ objects: { crm_lead: { modifyAllRecords: true } } }], source);
602596
expect(map.crm_lead.modifyAllRecords).toBe(true);
603597
expect(can(map.crm_lead)).toEqual({ allowRead: true, allowCreate: false, allowEdit: true, allowDelete: true, allowTransfer: true });
604598
});
605599

606-
it('CONTROL: the super-user wildcard fold answers as before, transfer on the object opting nothing in aside', () => {
600+
it('CONTROL: the super-user wildcard fold answers as before', () => {
607601
const map: any = buildEffectiveObjectPermissions(
608602
[{ objects: { '*': { allowRead: true, viewAllRecords: true, modifyAllRecords: true } } }],
609603
source,
610604
);
611605
expect(can(map.crm_lead)).toEqual({ allowRead: true, allowCreate: false, allowEdit: true, allowDelete: true, allowTransfer: true });
612606
expect(can(map.sys_user)).toEqual({ allowRead: true, allowCreate: false, allowEdit: true, allowDelete: false, allowTransfer: true });
613607
expect(can(map.sys_feed_note)).toEqual({ allowRead: true, allowCreate: false, allowEdit: true, allowDelete: true, allowTransfer: true });
614-
// The fold copies the bits the wildcard grants, never modifyAllRecords itself.
608+
// The fold copies the bits the wildcard grants (transfer among them), never
609+
// modifyAllRecords itself, so the lowering never reaches a folded entry.
610+
expect(can(map.sys_automation_run)).toEqual({ allowRead: true, allowCreate: false, allowEdit: false, allowDelete: false, allowTransfer: true });
615611
for (const name of Object.keys(SCHEMAS)) expect(map[name], name).not.toHaveProperty('modifyAllRecords');
616-
// The one answer that moves: the guard refuses the update a transfer is.
617-
expect(can(map.sys_automation_run)).toEqual({ allowRead: true, allowCreate: false, allowEdit: false, allowDelete: false, allowTransfer: false });
618612
});
619613
});
620614

‎packages/core/src/security/effective-object-permissions.ts‎

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -240,15 +240,13 @@ const GUARDED_WRITE_BUCKETS: ReadonlySet<string> = new Set(['better-auth', 'engi
240240
* stands (an admin CAN write them via the data API, and the hint must not
241241
* under-report that).
242242
*
243-
* [#30440] Every verb the guard refuses is refused whatever grants it:
244-
* - `allowTransfer` follows `edit` — an owner change is an update, and the
245-
* guard refuses the update unless `edit` is opted in;
246-
* - `modifyAllRecords` grants edit, delete and transfer on its own (the
247-
* spec's `objectPermissionGrants`), so where the guard refuses one of them
248-
* it is lowered by {@link lowerModifyAllRecords}: to `viewAllRecords`, the
249-
* read it implies, plus the plain bit of each verb the object still opts in.
250-
* Where `edit` and `delete` are both opted in it grants nothing the guard
251-
* refuses, and stays.
243+
* [#30440] `modifyAllRecords` grants edit, delete and transfer on its own (the
244+
* spec's `objectPermissionGrants`), so no `allow*: false` beside it takes any of
245+
* them away. Where the guard refuses `edit` or `delete` it is lowered by
246+
* {@link lowerModifyAllRecords}: to `viewAllRecords`, the read it implies, plus
247+
* the plain bit of each verb the object still opts in — `allowTransfer` with
248+
* `edit`, since an owner change is an update. Where `edit` and `delete` are
249+
* both opted in it grants nothing the guard refuses, and stays.
252250
*/
253251
export function clampManagedObjectWrites(
254252
objects: Record<string, any>,
@@ -267,7 +265,6 @@ export function clampManagedObjectWrites(
267265
// would clamp away a legitimate `{ enabled: true, visibleWhen: … }`.
268266
if (!isWriteOptedIn(ua.create)) acc.allowCreate = false;
269267
if (!del) acc.allowDelete = false;
270-
if (!edit) acc.allowTransfer = false;
271268
lowerModifyAllRecords(acc, { allowEdit: edit, allowDelete: del, allowTransfer: edit });
272269
}
273270
}

0 commit comments

Comments
 (0)