Repository navigation
fix: keep credentials out of filter and sort allowlists; read numeric keys canonically - #612
Merged
Merged
Conversation
…numeric keys only from canonical decimal text A field that declares a view.password is now left out of the generated filter and sort allowlists in every port, so a client cannot probe a credential by filtering or sorting on it; an explicit request answers the existing invalid_filter_field / invalid_sort 400. Covered by one shared api-contract scenario and a test per port. The TypeScript, Java and Python ObjectManagers now read a numeric primary key from text only in canonical decimal form (no 0x1, 1e0, +1, whitespace, leading zero or negative zero), with each runtime's existing bad-key error. Also corrects the grid-proof line count in the CHANGELOG.
…runtime-ts closure
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What Changed
view.password), including a shared column of a single-table (TPH) hierarchy. The filter type, OpenAPI parameters and agent UI page leave them out too. A request naming one gets the existing400 invalid_filter_fieldorinvalid_sort. The change lands in the TypeScript, C#, Java, Kotlin and Python generators. In Java, Kotlin and C# the sort allowlist previously listed every scalar field, so routes for models with a credential change: regenerate. Covered by the sharedsecret-fields/api-contract scenarios and a test per port.0x1,1e0,+1, whitespace, leading zeros and negative zero are refused with each runtime's existing bad-key error:InvalidKeyError/400 invalid_idin TypeScript,IllegalArgumentExceptionfor Java ref ids,ValueErrorin Python. The check walks characters, with no regex. String and uuid keys are unchanged.docs/features/metadata-driven-runtime.md.Validation
Risk Assessment
✅ Low: The credential allowlist and canonical-key changes trace correctly in every port. The round-6 TPH sibling-credential scenario is wired into all five generated-lane harnesses, and I found no source-backed defect.
Testing
Baseline
scripts/ci-local.sh --affected --strict-toolchainsalready passed at the target commit and covered broad regression. Driven live: (1) a generated TypeScript API against a real Postgres testcontainer refuses filter and sort on a credential with invalid_filter_field / invalid_sort, and the TPH sibling-credential rule holds on base and subtype routes, 4 passing; (2) a real TypeScript ObjectManager mounted on Fastify answers 400 invalid_id for 0x1, 1e0, +1, whitespace, trailing dot, leading zero, negative zero and an unsafe integer, and 200 for canonical 1 and 9007199254740991. The Python key-text pytest file passed (44), but in-process only, so it is not counted as live. Java, Kotlin, Python and C# credential allowlists were not driven live here. The CHANGELOG line count is documentation-only with no runtime surface. Overall: the three live scenarios pass. Evidence logs are in the evidence directory.Evidence: TS generated secret-fields filter/sort and TPH credential refusal, live Postgres testcontainer (bun test, 4 pass)
Evidence: TS canonical key text refused on real Fastify ObjectManager mount (400 invalid_id per non-canonical id)
Evidence: Python ObjectManager numeric key-text pytest (44 passed, in-process)
Pipeline
Updates from git push no-mistakes
✅ **Intent** - passed
✅ No issues found.
🔧 **Rebase** - 1 issue found → auto-fixed ✅
docs/CONFORMANCE.md- merge conflict rebasing onto origin/main🔧 Fix applied.
✅ Re-checked - no issues remain.
✅ **Review** - findings resolved; 1 info (currency-key note) not changed
InvalidKeyError/undefined; Python refuses the infinity case; each site has a test)server/typescript/packages/runtime-ts/src/canonical-key.ts:47- Canonical text is accepted without a range check, so two different canonical key texts can still name one row in TypeScript.isCanonicalIntegerandisCanonicalDecimalaccept any digit string, andcoercePkValue(object-manager.ts:587-597),parseIdandcoerceIdForColumn(drizzle-fastify/util.ts) then callNumber(). For afield.longkey,9007199254740992and9007199254740993both become 9007199254740992, which is the same class of problem the change set out to close. A canonical string of more than 308 digits becomesInfinityfor a double or float key. Java'sKeyText.coercerefuses both cases: it usesLong.parseLongand rejects an infinite double or float. Python'sint()is exact. Smallest fix: make the TS readers refuse an integer thatNumber.isSafeIntegerrejects, or a non-finite result, with the sameInvalidKeyErrororundefined. This adds a rule beyond canonical form, so it needs the author's sign-off. The sibling sites areobject-manager.ts:591and:595,util.tsparseId, andutil.tscoerceIdForColumn(number branch). Python's float and double branch atobject_manager.py_coerce_key_valuehas the same infinity case.server/python/src/metaobjects/runtime/object_manager.py:1140- Cross-runtime gap onfield.currencykeys. Java'sKeyText.isNumericincludesCurrencyFieldand refuses non-canonical text such as01or1. TypeScript'sINTEGER_SUBTYPESand Python's_KEY_INT_SUBTYPESleave currency out, so currency key text still goes through the old lenient path (Python's_INT_TEXT, which allows whitespace, and TS's raw string). A currency primary key is unlikely, so this is low impact. If it matters, addFIELD_SUBTYPE_CURRENCYto the integer set in TS (object-manager.ts:579) and Python (object_manager.py:1141).🔧 Fix applied.
2 issues (1 warning, 1 info) still open:
server/python/src/metaobjects/runtime/object_manager.py:1140- Cross-runtime gap onfield.currencykeys. Java'sKeyText.isNumericincludesCurrencyFieldand refuses non-canonical text such as01or1. TypeScript'sINTEGER_SUBTYPESand Python's_KEY_INT_SUBTYPESleave currency out, so currency key text still goes through the old lenient path (Python's_INT_TEXT, which allows whitespace, and TS's raw string). A currency primary key is unlikely, so this is low impact. If it matters, addFIELD_SUBTYPE_CURRENCYto the integer set in TS (object-manager.ts:579) and Python (object_manager.py:1141).canonical-key.tsanderrors.ts)examples/showcase/codegen/runtime/drizzle-fastify/util.ts:7- The committed ejected runtime copies inexamples/showcaseandexamples/advanced-modelingare broken and stale.drizzle-fastify/util.ts:7imports../canonical-key.js,drizzle-fastify/route-error-handler.ts:35imports../errors.js, andconstraint-errors.ts:30imports./errors.js.codegen/runtime/holds neithercanonical-key.tsnorerrors.tsin either example (lsshows only constraint-errors, decimal-wire, drizzle-fastify/, duration-wire, route-errors, sql-dialect, timestamp-wire and wire-format). Those imports cannot resolve.meta ejectcopies the transitive closure of the package's relative imports, so a fresh eject would add both files. These copies were edited by hand or partially regenerated.util.ts:64in both examples also still readsNumber.isFinite(Number(raw)), while the package has!Number.isNaN(Number(raw))after the fix round (de75062). So the copies are not verbatim, which defeats the 'byte comparison against the package' contract described incli/src/lib/runtime-eject.ts. Fix: re-run the example regeneration (scripts/regen-showcase.ts, ormeta eject routes entityper example) so both examples getcanonical-key.ts,errors.tsand the currentutil.ts. Sibling sites:examples/advanced-modeling/codegen/runtime/drizzle-fastify/util.ts:7,.../drizzle-fastify/route-error-handler.ts:35,.../constraint-errors.ts:30, andexamples/showcase/codegen/runtime/drizzle-fastify/route-error-handler.ts:35and.../constraint-errors.ts:30.🔧 Fix applied.
2 issues (1 warning, 1 info) still open:
server/python/src/metaobjects/runtime/object_manager.py:1140- Cross-runtime gap onfield.currencykeys. Java'sKeyText.isNumericincludesCurrencyFieldand refuses non-canonical text such as01or1. TypeScript'sINTEGER_SUBTYPESand Python's_KEY_INT_SUBTYPESleave currency out, so currency key text still goes through the old lenient path (Python's_INT_TEXT, which allows whitespace, and TS's raw string). A currency primary key is unlikely, so this is low impact. If it matters, addFIELD_SUBTYPE_CURRENCYto the integer set in TS (object-manager.ts:579) and Python (object_manager.py:1141).isCanonicalDecimalnow also requires a safe integer for integer-shaped text, with tests forparseId,coerceIdForColumn,rawIdLiteraland a decimal key)server/typescript/packages/runtime-ts/src/canonical-key.ts:50- Round-1 finding review-1 (user chose to fix) is only half closed. Fix round 2 (de75062) addedNumber.isSafeIntegertoisCanonicalIntegerandNumber.isFinitetoisCanonicalDecimal. ButisCanonicalDecimalstill accepts integer-shaped text without a safe-integer check.parseId('9007199254740993')andcoerceIdForColumn({dataType:'number'}, '9007199254740993')both passisCanonicalDecimal(finite) and returnNumber(raw)= 9007199254740992. So two different canonical id texts (...992,...993) still name one row on every HTTP mount that reads a numeric column id (drizzle-fastify/index.ts:288,380,429; hono/index.ts:281,347,384; mount-read-only.ts fastify:316 and hono:278; mount-m2m.ts:102,113), andrawIdLiteralemits the rounded literal on raw-SQL views. This is the class the change set out to close. The new test only covers the unsafe-integer case throughisCanonicalInteger; itsisCanonicalDecimalcases cover the infinite case only. Smallest fix: inisCanonicalDecimal, when the text has no., also requireisCanonicalInteger(text). Sibling:coercePkValueDECIMAL_SUBTYPES branch (object-manager.ts:594-596) takes the sameisCanonicalDecimalforfield.decimal, so an integer-valued decimal key past 2^53 also rounds. Add test cases forcoerceIdForColumn/parseId/rawIdLiteralwith9007199254740993.🔧 Fix applied.
2 issues (1 warning, 1 info) still open:
server/python/src/metaobjects/runtime/object_manager.py:1140- Cross-runtime gap onfield.currencykeys. Java'sKeyText.isNumericincludesCurrencyFieldand refuses non-canonical text such as01or1. TypeScript'sINTEGER_SUBTYPESand Python's_KEY_INT_SUBTYPESleave currency out, so currency key text still goes through the old lenient path (Python's_INT_TEXT, which allows whitespace, and TS's raw string). A currency primary key is unlikely, so this is low impact. If it matters, addFIELD_SUBTYPE_CURRENCYto the integer set in TS (object-manager.ts:579) and Python (object_manager.py:1141).server/typescript/packages/codegen-ts/src/templates/entity-file.ts:231-renderFilterType(entity)is the one call site that still omits the loaded root. The other four sites (reference/entity.ts:148, projection-decl.ts:222, value-object-file.ts:69 and :99) now passctx.loadedRoot. Without itcredentialFieldNamessees the entity alone. So when a TPH sibling subtype marks a shared column as aview.password, the clientFiltertype for this entity still offers that column as filterable and sortable. The server allowlist built on the lines just above (renderFilterAllowlist(entity, undefined, ctx)) refuses it with 400. The CHANGELOG says the client filter type leaves credentials out.renderEntityFileis a live path: theentity-filegenerator (generators/entity-file.ts:48) and the read-view branch of reference/entity.ts:130 both call it. This is a client-type inconsistency only; the server still refuses the request, so no leak. Same omission in the test-generators copy: server/typescript/packages/test-generators/src/templates/entity-file.ts:231. Fix: passctx.loadedRootas the third argument in both.🔧 Fix applied.
3 issues (1 warning, 2 infos) still open:
server/python/src/metaobjects/runtime/object_manager.py:1140- Cross-runtime gap onfield.currencykeys. Java'sKeyText.isNumericincludesCurrencyFieldand refuses non-canonical text such as01or1. TypeScript'sINTEGER_SUBTYPESand Python's_KEY_INT_SUBTYPESleave currency out, so currency key text still goes through the old lenient path (Python's_INT_TEXT, which allows whitespace, and TS's raw string). A currency primary key is unlikely, so this is low impact. If it matters, addFIELD_SUBTYPE_CURRENCYto the integer set in TS (object-manager.ts:579) and Python (object_manager.py:1141).server/java/codegen-spring/src/main/java/com/metaobjects/generator/spring/SpringFilterAllowlistGenerator.java:144- The credential exclusion on the filter allowlists is per-field only in Java, Kotlin, Python and C#. TypeScript also excludes a column that a sibling subtype of the same single-table (TPH) hierarchy marks as a credential (credentialFieldNames, filter-shared.ts, with a test). In the other four ports a TPH base allowlist is the union of base and subtype columns, deduplicated by name (out.putIfAbsent). Take two subtypes that both declaretoken. AThing has it as a plain@filterablecolumn. BThing has it asview.password. The generator skips BThing'stokenas a credential but keeps AThing's.tokentherefore stays on the base allowlist, andGET /things?filter[token][like]=a%probes the shared column that holds BThing's secret. The intent says the allowlists are 'built without credentials in every port', and the TS side already treats this model as in scope. Same invariant, other sites: KotlinFilterAllowlistGenerator.kt:~201 (putIfAbsent), filter_allowlist_generator.py:~223 (theaddclosure; the outcome depends on declaration order), FilterAllowlistGenerator.cs:~152, and the sort-field loops at SpringControllerGenerator.java:~1162 and KotlinSpringControllerGenerator.kt:~931. The remedy extends the per-port change to a hierarchy-wide credential set. Whether the other ports should match TS here, or the TS hierarchy rule should be narrowed, is the author's decision.CHANGELOG.md:176- The CHANGELOG entry for canonical key text does not mention a behavior the TS fix rounds added. TypeScript now also refuses an integer key that is not a safe integer (beyond ±2^53,isCanonicalIntegerandisCanonicalDecimalfor integer-shaped text) and a non-finite decimal key. Java usesLong.parseLongand accepts up toLong.MAX_VALUE. A TSfield.longkey from 2^53 to 2^63-1 used to round silently to a different row. It is nowInvalidKeyError(HTTP400 invalid_id). Add one sentence so the cross-runtime difference is recorded.🔧 Fix applied.
2 issues (1 warning, 1 info) still open:
server/python/src/metaobjects/runtime/object_manager.py:1140- Cross-runtime gap onfield.currencykeys. Java'sKeyText.isNumericincludesCurrencyFieldand refuses non-canonical text such as01or1. TypeScript'sINTEGER_SUBTYPESand Python's_KEY_INT_SUBTYPESleave currency out, so currency key text still goes through the old lenient path (Python's_INT_TEXT, which allows whitespace, and TS's raw string). A currency primary key is unlikely, so this is low impact. If it matters, addFIELD_SUBTYPE_CURRENCYto the integer set in TS (object-manager.ts:579) and Python (object_manager.py:1141).secret-fieldsand runs in the generated lane of all five ports)fixtures/api-contract-conformance/secret-fields/scenarios/filter-sort-refuses-credential.yaml:1- Recorded round-5 decision required ONE shared scenario in fixtures/api-contract-conformance/secret-fields for the TPH sibling-credential rule: a TPH base with two subtypes that both declaretoken, one plain@filterable/@sortableand oneview.password. A filter and a sort ontokenmust answer400 invalid_filter_field/invalid_sorton the base route and on the plain subtype's route. Commit e3a5819 adds no fixture or scenario. It adds only per-port codegen unit tests, which are string checks on generated output.docs/CONFORMANCE.mdcounts and the secret-fields README are unchanged, though CHANGELOG now says the rule holds 'in every port'. No cross-port HTTP corpus gates the hierarchy-wide rule. The corpus has a singleAccountmodel and each port's harness hard-codes it (e.g.InMemoryAccountRepositorySource.java,GeneratedSecretFieldsControllerHarness.kt,generated_secret_fields_app.py,SecretFieldsGeneratedServerFactory.cs,api-contract-secret-fields-generated-server.ts), so the scenario needs a second model and harness work in five ports. The remedy extends harness machinery, so the author or user must confirm the scope or accept the unit tests as sufficient. The generator logic itself traces correct: base and subtype allowlists in Java, Kotlin, Python and C# droptokenin both declaration orders.🔧 Fix applied.
1 info still open:
server/python/src/metaobjects/runtime/object_manager.py:1140- Cross-runtime gap onfield.currencykeys. Java'sKeyText.isNumericincludesCurrencyFieldand refuses non-canonical text such as01or1. TypeScript'sINTEGER_SUBTYPESand Python's_KEY_INT_SUBTYPESleave currency out, so currency key text still goes through the old lenient path (Python's_INT_TEXT, which allows whitespace, and TS's raw string). A currency primary key is unlikely, so this is low impact. If it matters, addFIELD_SUBTYPE_CURRENCYto the integer set in TS (object-manager.ts:579) and Python (object_manager.py:1141).✅ **Test** - passed
✅ No issues found.
scripts/ci-local.sh --affected --strict-toolchainsbun test test/api-contract-secret-fields.test.ts -t "filter-sort-refuses-credential|tph-sibling-credential|sibling"in server/typescript/packages/integration-tests (4 pass, 0 fail; 2 layouts x 2 scenarios; one Postgres testcontainer per scenario via Docker)Live script (in $DEV_SCRATCH, removed after): real runtime-ts ObjectManager + in-memory driver + FastifymountCrudRoutes, GET /posts/<id> for 1, 0x1, 1e0, +1, ' 1', '1 ', 01, -0, 1., 9007199254740993, 9007199254740991, abcpython3 -m pytest -p no:cacheprovider tests/runtime/test_object_manager_numeric_key_text.pyin server/python (44 passed; in-process unit-level, not live)Checked worktree clean after testing (no artifacts left in worktree); no containers started by this run remained (other sessions' containers untouched)🔧 **Document** - 1 issue found → auto-fixed (2) ✅
CHANGELOG.md:177- The ObjectManager key-text rule (Java/Python/TS findById, update, delete and load take only canonical decimal text, pass the decimal spelling) is recorded only in the CHANGELOG release note. No durable owner doc states it. Candidate owners: spec/wire-format.md or docs/features/api-contract.md. Out of scope for this doc-repair pass, which is limited to stale facts, so left as one follow-up.🔧 Fix applied.
3 infos still open:
docs/features/api-contract.md:221- Round-1 user decision (docs-1) was not yet applied in the target commit. Added the ObjectManager key-text rule to the malformed-id row: TypeScript, Java and Python ObjectManagers read a numeric key passed as text to findById, update, delete and load by canonical decimal form only, so the caller passes the decimal spelling; a string or uuid key is untouched. Verified the rule against server/typescript/packages/runtime-ts/src/canonical-key.ts. Resolved, so no open item remains here.docs/features/api-contract.md:689- The credentials paragraph said the allowlist is built without a credential but did not state the single-table rule. Added one clause: on a TPH hierarchy a column one subtype marks as a credential is on no allowlist of the base or any subtype. Verified against the C# FilterAllowlistGenerator and RoutesGenerator, which call TphPlanBuilder.HierarchyCredentialNames. Resolved.docs/features/own-your-codegen.md:390- Pre-existing gap, not caused by this change: the routes eject row lists the runtime-ts files copied into codegen/runtime/ but omits decimal-wire.ts, duration-wire.ts, sql-dialect.ts and wire-format.ts, which drizzle-fastify imports transitively. This change added canonical-key.ts and errors.ts to the row. A full closure list is a wider edit to an ownership table, so I left the rest as is.🔧 Fix applied.
✅ Re-checked - no issues remain.
✅ **Lint** - passed
✅ No issues found.
✅ **Push** - passed
✅ No issues found.