Skip to content

Commit b2be4d2

Browse files
authored
fix: generated create routes drop server-owned input across ports (1.2.x security) (#568)
* fix: generated create routes store only client-settable fields (1.2.x security) Python 1.2.1 stopped its generated routes from handing raw request input to the repository. The same audit found related create-path holes in 1.2.0 in the other four ports; this closes each in its own idiom. Server-owned values are dropped silently, never answered with 400. - Java (codegen-spring): create strips a generated id, readOnly and derived fields; a TPH per-subtype create also strips the body discriminator and sibling-subtype fields. - Kotlin (codegen-kotlin): create skips readOnly/derived columns; a TPH per-subtype create writes only the route subtype's own columns. - C# (MetaObjects.Codegen): every readOnly property shape gets a private setter; create resets a generated id, the TPH discriminator and M:N navigations before Add. - TypeScript (codegen-ts): the update schema omits primary-key fields, so PUT/PATCH can no longer re-key a row with an assigned key. Proof: new shared api-contract scenarios (core + TPH input-server-owned, TPH foreign discriminator) and a readOnly `role` field in secret-fields, run in every port's generated lane and the reference lanes; a new `unset` assertion key in all five harnesses. In-memory test repositories now store what they are handed, so the scenarios fail on the 1.2.0 generators. Proposed versions (not published): npm 1.2.2, NuGet 1.2.2, Maven 8.2.2; PyPI unchanged at 1.2.1. metamodelVersion unchanged. * fix: keep a @required readOnly field creatable in C# and Java generated create Pre-gate review follow-ups to the 1.2.x create-input patch: - C#: the required-key check skips readOnly fields (the private setter never binds them), and create validation ignores a violation naming only a @required readOnly member, as Java's SERVER_OWNED_ON_CREATE does. - Java: the create-validation server-owned set covers every DTO component, so a nulled readOnly or derived value-object column no longer 400s. - TypeScript: drop the now-dead PK guard in the update-schema nullable arm and list the PK rule in updateSchemaFields' doc comment. * no-mistakes(review): apply reviewer inline fixes * no-mistakes(review): Kotlin readOnly create fix + C# reset skip * no-mistakes(document): docs: finish stale corpus counts from input fix
1 parent 783ac21 commit b2be4d2

92 files changed

Lines changed: 1359 additions & 222 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎CHANGELOG.md‎

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,52 @@ here.**
1010

1111
## [Unreleased]
1212

13+
_Proposed as npm `1.2.2` (all 14 `@metaobjectsdev/*` packages), NuGet `1.2.2` and Maven Central
14+
`8.2.2`; `1.2.1` was spent by the Python-only release. PyPI stays at `1.2.1`: no Python product
15+
file changes. No vocabulary or `metamodelVersion` change._
16+
17+
### Security
18+
19+
- **Generated create routes in Java, Kotlin and C#, and TypeScript updates, let a client write
20+
fields it must never set.** The same class of hole the Python 1.2.1 patch closed, found by an
21+
audit of the other four ports after it. Every adopter serving these generated routes should
22+
upgrade and regenerate; an ejected (owned) generator needs the same change made by hand.
23+
24+
- **Java (`codegen-spring`).** The create route passed the bound DTO to the repository as
25+
sent, so a client `id` on a generated key and a `@mutability: readOnly` or derived field
26+
reached it. On a TPH per-subtype route the body's discriminator and a sibling subtype's
27+
columns did too. The route now rebuilds the DTO with each of those components set to null
28+
before the repository call; the route's subtype still comes from the URL. A `@required`
29+
`readOnly` or derived value-object column no longer fails create validation once nulled.
30+
- **Kotlin (`codegen-kotlin`).** The create route wrote `readOnly` and derived columns from the
31+
body, and a TPH per-subtype route wrote a sibling subtype's columns. It now writes only the
32+
route subtype's own settable columns.
33+
- **C# (`MetaObjects.Codegen`).** The create route bound the EF Core entity from the body, so a
34+
client `id` on a generated key was inserted, a TPH create stored the body's discriminator (a
35+
POST to the Bridge route could create a Copay row), and a TPH subtype's `readOnly` field and
36+
an M:N navigation graph were written. The route now resets the generated key and the
37+
discriminator to their defaults and empties the M:N navigations before `Add`, and a
38+
`readOnly` property of every shape, a TPH subtype's included, has a private setter, which
39+
System.Text.Json does not bind. A `@required` `readOnly` field is therefore neither demanded
40+
of the create body nor held to its `[Required]` there, so such an entity stays creatable.
41+
- **TypeScript (`codegen-ts`).** The `<Entity>UpdateSchema` kept an assigned (non-generated)
42+
primary key, so a PUT or PATCH could re-key the row. The update schema now leaves out every
43+
primary-key field; the insert schema still takes an assigned key, which is the caller's on
44+
create.
45+
46+
Each of these values is dropped silently, never answered with a 400. A key the model does not
47+
declare is dropped silently in TypeScript, C# and Python. In Java and Kotlin the answer to an
48+
undeclared key is the host's Jackson `ObjectMapper`'s: Spring Boot's default ignores it, and a
49+
plain `ObjectMapper` (`FAIL_ON_UNKNOWN_PROPERTIES` on) answers 400. This patch leaves that as
50+
it was.
51+
52+
Gated by the shared api-contract scenarios `input-server-owned-dropped`,
53+
`tph-input-server-owned-dropped` and `tph-input-foreign-discriminator-dropped`, and a `readOnly`
54+
`role` on the `secret-fields` corpus, in every port's generated lane and in the reference lanes.
55+
Python's generated TPH routes answer a foreign body discriminator with a 400 rather than
56+
dropping it (nothing is stored); its runner skips that one scenario, recorded in the Python
57+
codegen `KNOWN_GAPS.md`.
58+
1359
## [1.2.1] — Python only
1460

