Skip to content

tx: stacked bug fixes for 23 HTTP 500, wire/schema, VCL/ECL, and validation issues - #492

Open
jmandel wants to merge 23 commits into
HealthIntersections:mainfrom
jmandel:fix/fuzz-bugs-2026-12
Open

jmandel wants to merge 23 commits into
HealthIntersections:mainfrom
jmandel:fix/fuzz-bugs-2026-12

Conversation

@jmandel

@jmandel jmandel commented Dec 6, 2026

Copy link
Copy Markdown
Contributor

Summary

This PR fixes 26 bugs discovered via systematic terminology server fuzzing and differential testing against main (456744bf), covering HTTP 500 crashes, invalid JSON / FHIR schema violations, parameter/wire handling, VCL / ECL 2.2 / filter semantics, $expand, $validate-code, $lookup, $translate, $subsumes, and i18n formatting.

Every fix is structured as a standalone, self-contained, cherry-pickable commit paired with its own focused Jest regression test (tests/tx/fix-*.test.js) so individual commits can be reviewed, discussed, or cherry-picked independently with zero cross-commit entanglement.


Commit & Issue Index

Group A — HTTP 500 Crashes, Wire Safety & Parameter Validation

Commit Ref Area Summary Key Files
2976697a ISS-01 Search Handle repeated query params (AND semantics), non-string _search JSON (400 on object/array), and preserve repeated params in Bundle.link.url tx/workers/search.js, tests/tx/fix-iss01-search-params.test.js
ccbab800 ISS-02 $batch-validate-code Return HTTP 405 (Allow: POST) for GET /$batch-validate-code and HTTP 400 for malformed POST bodies instead of HTTP 500 TypeError tx/workers/batch-validate.js, tests/tx/fix-iss02-batch-validate-get.test.js
39f22d2f ISS-03 compose.lockedDate Pass status code 422 in checkNoLockedDate so ValueSet.compose.lockedDate returns HTTP 422 instead of HTTP 500 tx/workers/worker.js, tests/tx/fix-iss03-locked-date.test.js
8c9eed2f ISS-04 Parameters Reject parameter entries with >1 value[x] key or mixing value[x]/resource/part with HTTP 400 tx/library/parameter-types.js, tests/tx/fix-iss04-multi-value-param.test.js
aeacda6b ISS-05 OMOP Throw typed HTTP 422 too-costly Issue from OMOPServices.iterator() / nextContext() instead of raw Error (HTTP 500) tx/cs/cs-omop.js, tests/tx/fix-iss05-omop-iterator.test.js
96de664f ISS-08 VCL / SNOMED SCG Extract full Unicode code points (instead of single UTF-16 code units) in lexer diagnostics so astral characters (😀, 🩺) never emit lone surrogates (\ud83d / \ud83e) invalid under RFC 8259 vcl/vcl-parser.js, tx/sct/expressions.js, tests/tx/fix-iss08-surrogate-pairs.test.js
ff386ba5 ISS-09 Parameters Enforce 32-bit signed FHIR integer (-2147483648..2147483647), positiveInt (>= 1), and unsignedInt (>= 0) bounds with HTTP 400 tx/library/parameter-types.js, tests/tx/fix-iss09-int32-bounds.test.js
1d0c5b59 ISS-15 HTTP / JSON Intercept Express entity.parse.failed alongside entity.too.large so malformed application/json bodies return HTTP 400 application/fhir+json OperationOutcome instead of HTML tx/tx.js, tests/tx/fix-iss15-malformed-json.test.js
87f3d922 (live) HTTP / i18n Parse Accept-Language via Languages.fromAcceptLanguage(..., true, true) instead of LanguageDefinitions.parse() in requestLanguages() and buildParameters(), preventing HTTP 500 TypeError: languages is not iterable when clients (browsers, Node fetch) send Accept-Language: * or en-US on error paths tx/tx.js, tx/workers/worker.js, tests/tx/fix-accept-language-iterable.test.js

Group B — Core Terminology Semantics & Schema Conformance

