Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions .changeset/35802-cbp-predicate-write-master-gate.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
---
'@objectstack/plugin-security': patch
---

fix(plugin-security)!: a predicate update or delete of a `controlled_by_parent` detail now writes every row its caller may write by id, the rows other users created included, instead of stopping at the platform's creator-only floor

Clause-②: no (narrowing)
Metadata-protocol: none

<!-- adr-0087: not-required (no-migration-prescription) No key of any schema is added, removed, renamed or re-shaped, and no export changes shape. What moves is which rows one predicate update or delete of a controlled_by_parent detail writes, and whether such a write is refused whole: no stored row, registry key or authored value changes, so there is nothing for a migration to rewrite and no tombstone. -->

**BREAKING: an existing flow now changes or deletes detail rows its caller did not create.** A flow's bulk update or bulk delete node, a server-side script or a hook that runs a predicate write (`update(object, data, { where, multi: true })`, `delete(object, { where, multi: true })`) on a `controlled_by_parent` detail, as an organization member who may edit the master record (or read it, where the detail declares `sharing.controlledByParent.writeRequiresMasterRead`), used to change or delete only the detail rows that member had created and answer success. It now changes or deletes every row its predicate matches that the member can read, within any row-level `update` or `delete` policy the app authored on the detail. Review any such flow that deletes by predicate before upgrading: it will delete more rows than it did.

It ships `patch` because it is a non-protocol breaking change (AGENTS.md Post-Task Checklist step 3): no schema, key or stored value moves, so `Metadata-protocol` is `none`.

- FROM: on a `controlled_by_parent` detail the predicate write kept the platform ownership floor (`owner_only_writes` / `owner_only_deletes` in `member_default`, `created_by == current_user.id`) after its master check had passed. It matched only the rows the caller created, answered success, and never judged the other rows. Measured on a 4-row detail under one master: the master's owner changed 2 rows by predicate and all 4 by id; a member holding an `edit` share on the master, and a manager holding `modifyAllRecords`, changed 0 by predicate and all 4 by id.
- TO: once the master check has passed for every master the write reaches, the write is no longer held to that floor. It changes the rows a write of each row by id would change for the same caller, and it applies to all of its matched rows or to none: a newly matched row refused by a row-level `check`, a validation rule, a hook or a `restrict` relation refuses the whole write with that refusal, and nothing is written.

**A detail that carries its own row-level write policy now writes fewer of the caller's own rows by predicate.** Where an app authors an `update` or `delete` policy with a `using` on a `controlled_by_parent` detail, a predicate write used to compose the platform floor beside that policy as one more OR term, so it also wrote the rows the caller created that the policy does not admit. The floor is no longer a term of that write, so the authored policy alone bounds it: those rows are left unwritten and the write answers success for the rows the policy admits. A by-id write of such a row was already refused, so the two now agree. A write made on another user's behalf keeps the floor and is not changed.