1561
_PyPI `1.2.1` only. npm, NuGet and Maven Central stay at `1.2.0` (`8.2.0`): none of them has a

‎bun.lock‎

Lines changed: 14 additions & 14 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎client/web/packages/react/package.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@metaobjectsdev/react",
3-
"version": "1.2.0",
3+
"version": "1.2.2",
44
"description": "React runtime for metaobjects: useEntityForm hook and CurrencyInput component.",
55
"type": "module",
66
"main": "./dist/index.js",

‎client/web/packages/runtime-web/package.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@metaobjectsdev/runtime-web",
3-
"version": "1.2.0",
3+
"version": "1.2.2",
44
"description": "Pure framework-agnostic browser core for metaobjects: currency, filter URL serialization, fetcher contract types.",
55
"type": "module",
66
"main": "./dist/index.js",

‎client/web/packages/tanstack/package.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@metaobjectsdev/tanstack",
3-
"version": "1.2.0",
3+
"version": "1.2.2",
44
"description": "TanStack runtime for metaobjects: EntityFetcherProvider, EntityGrid, default cell renderers.",
55
"type": "module",
66
"main": "./dist/index.js",

‎docs/CONFORMANCE.md‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ regenerate with `ls -d fixtures/<corpus>/*/ | wc -l` for directory-shaped corpor
3636
| [`fixtures/extract-conformance/`](../fixtures/extract-conformance/) | 58 | ✓ | ✓ | inherits the shared JVM engine | ✓ | ✓ |
3737
| [`fixtures/output-prompt-conformance/`](../fixtures/output-prompt-conformance/) | 17 | ✓ | ✓ | ✓ | ✓ | ✓ |
3838
| [`fixtures/persistence-conformance/`](../fixtures/persistence-conformance/) | 59 (53 query + 6 migration) | all 59; the 24 `report-*` and the `-15` decimal scenarios also on SQLite, MySQL and D1, `decimal-exact` also on MySQL (a scenario's `engines:` key is exact) | 53 query (migrations TS-only, ADR-0015); the `report-*` and `engines:` scenarios also on SQLite and MySQL | 53 query (via Exposed); the `report-*` and `engines:` scenarios also on SQLite and MySQL | 53 query; the `report-*` and `engines:` scenarios also on SQLite and MySQL | 53 query (pg8000); the `report-*` and `engines:` scenarios also on SQLite (`sqlite3`) and MySQL (PyMySQL) |
39-
| [`fixtures/api-contract-conformance/`](../fixtures/api-contract-conformance/) | 119 (31 core + 10 tph + 9 m2m + 5 jsonb + 2 write-through + 2 secret-fields + 12 projection + 37 report + 11 decimal) | ✓ (Fastify reference + generated lane); `report/` and `decimal/` also on SQLite, MySQL and D1 | ✓ (embedded HTTP + JDBC); `report/` and `decimal/` generated controllers over OMDB on Postgres, SQLite and MySQL | ✓ (embedded HTTP + Exposed); `report/` and `decimal/` also on SQLite and MySQL | ✓ (Kestrel + Npgsql); `report/` and `decimal/` also on SQLite and MySQL | ✓ (FastAPI + pg8000); `report/` and `decimal/` also on SQLite and MySQL |
39+
| [`fixtures/api-contract-conformance/`](../fixtures/api-contract-conformance/) | 122 (32 core + 12 tph + 9 m2m + 5 jsonb + 2 write-through + 2 secret-fields + 12 projection + 37 report + 11 decimal) | ✓ (Fastify reference + generated lane); `report/` and `decimal/` also on SQLite, MySQL and D1 | ✓ (embedded HTTP + JDBC); `report/` and `decimal/` generated controllers over OMDB on Postgres, SQLite and MySQL | ✓ (embedded HTTP + Exposed); `report/` and `decimal/` also on SQLite and MySQL | ✓ (Kestrel + Npgsql); `report/` and `decimal/` also on SQLite and MySQL | ✓ (FastAPI + pg8000); `report/` and `decimal/` also on SQLite and MySQL |
4040
| [`fixtures/decimal-wire/`](../fixtures/decimal-wire/) | 1 vector file (format, parse, filter operand, 15-digit read) | ✓ (`runtime-ts` and the generated helper) | ✓ (`CanonicalDecimal`) | ✓ (the generated wire file) | ✓ (`DecimalWire`) | ✓ (`decimal_wire`) |
4141
| [`fixtures/validation-conformance/`](../fixtures/validation-conformance/) | 42 cases | ✓ (generated Zod + run-time `runValidators`) | ✓ | ✓ | ✓ | ✓ (generated Pydantic + run-time `run_validators`) |
4242
| [`fixtures/registry-conformance/`](../fixtures/registry-conformance/) | 1 canonical manifest | ✓ (reference emitter) | ✓ | ✓ | ✓ | ✓ |
@@ -366,9 +366,9 @@ REAL, a MySQL `DECIMAL` keeps its scale, a MySQL `DATETIME` is the UTC wall cloc
366366
`report-relative-date` carries a per-engine seed (`seed-data-engine`). `op: relate` and the
367367
write ops stay Postgres-only. See [features/reporting.md](features/reporting.md#what-the-corpus-gates).
368368

369-
### `fixtures/api-contract-conformance/` (119)
369+
### `fixtures/api-contract-conformance/` (122)
370370

371-
All 119 scenarios → [features/api-contract.md](features/api-contract.md) (cross-port
371+
All 122 scenarios → [features/api-contract.md](features/api-contract.md) (cross-port
372372
REST API URL grammar + JSON wire format). Verifies every backend's emitted CRUD
373373
routes answer identically over HTTP — list / get / create / patch+put / delete,
374374
plus pagination (`limit`/`offset`), sort (`sort=field:dir`), the `withCount=1`
@@ -378,12 +378,12 @@ status codes.
378378
The corpus also covers the 9 cross-port filter operators (`eq`, `ne`, `gt`,
379379
`gte`, `lt`, `lte`, `in`, `like`, `isNull`) plus the implicit-AND combinator
380380
and 2 error shapes (`invalid_filter_field` / `invalid_filter_op`) under the
381-
URL grammar `?filter[<field>][<op>]=<value>` (FR-009). On top of the 31 core
382-
scenarios the corpus carries eight sub-corpora — `tph/` (10, single-table
381+
URL grammar `?filter[<field>][<op>]=<value>` (FR-009). On top of the 32 core
382+
scenarios the corpus carries eight sub-corpora — `tph/` (12, single-table
383383
inheritance; a subtype decimal filters and refuses extra digits), `m2m/` (9 — 3 plain, 5 gating TPH x M:N together, the combination
384384
each corpus alone could not reach, and 1 pinning the collection-URL spelling),
385385
`jsonb/` (5, typed value-object columns; numbers inside them: a double stays a JSON number, a decimal is the canonical string),
386-
`write-through/` (2, table-write + view-read entities), `secret-fields/` (2, #484: a `@formExclude` or credential `view.password` field is ignored on create, PATCH and PUT, and a credential is never returned), `projection/` (12, a
386+
`write-through/` (2, table-write + view-read entities), `secret-fields/` (2, #484 + the 1.2.x input gate: a `@formExclude` or credential `view.password` field is ignored on create, PATCH and PUT, a credential is never returned, and a `@mutability: readOnly` field is ignored on write too), `projection/` (12, a
387387
read-only view answers reads and refuses writes with 405; a projection with no declared
388388
identity has no item route; a projection keyed on a field not named `id` is addressed by
389389
it, whether its identity names `@fields` or derives them; decimal and float fields filter), `decimal/` (11, ADR-0019 Amendment 1: a decimal, array element and undeclared-precision column included, is one
@@ -611,7 +611,7 @@ files into a real Cube.
611611
## Orphaned fixtures (tested but not yet documented)
612612

613613
The fixtures in the nine corpora mapped above (metamodel 421 + yaml 16 + verify 45
614-
+ render 18 + persistence 59 + api-contract 119 + source-resolution 25 + scope 10 +
614+
+ render 18 + persistence 59 + api-contract 122 + source-resolution 25 + scope 10 +
615615
dependency 37) each map to a feature doc, and so do the two requirement corpora, `shared-model-conformance` and the
616616
`cube-model` corpus, whose case lists live in their own READMEs. None are orphaned today. The remaining
617617
corpora in the totals table gate tooling contracts (registry manifests, provider

‎docs/features/generated-mutations.md‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,21 @@ but the semantics are one contract — call them **PATCH-1..7** (FR-035):
6666
- **PATCH-7 (verbs).** At the HTTP tier both `PATCH` and `PUT` route to the update
6767
handler with partial-merge semantics. True PUT-as-full-replace is out of scope.
6868

69+
**Create stores only what a client may set, in every port.** A generated create route
70+
never writes a client-sent value for a server-generated primary key (`@generation`
71+
`increment` or `uuid`), a `@mutability: "readOnly"` or `origin.*`-derived field, the TPH
72+
discriminator (a per-subtype route takes the subtype from the URL), a column only a
73+
sibling subtype declares, or (C#) an M:N navigation graph. Each is dropped silently, not
74+
answered with a 400. An assigned key (no `@generation`) is the caller's on create in
75+
TypeScript, C#, Java and Python, and on update it is the primary key like any other, so it
76+
is left out of the TypeScript `<Entity>UpdateSchema` too. (Kotlin's generated create is the
77+
exception: it never binds a declared key, assigned or not — `increment` is left to the
78+
column and a `uuid` key is minted app-side.) A key the entity does not declare is dropped in TypeScript,
79+
C# and Python; in Java and Kotlin that answer belongs to the host's Jackson
80+
`ObjectMapper` (Spring Boot's default ignores it, a plain `ObjectMapper` answers 400).
81+
Gated cross-port by `fixtures/api-contract-conformance/scenarios/input-server-owned-dropped.yaml`
82+
and the `tph/` and `secret-fields/` input scenarios.
83+
6984
The generated update does **not** guard against a concurrent write: two callers
7085
patching the same row both succeed, and the last one wins. Adding that guard is
7186
adopter-owned — see [Optimistic concurrency](#optimistic-concurrency-adopter-owned).

0 commit comments

Comments
 (0)