Commit Ref Area Summary Key Files
fa08e6a0 ISS-10 $translate (R5) Map R4 target.equivalence to R5 relationship and strip equivalence on R5 responses (never emitting valueless {"name":"relationship"}) tx/workers/translate.js, tx/xversion/xv-conceptmap.js, tx/xversion/xv-parameters.js, tx/tx.js, tests/tx/fix-iss10-translate-r5-equiv.test.js
52e1b587 ISS-11 $lookup Omit description sub-part for displayless parent/child concepts instead of emitting invalid empty valueString: "" (ele-1) tx/cs/cs-cs.js, tests/tx/fix-iss11-lookup-empty-desc.test.js
6935ac7f ISS-12 $expand Fix doubled cs.system() + cs.system() typo and emit standard 'used-codesystem' instead of cs.contentMode() ("example") for non-complete package CodeSystems tx/workers/expand.js, tests/tx/fix-iss12-expand-example-cs.test.js
a9873489 ISS-16 $expand / $validate-code Evaluate compose.include / exclude entries carrying both concept and filter (e.g. VCL and-code-filter) as intersection instead of union, while preserving HL7 vcl-tests.json AST expectations tx/workers/expand.js, tx/workers/validate.js, tests/tx/fix-iss16-concept-filter-intersection.test.js
b308d03c ISS-17 VCL / $expand / $validate-code Honor R6 extension-ValueSet.compose.include.filter.op (of) emitted by vcl-parser.js for .property projection tx/workers/supplement-filters.js, tx/workers/expand.js, tx/workers/validate.js, tx/cs/cs-cs.js, tests/tx/fix-iss17-filter-op-of.test.js
01621fe2 ISS-18 Filters Add structural parent exists filter over nested CodeSystem.concept.concept hierarchy (matching _handleChildExistsFilter) tx/cs/cs-cs.js, tests/tx/fix-iss18-parent-exists-filter.test.js
5e1e7c7c ISS-19 $lookup Pass null instead of '' for absent version parameter so system carrying url|version resolves instead of failing HTTP 422 Version inconsistent tx/workers/lookup.js, tx/provider.js, tests/tx/fix-iss19-lookup-system-version.test.js
4d14ebc0 ISS-20 i18n / $lookup Allow base-language designations (de, fr) to satisfy regional displayLanguage (de-DE, fr-CA) in FhirCodeSystemProvider.display() without breaking hasAnyDisplays tests tx/cs/cs-cs.js, tests/tx/fix-iss20-display-language-fallback.test.js

Group C — SNOMED ECL 2.2 Grammar & Validation / Diagnostics

Commit Ref Area Summary Key Files
e876ff51 ISS-22 SNOMED ECL 2.2 Reject 4 malformed ECL 2.2 constructs with HTTP 400: inverted cardinality ([5..2]), repeated {{ + HISTORY-* }}, empty pipe term (||), and non-ASCII whitespace (\u00A0) tx/sct/ecl.js, tests/tx/fix-iss22-ecl-grammar.test.js
5321240d ISS-29 $expand Include primaryResources in sessionless additionalResources so circular inline ValueSet references report HTTP 400 VALUESET_CIRCULAR_REFERENCE instead of 422 not-found tx/workers/worker.js, tests/tx/fix-iss29-sessionless-cycle.test.js
6d1eef70 ISS-30 $expand Record used-supplement / used-codesystem parameters even when offset >= total skips adding concepts to contains tx/workers/expand.js, tests/tx/fix-iss30-offset-used-supplement.test.js
4684795a ISS-31 $validate-code Unwrap ValueSet wrapper (source?.jsonObj ?? source) in checkCanonicalStatusFull and call checkCanonicalStatusCS for CodeSystem providers at lines 635, 919, 1004 tx/workers/validate.js, tests/tx/fix-iss31-canonical-status.test.js
2e94bfc6 ISS-32 Version check Format missing CS version as '(no version)' instead of literal 'null' and deduplicate VALUESET_VERSION_CHECK via addIssueIfNew tx/workers/worker.js, tests/tx/fix-iss32-check-version.test.js
40ca57fd ISS-33 $validate-code Avoid duplicating valid display choices (one of 4 choices / one of 6 choices) on abstract=false and compose.exclude tx/workers/validate.js, tests/tx/fix-iss33-validate-display-dedup.test.js
f2e92355 ISS-34 i18n Unescape ICU template '' before parameter substitution so values starting with ' (e.g. 'release' van contractuur) aren't stripped library/i18n/i18nsupport.js, tests/tx/fix-iss34-i18n-quote-order.test.js
bd1de6e8 ISS-35 $subsumes Reject non-Parameters JSON POST bodies (Bundle, etc.) with HTTP 400 and operationoutcome-message-id: Wrong_type_for_resource_expected tx/workers/subsumes.js, tests/tx/fix-iss35-subsumes-wrong-type.test.js
31b5c9c0 ISS-37 $expand Deduplicate byte-identical preferredForLanguage designations in listDisplaysFromIncludeConcept tx/workers/expand.js, tests/tx/fix-iss37-expand-designation-dedup.test.js