The fix for a caller that must keep the old outcome: narrow the predicate to the rows it means to write (add `created_by` to the `where` to keep writing only the caller's own rows), or write the rows by id to get an outcome per row. To forbid a caller from writing rows other users created on a detail, author a row-level policy on the detail; it binds every row, by id and by predicate.

This is the `controlled_by_parent` half of the predicate-write change shipped beside it: see the note "a predicate update or delete now writes the rows a Modify All holder, a non-creator owner or an edit-share target can write by id" for every other object. It follows the maintainer's ruling that a predicate write and a by-id write of such a detail agree (ADR-0055 §3 as amended 2026-11-22).

What does not change:

- A predicate write reaches only the rows its predicate matches that the caller can read, and a predicate matching more than 10,000 of them is refused before anything is written.
- It is refused whole, with `PERMISSION_DENIED` / 403 and nothing written, when it reaches a detail row under a master the caller may not edit (or may not read, where the detail declares `writeRequiresMasterRead`).
- A detail row that names no master (an optional master) is written by its owner or a Modify All holder; a predicate write that reaches such a row the caller can read and may not write is refused whole.
- A write made on another user's behalf keeps the floor for both principals, as its by-id write does.
- `sharing.controlledByParent.ownerMayEdit` widens a by-id update only: a predicate update still needs edit on the master.
- A by-id write is unchanged, and so is every predicate write on an object that is not a `controlled_by_parent` detail.
- No key, option or response member is added.

A predicate write on such a detail also asks the read door for its rows once where it asked twice: the write is scoped to the rows its master check judged, so a row that starts matching the predicate while the write is being authorized is not written.
4 changes: 2 additions & 2 deletions .changeset/35802-predicate-write-floor-deferral.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
---
'@objectstack/plugin-security': patch
---
Expand All @@ -18,7 +18,7 @@

A predicate write (`update(object, data, { where, multi: true })`, `delete(object, { where, multi: true })`) by an organization member held the platform's own ownership floor (`owner_only_writes` / `owner_only_deletes` in `member_default`, `created_by == current_user.id`) as an unconditional condition, where record sharing enforces writes. Unless an app-authored write policy admitted a row, the write matched only the rows that member had created, even when the same user could update or delete the other matching rows one at a time by id. This affected a manager holding `modifyAllRecords` on the object, a row's owner who did not create it, and, for an update, the target of an `edit`-level record share or a member of the queue a row sits in. The write answered success and changed fewer rows than its predicate matched. A write by id lets the record-sharing service's `allow` verdict replace the floor.

The predicate write now makes the by-id decision for each matched row the floor would refuse. Such a row is written when a write of that row by id would be, because the sharing service answers `allow` for it: ownership at the caller's write depth, Modify All, or, for an update only, an `edit` share or the row's queue. A row the service abstains on keeps the floor: on an object with no `owner_id`, on a delete under `public_read_write` (an update there has no floor to keep, because that OWD opens row updates), and on a `controlled_by_parent` detail unless an update's row sits in a queue the caller belongs to. A row it denies keeps the floor too. The row-level `check` on each updated row follows the same decision.
The predicate write now makes the by-id decision for each matched row the floor would refuse. Such a row is written when a write of that row by id would be, because the sharing service answers `allow` for it: ownership at the caller's write depth, Modify All, or, for an update only, an `edit` share or the row's queue. A row the service abstains on keeps the floor: on an object with no `owner_id`, and on a delete under `public_read_write` (an update there has no floor to keep, because that OWD opens row updates). A row it denies keeps the floor too. The row-level `check` on each updated row follows the same decision.

The by-id decision costs one sharing verdict, a few store reads, for each matched row the floor does not already admit. Measured on SQLite in memory:

Expand All @@ -35,6 +35,6 @@
- An `edit` share still widens update and never delete.
- The tenant wall is unchanged.
- A write made on another user's behalf keeps the floor for both principals, as its by-id write does.
- A `controlled_by_parent` detail keeps the floor on a predicate write, except on an update of a row that sits in a queue the caller belongs to, which the sharing service answers `allow` for under any OWD. The master gate still judges the predicate write. Its by-id write is decided by the master gate instead of the floor, and that half is not changed here.
- A `controlled_by_parent` detail is not decided by this composition. Its predicate write, like its by-id write, is decided by its master gate instead of the floor: see the note "a predicate update or delete of a `controlled_by_parent` detail now writes every row its caller may write by id".

A flow, script or server-side bulk update or delete that relied on a predicate write skipping the rows its caller did not create now changes those rows too, when the caller may write them by id, and is refused whole when one of them is refused. The fix is the one above.
8 changes: 6 additions & 2 deletions content/docs/permissions/permissions-matrix.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,12 @@ by-id write and a predicate write both take that replacement unless an
app-authored `using` policy for the write applies to the caller; then the write
keeps the floor beside that policy, so a row the caller created stays writable
and the policy bounds every other row. A write made on another user's behalf
keeps the floor. A `controlled_by_parent` detail's by-id write is
judged by its master gate instead of the floor. An app-authored policy is never
keeps the floor. A `controlled_by_parent` detail's write, by id or by
predicate, is judged by its master gate instead of the floor: a caller who may
edit the master (or read it, where the detail declares
`writeRequiresMasterRead`) writes the detail rows under it whoever created
them, and a predicate write that reaches a master the caller may not write
under is refused whole. An app-authored policy is never
replaced. The Layer 0 tenant wall always ANDs on top. See
[Sharing & OWD](/docs/permissions/sharing-rules#how-viewallrecords--modifyallrecords-interact-with-the-owd)
and `plugin-security/src/security-plugin.ts` (`computeLayeredRlsFilter`).
Expand Down
5 changes: 3 additions & 2 deletions content/docs/permissions/rls.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,10 @@ does not take away a row the floor admits (one the caller created), whether
or not record sharing replaces the floor for that row. Two exceptions: on an
object whose org-wide default is `public_read_write`, an `update` has no floor,
so an authored `update` policy is the whole scope and does refuse the caller's
own non-matching row; and on a `controlled_by_parent` detail, a by-id write is
own non-matching row; and on a `controlled_by_parent` detail, a write is
judged by its master gate instead of the floor, so a detail policy bounds every
detail row written by id (a predicate write on a detail keeps the floor). To cap what a caller
detail row written, by id or by predicate (a write made on another user's
behalf keeps the floor). To cap what a caller
may do to rows they created, use a `check` (it judges the stored image) or a
`beforeUpdate` / `beforeDelete` lifecycle hook (it sees the prior row as
`ctx.previous`). Nothing is derived for `insert`
Expand Down
9 changes: 7 additions & 2 deletions content/docs/permissions/sharing-rules.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,13 @@ Two things the bits do **not** override, regardless of the OWD:
`org_member`). Under `public_read_write` the update policy does not apply
(that OWD opens row updates) and the delete policy does; under every other
OWD both apply, and record sharing can replace them row by row, as below.
A `controlled_by_parent` detail's by-id write is judged by its master gate
instead. The super-user bits short-circuit RLS **only
A `controlled_by_parent` detail's write is judged by its master gate
instead, by id and by predicate alike: a caller who may edit the master (or
read it, where the detail declares `writeRequiresMasterRead`) updates and
deletes the detail rows under it whoever created them. A predicate
(`multi: true`) update or delete writes the rows a by-id write of each
would, and is refused whole, with nothing written, when it reaches a master
the caller may not write under. The super-user bits short-circuit RLS **only
where the object's access posture permits it** — `access: { default:
'private' }`, `tenancy.enabled: false` (deployment-level: no organization column), or better-auth
managed objects (ADR-0066 D2 ①). On an ordinary tenant business object,
Expand Down
Loading
Loading