Skip to content

Commit 1c32be0

Browse files
committed
Merge remote-tracking branch 'origin/main' into claude/project-thread-h42d2s
2 parents cdf571a + 5210acf commit 1c32be0

18 files changed

Lines changed: 933 additions & 73 deletions
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
---
2+
'@objectstack/core': patch
3+
'@objectstack/objectql': patch
4+
'@objectstack/service-storage': patch
5+
---
6+
7+
fix(service-storage): a member attaches a file through the attach verb again; the verb vouches for the one file it created
8+
9+
Clause-②: no
10+
Metadata-protocol: none
11+
12+
A signed-in member who may attach files can attach one again through the server-side attach verb (`attachFileAs` on the `file-attachments` service), and so can a print to a record's attachments (`printRecordToFile`). Since the write-time reference check began judging a `lookup` value through the caller's own read door, the verb's `sys_attachment` insert — written as the caller — was refused over its `file_id`: a member who may attach need not read `sys_file`, so the file the verb had just created answered `reference_not_found` and the call failed.
13+
14+
The rule now: a service verb that has created a record in the same call may vouch, on its own write, for the one reference to that record (`vouchForReference`, `@objectstack/core`). The write-time reference check does not ask the caller's read door for exactly that object, field and id, and still probes that the record exists. The attach verb vouches for its own `sys_attachment.file_id` and for nothing else; every other gate on the insert still judges the caller (the permission to create an attachment, the parent-edit attach rule, `enable.files`, the file-reference gate, row- and field-level security, and the `uploaded_by` stamp).
15+
16+
Unchanged: no caller gains a read of `sys_file` or of anything else. A `sys_file` id sent through any data door — REST, MCP, a flow, an import — is judged through the caller's read door exactly as before, the file the verb attached included. The mark is a symbol-keyed context property that no request body, query, stored row or flow definition can spell.
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
---
2+
'@objectstack/objectql': patch
3+
---
4+
5+
fix(objectql)!: an update compares a value the caller sends only against the stored row as the caller's own read door serves it — a `secret` reference and a master-detail repoint
6+
7+
Clause-②: yes (narrowing) — a non-system update that sends a `secret:` reference is refused even when the record already holds it, and a non-system update naming the master-detail FK of a detail with a parent-scoped `requiredWhen`, in a FK column it may edit but not read, no longer lets a row that already lacks a required value rest under the header it names.
8+
Metadata-protocol: none
9+
10+
<!-- adr-0087: not-required (no-migration-prescription) No key of any schema is added, removed, renamed or re-shaped, and no export or type changes. Both refusals are answers the engine already gives — VALIDATION_ERROR for a secret reference, the field's required finding for requiredWhen — so there is nothing for a migration to rewrite and no tombstone. -->
11+
12+
**BREAKING** accept-set narrowing at two update seams of `@objectstack/objectql`, served by every write door, by id and in bulk alike. A system write is unchanged at both.
13+
14+
**A `secret` reference.** A non-system update keeps a `secret:` reference only where every record it lands on serves that reference, in that column, to the caller's own read door. The read path serves a `secret` column masked to every caller, so after the upgrade every non-system update that sends a reference is refused with `400 VALIDATION_ERROR` and nothing is written, with one answer whatever the reference names and whatever the column holds — the record's own reference included, which was accepted and kept before. The same holds for a reference a `beforeUpdate` hook writes onto the payload, such as one that spreads the stored row (`ctx.previous`) back into it. To leave a secret unchanged, omit the field or send back the read mask; a hook that writes the stored row back omits its `secret` columns. A new value is still sealed, `null` still clears, and the system principal keeps the pass-through.
15+
16+
**A master-detail repoint.** On a detail whose fields declare a parent-scoped `requiredWhen`, the ADR-0113 pre-check of an update that names the master-detail FK reads the header the row hung off from the stored FK only as the caller's own read door serves it. Where the caller may edit the FK but not read it (a field permission `{ readable: false, editable: true }`), the prior header is unknown to it and is bound as an unresolved one, so the pre-check cannot prove a violation was already stored: a row that already lacks a value its requirement asks for, and that such a caller names a header for, is refused with the field's `required` finding whatever header the row hung off — including the header it already hangs off, which used to rest. A caller who can read the FK is judged as before, and an update that does not name the FK is unchanged. The `validate()` preview of such an update binds the prior header the same way, so it predicts the same `required` refusal instead of admitting the row.

