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
2 changes: 1 addition & 1 deletion .changeset/undeclared-query-params.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
5 changes: 0 additions & 5 deletions src/Query.filter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down
2 changes: 1 addition & 1 deletion src/internal/codecs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ export const nest = (flat: { readonly [key: string]: unknown }): Record<string,
// No bare key holds the name, so an own entry under it is a group this
// loop made.
const group = Option.getOrElse(Record.get(nested, name), () => {
const made: Record<string, unknown> = {};
const made = {};
define(nested, name, made);
return made;
}) as Record<string, unknown>;
Expand Down
Loading