Skip to content

Commit 359c749

Browse files
committed
fix(rest)!: /meta/_drafts refuses a bracketed packageId or type key
The arity doors' bracketed-package decision becomes one per-door table, metaBracketedFilterRefusal: the list and the book tree judge `package`, _drafts judges `packageId` and `type`. metaQueryArityRefusal asks it, so the runtime dispatcher's _drafts gets it with no runtime change; RestServer's _drafts door asks it right after its multiplicity gate. Claude-Session: https://claude.ai/code/session_01ADHkmSq83zsshBxiLpFJdE Co-authored-by: Claude <noreply@anthropic.com>
1 parent b748eaa commit 359c749

4 files changed

Lines changed: 99 additions & 32 deletions

File tree

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
---
2+
'@objectstack/rest': patch
3+
---
4+
5+
fix(rest)!: a bracketed `packageId` or `type` key on `GET /meta/_drafts` (`?packageId[]=ID`, `?packageId[0]=ID`, `?type[]=TYPE`, `?type[0]=TYPE`) is refused 400 naming the key instead of being ignored and answered with every package's or every type's drafts
6+
7+
Clause-②: no (narrowing) — `GET /meta/_drafts` with any query key that opens `packageId[` or `type[` (on `RestServer` and on the runtime dispatcher, which share the arity decision) is refused with `400 VALIDATION_ERROR`; it answered 200 with every draft the caller may read before. No package export, answer member, error code, status or `rule` tag is added: the refusal reuses the `bracketed-parameter` rule the list and the book tree already answer.
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: a drafts request that spells its one-package or one-type filter as an array key is refused instead of served unfiltered. There is nothing for a migration to rewrite and no tombstone. -->
11+
12+
**BREAKING** accept-set narrowing on the `/meta/_drafts` read (`@objectstack/rest`).
13+
14+
- **Before.** `?packageId[]=ID`, `?packageId[0]=ID`, `?type[]=TYPE` and `?type[0]=TYPE` (the qs-style array spellings) reached the door under the key as spelled, which neither filter read, so an author who asked for one package's or one type's drafts got every draft, as if it were the filtered list. Beside a plain `?packageId=` the bracketed key was silently dropped.
15+
- **Now.** The door refuses a key that opens `packageId[` or `type[` after its capability gate and its multiplicity gate, before any read: `400 VALIDATION_ERROR`, message `Query parameter 'packageId[]' names no package; the 'packageId' filter takes exactly one package id, spelled ?packageId=ID. …` or `Query parameter 'type[]' names no metadata type; the 'type' filter takes exactly one metadata type, spelled ?type=TYPE. …`, and no list. A bracketed key beside the plain one is refused too.
16+
- **Unchanged.** `?packageId=ID` and `?type=TYPE` narrow as before, and leaving them out lists every draft; a repeated `packageId` or `type` keeps its 400; a caller with no authoring capability is still refused 403 first.
17+
- **Who sees it.** An API client that serialises arrays qs-style. `@objectstack/client`'s `listDrafts` builds both keys with `URLSearchParams` (no brackets), and the console sends `?packageId=` plain.
18+
19+
**The remedy.** FROM `?packageId[]=ID` (or `?packageId[0]=ID`) TO `?packageId=ID`; FROM `?type[]=TYPE` (or `?type[0]=TYPE`) TO `?type=TYPE`; leave the key out to list every draft.

‎packages/rest/src/meta-collection-routes.ts‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -465,6 +465,16 @@ export function registerMetaCollectionRoutes(this: MetaCollectionRouteHost, scop
465465
// [#23214] The list lives beside the shared decision, so the
466466
// runtime dispatcher's twin refuses the same names.
467467
if (refuseRepeatedQueryParams(req, res, metaReadGate.META_QUERY_ARITY_DOORS.drafts)) return;
468+
// A bracketed `packageId` or `type` key (`?type[]=`) is read
469+
// by neither filter below, so it narrowed nothing: refused
470+
// here, by the decision the dispatcher's twin asks too.
471+
const bracketedFilter = metaReadGate.metaBracketedFilterRefusal('drafts', req.query);
472+
if (bracketedFilter) {
473+
res.status(bracketedFilter.status).json({
474+
error: { code: bracketedFilter.code, message: bracketedFilter.message },
475+
});
476+
return;
477+
}
468478
// [#29180] A `type` that names no metadata type narrowed the
469479
// list to nothing and answered `200 {"drafts":[]}`, a
470480
// confident "nothing pending". Refused by the list door's own
@@ -651,7 +661,7 @@ export function registerMetaCollectionRoutes(this: MetaCollectionRouteHost, scop
651661
// A bracketed `package` key (`?package[]=`) is read by no
652662
// binding below, so it scoped nothing: refused here, by the
653663
// decision the dispatcher's twin asks too.
654-
const bracketedPackage = metaReadGate.metaBracketedPackageRefusal('list', req.query);
664+
const bracketedPackage = metaReadGate.metaBracketedFilterRefusal('list', req.query);
655665
if (bracketedPackage) {
656666
res.status(bracketedPackage.status).json({
657667
error: { code: bracketedPackage.code, message: bracketedPackage.message },

‎packages/rest/src/meta-item-read-gate.ts‎

Lines changed: 68 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -2417,7 +2417,7 @@ const LAYERED_VIEW_MEMBER_MESSAGE =
24172417
* everywhere; `rule` names which of the three refused, because `RestServer`'s
24182418
* item read answers the third at a different point (see
24192419
* {@link metaItemQueryRefusal}). The arity doors answer a fourth,
2420-
* `bracketed-parameter` ({@link metaBracketedPackageRefusal}).
2420+
* `bracketed-parameter` ({@link metaBracketedFilterRefusal}).
24212421
*/
24222422
export interface MetaItemQueryRefusal {
24232423
readonly status: 400;
@@ -2558,50 +2558,88 @@ export const META_QUERY_ARITY_DOORS: Readonly<Record<MetaQueryArityDoor, readonl
25582558
* door's {@link META_QUERY_ARITY_DOORS} entry that was supplied more than once,
25592559
* as `400 VALIDATION_ERROR` with `repeatedQueryParamMessage`'s sentence, which
25602560
* is the answer `RestServer`'s door gives through `refuseRepeatedQueryParams`;
2561-
* then a bracketed `package` key ({@link metaBracketedPackageRefusal}), which
2561+
* then a bracketed narrowing filter ({@link metaBracketedFilterRefusal}), which
25622562
* `RestServer`'s door asks right after its multiplicity gate. It returns
25632563
* `undefined` otherwise, and has then unwrapped a one-element array in place.
25642564
* ⛔ Ask it before any read of the door's query.
25652565
*/
25662566
export function metaQueryArityRefusal(door: MetaQueryArityDoor, query: unknown): MetaItemQueryRefusal | undefined {
25672567
if (!query || typeof query !== 'object') return undefined;
25682568
return repeatedOnceRefusal(query as Record<string, unknown>, META_QUERY_ARITY_DOORS[door])
2569-
?? metaBracketedPackageRefusal(door, query);
2569+
?? metaBracketedFilterRefusal(door, query);
25702570
}
25712571

25722572
/**
2573-
* The answer of the two arity doors that read `?package=` — the list and the
2574-
* book tree — to a BRACKETED spelling of it: `?package[]=ID`, `?package[0]=ID`,
2575-
* any key that opens `package[`. A client that serialises arrays qs-style sends
2576-
* it; every adapter hands the key through as spelled, so the door's
2577-
* `metaItemPackageBinding(query.package)` read no package, and a caller who
2578-
* named ONE package was answered across every package. `400
2579-
* VALIDATION_ERROR`, in the list chain's narrowing-filter frame
2580-
* ({@link listFilterRefusalMessage}), naming the key as sent; beside a plain
2581-
* `?package=` too (two spellings of one scope). Asked at the door's entry,
2582-
* before any read — where the binding is read — by both transports:
2573+
* One filter an arity door judges for a BRACKETED spelling: the name as the
2574+
* door reads it, what one value of it names, how one value is spelled, what the
2575+
* door serves, and what leaving the parameter out reads. Every field goes into
2576+
* {@link listFilterRefusalMessage}'s one sentence frame.
2577+
*/
2578+
interface MetaBracketedFilter {
2579+
readonly param: string;
2580+
readonly names: string;
2581+
readonly takes: string;
2582+
readonly served: 'list' | 'tree';
2583+
readonly unscoped: string;
2584+
}
2585+
2586+
const PACKAGE_ID_TAKES = 'one package id, spelled';
2587+
2588+
/**
2589+
* The single-valued filters each arity door judges for a bracketed spelling, in
2590+
* the order asked: the names these doors read at their entry whose absence
2591+
* WIDENS the answer (no package is every package, no type is every type). The
2592+
* list's `id` and `object` are judged a step later, in the list chain
2593+
* ({@link refuseBracketedListFilter}).
2594+
*/
2595+
const META_BRACKETED_FILTERS: Readonly<Partial<Record<MetaQueryArityDoor, readonly MetaBracketedFilter[]>>> = Object.freeze({
2596+
list: Object.freeze([
2597+
{ param: 'package', names: 'package', takes: `${PACKAGE_ID_TAKES} ?package=ID`, served: 'list', unscoped: 'list across every package' },
2598+
] as const),
2599+
'book-tree': Object.freeze([
2600+
{ param: 'package', names: 'package', takes: `${PACKAGE_ID_TAKES} ?package=ID`, served: 'tree', unscoped: 'read the tree across every package' },
2601+
] as const),
2602+
drafts: Object.freeze([
2603+
{ param: 'packageId', names: 'package', takes: `${PACKAGE_ID_TAKES} ?packageId=ID`, served: 'list', unscoped: 'list the drafts of every package' },
2604+
{ param: 'type', names: 'metadata type', takes: 'one metadata type, spelled ?type=TYPE', served: 'list', unscoped: 'list the drafts of every type' },
2605+
] as const),
2606+
});
2607+
2608+
/**
2609+
* The answer of an arity door to a BRACKETED spelling of one of its narrowing
2610+
* filters ({@link META_BRACKETED_FILTERS}): `?package[]=ID` or `?package[0]=ID`
2611+
* on the list and the book tree, `?packageId[]=ID` or `?type[]=TYPE` on
2612+
* `_drafts` — any key that opens `param[`. A client that serialises arrays
2613+
* qs-style sends it; every adapter hands the key through as spelled
2614+
* (`readQuery` in `plugin-hono-server`, `readDispatchQuery` in
2615+
* `@objectstack/hono`), so the door, which reads `query[param]`, read no
2616+
* filter, and a caller who named ONE package (or one type) was answered across
2617+
* every package (or type). `400 VALIDATION_ERROR`, rule `bracketed-parameter`,
2618+
* in the list chain's narrowing-filter frame ({@link listFilterRefusalMessage}),
2619+
* naming the key as sent; beside a plain spelling too (two spellings of one
2620+
* filter). Asked at the door's entry, before any read, by both transports:
25832621
* {@link metaQueryArityRefusal} for the dispatcher, after
25842622
* `refuseRepeatedQueryParams` for `RestServer`.
25852623
*
25862624
* Every by-name `/meta` door (the item read, `/layers`, the save, the reset,
2587-
* `/publish`) and the diagnostics sweep already refuse the key: it is not in
2588-
* their closed set (route rule 5). `_drafts` and `state` read no `package`.
2625+
* `/publish`) and the diagnostics sweep already refuse such a key: it is not in
2626+
* their closed set (route rule 5).
25892627
*/
2590-
export function metaBracketedPackageRefusal(door: MetaQueryArityDoor, query: unknown): MetaItemQueryRefusal | undefined {
2591-
if (!META_QUERY_ARITY_DOORS[door].includes('package')) return undefined;
2592-
const key = bracketedKeyOf(query, 'package');
2593-
if (key === undefined) return undefined;
2594-
const tree = door === 'book-tree';
2595-
return {
2596-
status: 400,
2597-
code: 'VALIDATION_ERROR',
2598-
message: listFilterRefusalMessage(
2599-
key, 'package', "the 'package' filter takes exactly one package id, spelled ?package=ID",
2600-
"a bracketed 'package' key", tree ? 'tree' : 'list',
2601-
tree ? 'read the tree across every package' : 'list across every package',
2602-
),
2603-
rule: 'bracketed-parameter',
2604-
};
2628+
export function metaBracketedFilterRefusal(door: MetaQueryArityDoor, query: unknown): MetaItemQueryRefusal | undefined {
2629+
for (const filter of META_BRACKETED_FILTERS[door] ?? []) {
2630+
const key = bracketedKeyOf(query, filter.param);
2631+
if (key === undefined) continue;
2632+
return {
2633+
status: 400,
2634+
code: 'VALIDATION_ERROR',
2635+
message: listFilterRefusalMessage(
2636+
key, filter.names, `the '${filter.param}' filter takes exactly ${filter.takes}`,
2637+
`a bracketed '${filter.param}' key`, filter.served, filter.unscoped,
2638+
),
2639+
rule: 'bracketed-parameter',
2640+
};
2641+
}
2642+
return undefined;
26052643
}
26062644

26072645
/**

‎packages/rest/src/meta-item-read-routes.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,7 @@ export function registerMetaItemReadRoutes(this: MetaItemReadRouteHost, scope: M
386386
// A bracketed `package` key (`?package[]=`) is read by no
387387
// binding below, so it scoped nothing: refused here, by the
388388
// decision the dispatcher's twin asks too.
389-
const bracketedPackage = metaReadGate.metaBracketedPackageRefusal('book-tree', req.query);
389+
const bracketedPackage = metaReadGate.metaBracketedFilterRefusal('book-tree', req.query);
390390
if (bracketedPackage) {
391391
res.status(bracketedPackage.status).json({
392392
error: { code: bracketedPackage.code, message: bracketedPackage.message },

0 commit comments

Comments
 (0)