‎content/docs/permissions/system-context.mdx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ bugs — it is the protection or the side effect that silently does not happen.
138138
| 23b | **Position-catalog check skipped** — a `sys_user_position` write whose `position` names no position in the security catalog is not refused | plugin-security | Get: a system writer can store an assignment naming no position — the seed loader writes `stack.data` from `AppPlugin.start()` under a system context, as invitation acceptance and the platform's own bootstraps do. Lose: such a row grants nothing and nothing says so. A non-system insert, or a non-system update that changes `position`, is refused `400 VALIDATION_FAILED` / `reference_not_found` instead when the security catalog holds no position of that name: the environment registry (ADR-0131 D3), one per deployment, which takes no organization, so a name only a `sys_position` row carries — any organization's — is refused like one nobody carries. It is the same stand-down as the engine's referential-integrity check for a lookup column | `assertPositionNamesCatalogRow` |
139139
| 23c | **Grant-name catalog check skipped** — a `sys_user_permission_set` write whose `permission_set` names no permission set in the security catalog is not refused | plugin-security | Get: a system writer can store a grant naming a set not yet registered — seed replay and boot provisioning may write the grant before the definition it names is registered. Lose: such a row grants nothing and nothing says so. A non-system insert, or a non-system update that changes `permission_set`, is refused `400 VALIDATION_FAILED` / `reference_not_found` instead when the security catalog holds no set by that name; a grant that names no set at all is refused `required` for every caller. The grant names its set by name alone, and nothing derives the name from `permission_set_id` (ADR-0131 D4, D10) | `packages/plugins/plugin-security/src/grant-permission-set-name.ts#onInsert`, `packages/plugins/plugin-security/src/grant-permission-set-name.ts#onUpdate` |
140140
| 23d | **Grant-holder membership check skipped** — a `sys_user_position` or `sys_user_permission_set` write naming a user with no `sys_member` row in the row's organization is not refused | plugin-security | Get: a system writer can store such a grant — invitation acceptance writes the membership and its placement together, and seed replay, the organization-admin reconcile and the platform bootstraps write grants as the system. Lose: such a row takes effect once its user is admitted to the organization. A non-system insert, or a non-system update that moves `user_id` or `organization_id`, is refused `400 VALIDATION_FAILED` / `reference_not_found` at `user_id` instead, for every caller, a platform administrator included; the membership is read as `{ isSystem: true, tenantId }` with `tenantId` the row's own organization, never another one. A row stored with no organization is not judged. Under `single`, 18.0 stamps a new grant with the Default Organization, so such a row is one an earlier release wrote | `packages/plugins/plugin-security/src/grant-holder-membership-refusal.ts#onInsert`, `packages/plugins/plugin-security/src/grant-holder-membership-refusal.ts#onUpdate` |
141-
| 23e | **A `secret` field takes a stored reference as given** — a value already spelled `secret:` is stored unchanged | objectql | Get: a system writer may copy a `secret:` reference onto a record as it stands (seed replay, a migration). Every other caller may only seal a new value or keep its own record's ref: on a create any such value is refused, and on an update it is accepted only when every record the write lands on already holds exactly that reference in that column, which is then left as it is, as an echoed read mask is. Any other reference is refused `400 VALIDATION_ERROR` before anything is written, with one answer whatever it names. Lose: the check that the reference is the record's own — a system writer that copies one is trusted to mean it. Inbound HTTP never carries the flag | `encryptSecretFields` |
141+
| 23e | **A `secret` field takes a stored reference as given** — a value already spelled `secret:` is stored unchanged | objectql | Get: a system writer may copy a `secret:` reference onto a record as it stands (seed replay, a migration). Every other caller may only seal a new value or keep its own record's ref, and its own is the value it reads in that column: on a create any such value is refused, and on an update it would be kept only where every record the write lands on serves exactly that reference to this caller's own read door. The read path serves a `secret` column masked to every caller, so every reference such a caller sends is refused `400 VALIDATION_ERROR` before anything is written, with one answer whatever it names and whatever the column holds; an echoed read mask still leaves the column as it is. Lose: the check that the reference is the record's own — a system writer that copies one is trusted to mean it. Inbound HTTP never carries the flag | `encryptSecretFields` |
142142
| 23f | **Agent ceiling grant check skipped** — a `sys_user_permission_set` write naming an MCP agent ceiling set is not refused | plugin-security | Get: a system writer is not judged. The platform-admin promotion and the organization-admin reconcile name their sets in code, and neither is a ceiling; the self-registration grant writes the configured `audience.selfRegistrationPermissionSet`, which the audience validation (`assertAudienceConfig`, plugin-auth) refuses when it names an agent ceiling set. Lose: seed replay and the development-only demo-staff seed write the sets their stack declares, unjudged, so a seed that names an agent ceiling set stores it. A non-system insert, or a non-system update whose resulting row names one, is refused `400 VALIDATION_FAILED` / `invalid_value` at `permission_set`, for every caller, a platform administrator included; a delete is not judged (ADR-0090 D10) | `packages/plugins/plugin-security/src/agent-ceiling-grant-refusal.ts#onInsert`, `packages/plugins/plugin-security/src/agent-ceiling-grant-refusal.ts#onUpdate` |
143143
| 24 | Tenant-audit warning silenced; `bypassTenantAudit` threaded to the driver | objectql | Get: unscoped system writes stop warning. Lose: the signal that would flag a genuine user-path scoping bug | `buildDriverOptions` |
144144
| 25 | Engine-owned / append-only write guard bypassed | plugin-security | Get: generic writes to `managedBy` engine-owned objects | `packages/plugins/plugin-security/src/system-write-guard.ts#isUserContextWrite`, `packages/plugins/plugin-security/src/system-write-guard.ts#assertEngineOwnedWriteAllowed` |

‎packages/core/src/security/index.ts‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -537,6 +537,16 @@ export {
537537
keepsFlowWriteReferenceCheck,
538538
} from './flow-write-reference-check.js';
539539

540+
// The mark a service verb's own write carries for one reference to a record
541+
// the same call authorized and created. Set by service-storage's
542+
// file-attachments writer, read by objectql's write-time reference check.
543+
export {
544+
VOUCHED_REFERENCES,
545+
vouchForReference,
546+
isVouchedReference,
547+
type VouchedReference,
548+
} from './vouched-reference.js';
549+
540550
// #30205 — a banned user's open work: the per-object counts, the optional bulk
541551
// hand-over (both read and written as the caller), and the ban-in-force
542552
// predicate objectql's write-time reference check refuses a new assignment by.
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.
2+
3+
/**
4+
* The mark a service's own write carries for ONE reference value it vouches
5+
* for: a record the same call has itself authorized and created.
6+
*
7+
* ## The rule it answers to
8+
*
9+
* A write that is not a system write may name, in a `lookup`, `user` or
10+
* `master_detail` field, only a record its caller's own read door returns; a
11+
* record the caller cannot read answers `reference_not_found`
12+
* (`assertReferencesResolve`, objectql). That rule judges a reference the
13+
* CALLER chose. Some service verbs write, as the caller, a row that links to a
14+
* record the verb created a moment earlier in the same call, after asking its
15+
* own authorization question first. The file-attachments verb is the case: it
16+
* asks the attach rule (`assertMayAttach`), stores a new `sys_file` for the
17+
* caller, then inserts the `sys_attachment` naming it AS the caller, so every
18+
* gate on that insert judges the caller. The caller did not choose that file
19+
* id, and a caller who may attach files need not read `sys_file` at all, so
20+
* the read-door question has nothing to judge there; asking it refuses the
21+
* verb outright.
22+
*
23+
* ## What it admits, and what it does not
24+
*
25+
* The mark names one `(object, field, id)`. The reference check reads it for
26+
* exactly that value on a write to that object: the caller's read door is not
27+
* asked for it, and the elevated, tenant-kept existence probe still is, so an
28+
* id that names no row of the caller's organization is refused as before.
29+
* Everything else about the write stays the caller's: every other field and
30+
* every other value in the same field is judged through the caller's read door,
31+
* and nothing about RLS, FLS, the owner and audit stamps, the object's hooks
32+
* or the caller's read of anything changes. It grants no read.
33+
*
34+
* ## Where it is set — and where it is never set
35+
*
36+
* Only by a service verb, on the one write it makes for the record it just
37+
* created, after that verb's own authorization: today the file-attachments
38+
* writer's `sys_attachment` insert (`FileAttachmentService.attachFileAs`,
39+
* service-storage). ⛔ Never on a context a request, an import, a flow, an
40+
* agent tool or any other generic data door hands the engine: a reference such
41+
* a door carries is the caller's choice, and the read-door rule judges it.
42+
*
43+
* ## Why a symbol, and why it is not an `ExecutionContext` field
44+
*
45+
* The same reasons as `FLOW_WRITE_REFERENCE_CHECK`: no request body, query
46+
* string, stored row or flow definition can spell a symbol, so no author can
47+
* set it; it is in no schema; `Symbol.for` keeps it one key across the ESM and
48+
* CJS builds; and, being undeclared, it does not survive
49+
* `ExecutionContextSchema.parse`. It rides a spread of the context as any own
50+
* property does, so a write a hook sets off under the vouched write carries it
51+
* too, and is admitted only for the same object, field and id.
52+
*/
53+
54+
/** The context key of the mark. See the module header. */
55+
export const VOUCHED_REFERENCES: unique symbol = Symbol.for('objectstack.core.vouchedReferences');
56+
57+
/** One reference value a service vouches for: `field` of a write to `object`, naming `id`. */
58+
export interface VouchedReference {
59+
readonly object: string;
60+
readonly field: string;
61+
readonly id: string;
62+
}
63+
64+
/**
65+
* `context` with `reference` added to the references it vouches for — a fresh
66+
* object; `context` is not changed. Called only by a service verb, for a
67+
* record the same call created (see the module header).
68+
*/
69+
export function vouchForReference<T extends object>(
70+
context: T,
71+
reference: VouchedReference,
72+
): T & { [VOUCHED_REFERENCES]: ReadonlyArray<VouchedReference> } {
73+
const held = (context as { [VOUCHED_REFERENCES]?: unknown })[VOUCHED_REFERENCES];
74+
const prior = Array.isArray(held) ? (held as ReadonlyArray<VouchedReference>) : [];
75+
const entry: VouchedReference = Object.freeze({
76+
object: String(reference.object),
77+
field: String(reference.field),
78+
id: String(reference.id),
79+
});
80+
return { ...context, [VOUCHED_REFERENCES]: Object.freeze([...prior, entry]) };
81+
}
82+
83+
/**
84+
* Does `context` vouch for `id` in `field` of a write to `object`? `false` for
85+
* every other value, field, object and context.
86+
*/
87+
export function isVouchedReference(context: unknown, object: unknown, field: unknown, id: unknown): boolean {
88+
if (context === null || typeof context !== 'object') return false;
89+
if (typeof object !== 'string' || typeof field !== 'string') return false;
90+
if (typeof id !== 'string' && typeof id !== 'number') return false;
91+
const held = (context as { [VOUCHED_REFERENCES]?: unknown })[VOUCHED_REFERENCES];
92+
if (!Array.isArray(held)) return false;
93+
const value = String(id);
94+
return held.some(
95+
(r) => r !== null && typeof r === 'object'
96+
&& (r as VouchedReference).object === object
97+
&& (r as VouchedReference).field === field
98+
&& (r as VouchedReference).id === value,
99+
);
100+
}

0 commit comments

Comments
 (0)