diff --git a/.changeset/undeclared-query-params.md b/.changeset/undeclared-query-params.md index 4ead55f5..aa9a1d92 100644 --- a/.changeset/undeclared-query-params.md +++ b/.changeset/undeclared-query-params.md @@ -2,6 +2,6 @@ "@thomasfosterau/effect-jsonapi": patch --- -**Security:** fixes a prototype-pollution vulnerability (CWE-1321) reachable through query parameters on endpoints whose query declares no family (e.g. `Endpoint.get` of a resource without relationships), and a request-triggerable 500 in the filter grammar for field names that collide with `Object.prototype` members. Versions 0.1.0–0.16.3 are affected; upgrade. +**Security:** fixes three defects reachable through query parameters; upgrade. A prototype-pollution vulnerability (CWE-1321) and a request-triggerable 500 on endpoints whose query declares no family (e.g. `Endpoint.get` of a resource without relationships) affect versions 0.1.0–0.16.3; a second request-triggerable 500, in the `filter: true` grammar for field names that collide with `Object.prototype` members, affects versions 0.13.0–0.16.3, the releases that ship that grammar. An endpoint whose query declares no family — `Endpoint.get(R)` for a resource with no relationships, or any `Query.schema(R, {})` — no longer passes undeclared query parameters through to the handler's `query` (typed `{}`). `Query.schema` now keeps only the keys it declares, whether or not it declares any, so such a query decodes (and encodes) to `{}` exactly as undeclared keys are already dropped by a query that declares something. That includes a name admitted by `Middleware.layerWith({ allowedQueryParameters })`, which now never reaches the decoded `query`, as documented. The bracket reshaper behind it writes every key as an own property and no longer throws on a bracket key whose name a bare key also holds. The `filter: true` grammar (and `Filter.normalise`) reads only a resource's own filterable fields, so any field name it does not declare is a 400 `Unknown filter field` on decode and an `InvalidFilter` on encode. Declared parameters decode and encode as before. diff --git a/src/Query.filter.test.ts b/src/Query.filter.test.ts index 6869658a..442a6611 100644 --- a/src/Query.filter.test.ts +++ b/src/Query.filter.test.ts @@ -669,11 +669,6 @@ describe("Query.Filter: rejections name the offending key", () => { ); }); - // `Resource.filterable` is a plain object, so a field name that is an - // `Object.prototype` member must read as undeclared, not as the inherited - // value (#260). - const inherited = ["constructor", "__proto__", "toString", "hasOwnProperty", "valueOf"]; - it.each(inherited)( "rejects a field named %s, an Object.prototype member, in every spelling", (name) => { diff --git a/src/internal/codecs.ts b/src/internal/codecs.ts index b6b84a65..fe39c01e 100644 --- a/src/internal/codecs.ts +++ b/src/internal/codecs.ts @@ -189,7 +189,7 @@ export const nest = (flat: { readonly [key: string]: unknown }): Record { - const made: Record = {}; + const made = {}; define(nested, name, made); return made; }) as Record;