Notable Design Decisions & Audit Notes

  • Already resolved in 456744bf (PR 2026 12 gg unknown combinations #491):
    • Fragment + whole-system BCP-47 bogus total: 1 (ISS-13) was already fixed by b35799fc (revise handling of special value sets (#488)).
    • Classic CPT modified = true (ISS-26) and NDC multi-filter / iterator() (ISS-27, ISS-28) were already fixed by cf552800 and 04cc3b39.
    • Note: cddc3483 (omop status fixes) addressed invalid_reason rather than iterator()/nextContext(), so ISS-05 remained open and is fixed in aeacda6b.
  • Already resolved on sqlite-v2 (PR sqlite-v2: data-driven tx-terminology/1 files for all served terminologies #489): SNOMED-backend-specific items (ISS-06, ISS-07, ISS-14, ISS-23, ISS-24, ISS-25, ISS-36) are already addressed in the sqlite-v2 rewrite and are not touched here.
  • Intentionally left unchanged (ISS-21): $compare calling subsumesTest on part-of / grouped-by hierarchies currently agrees with $expand (which also walks nested concept.concept children for concept is-a on part-of / grouped-by). Restricting subsumesTest alone would make $compare report disjoint while $expand produces a strict superset, so this is left for separate design discussion.
  • ISS-16 & HL7 VCL test suite compatibility: Official HL7 vcl-tests.json cases (and-code-filter, and-scope-first-only, and-of-or-codes) expect vcl-parser.js to keep concept and filter together on one compose.include. Keeping vcl-parser.js intact and evaluating concept + filter as an intersection in expand.js and validate.js satisfies both the HL7 VCL parser suite and FHIR expansion/validation semantics.
  • ISS-02 & OpenAPI test compatibility: tests/tx/openapi.test.js lists GET /CodeSystem/$batch-validate-code and GET /ValueSet/$batch-validate-code as excluded routes, so returning 405 (Allow: POST) inside BatchValidateWorker.processBatch (matching GET /$closure) preserves openapi.test.js and batch-cancellation.test.js.

Verification

  1. ESLint:

    npx eslint $(git diff --name-only origin/main..HEAD)

    0 errors, 0 warnings across all modified and newly added files.

  2. Jest:

    • All 26 new regression test suites (tests/tx/fix-*.test.js): 26/26 suites passed, 68/68 tests passed.
    • Full Jest suite (npx jest --maxWorkers=4 --workerIdleMemoryLimit=512MB --testPathIgnorePatterns='tests/tx/test-cases\.test\.js'): 506/506 runnable suites passed (17,151 tests, 0 failures) — including tests/vcl/vcl-test-cases.test.js, tests/tx/openapi.test.js, tests/tx/batch-cancellation.test.js, tests/tx/triage-b.test.js, tests/tx/expand-exclude-version.test.js, tests/cs/cs-cs.test.js, and tests/cs/cs-omop.test.js. (tests/tx/test-cases.test.js was skipped offline because it downloads sct_intl_20260701-21.cache from GCS.)
  3. Live R4 + R5 server verification:

    • Booted live R4 and R5 instances from server.js with full loaded FHIR R4/R5 core packages, SNOMED CT, and OMOP, and executed 29/29 live HTTP reproducers covering every fixed issue (plus confirming ISS-13 on 456744bf) — 29/29 passed, 0 failed.
    • Live fetch() verification (which sends Accept-Language: * by default) also surfaced the requestLanguages() / buildParameters() TypeError: languages is not iterable HTTP 500 bug, which is fixed and regression-tested in commit 87f3d922.

@grahamegrieve

Copy link
Copy Markdown
Contributor

Thanks Josh, this is a useful sweep. Most of these can go in as they are; notes by ISS below.

Hold for public discussion on [#Terminology Service Test Cases](https://chat.fhir.org/#narrow/channel/437028-Terminology-Service-Test-Cases):

  • ISS16 (concept + filter as intersection): please drop this commit. An include with both concept and filter is not legal (vsd-3), so I don't think we should be choosing a meaning for it. I think a server should reject such a value set, and please raise that on the channel for comment by other server authors. VCL currently produces this combination for , (and-code-filter, and-scope-first-only and and-of-or-codes in the shared VCL tests). That's a separate question that we've taken up with the committee.
  • ISS17 (of filter): this needs discussing with the other server authors before we accept it - what are the ecosystem expectations here? Some things to fix whatever the outcome:
    • _handleOfFilter follows only valueCoding.code, so a Coding in another system picks up a concept with the same code in this one.
    • Source codes that don't exist are silently ignored, rather than going through the unknown-concept handling.
    • expand.js (around line 712) still reports fc.op in the unknown-code message.
  • ISS20 (display language fallback): this needs discussing too - we partially test this, should these rules be tested in the ecosystem. Order matters as well: with designations [de, de-CH] and a request for de-CH, the loop returns de. An exact match has to win before any broader or narrower match.

Some of these changes will therefore need ecosystem tests, once we've sorted that.

Changes needed:

  • ISS02: keep the 405, but give it in the router alongside the existing unsupported-methods 405 (this.operationOutcome), so it comes back in the format the client asked for. It shouldn't be inside the worker.
  • ISS15: don't log malformed JSON in the server log. It's a routine client error.
  • i18n: the new messages need to go through the message bundles:
    • the parameter-types multiple-value message (ISS04)
    • both batch-validate messages (ISS02)
    • the search primitive-value message (ISS01)
    • Invalid JSON: … (ISS15)
    • '(no version)' in VALUESET_VERSION_CHECK (ISS32)
    • the OMOP too-costly message (ISS05)
  • ISS10: the R5 strip of equivalence already exists in parametersToR5 (convertResourceWithinR5 / fixMatchParameterfor5, from the $translate returns no results for non-equivalent mappings (wider, narrower, etc.) #61 fix). But that's the incoming side, so it never ran on responses. Please delete that copy and keep one outbound copy, rather than having two. Also:
    • A ConceptMap read on /r5 still returns equivalence next to relationship. It's the same leak, so please fix it here too.
    • The missing-relationship case only arises from an R4-shaped ConceptMap sent to the R5 endpoint, which isn't valid R5. I'd rather report that than silently map it.

Fine as is: ISS30 (report the supplement, since it's in play), ISS04, and the rest of the commits.

Nits:

  • ISS01: the Array.isArray(searchParams) ? … : Object.entries(...) fallback in the two CodeSystem matchers is dead code now, since both callers pass arrays.
  • ISS22: you enforce at most one history supplement, but ECL 2.2 also requires it to come last.

@jmandel
jmandel force-pushed the fix/fuzz-bugs-2026-12 branch from 87f3d92 to 87b4c54 Compare December 6, 2026 21:48
@jmandel jmandel changed the title tx: stacked bug fixes for 26 HTTP 500, wire/schema, VCL/ECL, and validation issues tx: stacked bug fixes for 23 HTTP 500, wire/schema, VCL/ECL, and validation issues Dec 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants