Sanitize OpenAPI document values before splicing into generated code (zod/effect/hono)

fix: sanitize OpenAPI document values before splicing into generated code (zod/effect/hono) (#3995)
Sanitize OpenAPI document values before splicing into generated code (zod/effect/hono)d346d9-fix-sanitize-openapi-document-values-before-splicing-cve-2026-96754-cve-2026-96755fixsanitize openapi document values before splicing

Committed by adamyordan

commit message
fix: sanitize OpenAPI document values before splicing into generated code (zod/effect/hono) (#3995)

* fix(zod,effect,hono): sanitize OpenAPI values before code generation
 
Three generator emission sites splice values taken directly from the input
OpenAPI document into generated TypeScript without making them safe for the
syntactic context they land in:
 
- packages/zod and packages/effect emit numeric/length constraints
  (minimum, maximum, exclusiveMinimum, exclusiveMaximum, multipleOf) as a
  bare, unquoted module-level expression (`export const XMin = ${min};`).
  There is no escaping that can make this position safe, so a non-numeric
  value (which the default validator accepts for a numeric schema) is
  emitted verbatim as code. Now validated as a finite number before
  interpolation; anything else fails generation with a clear error.
 
- packages/effect's default-value handling stringifies a value into a
  correctly single-quote-escaped literal and then swaps the quote
  delimiters for backticks without re-escaping the content, turning a
  string literal into a template literal and re-arming `${...}`
  interpolation. Fixed by keeping the delimiter the value was actually
  escaped for.
 
- packages/hono emits literal OpenAPI path text into a single-quoted
  literal inside the generated Hono route chain with no escaping applied
  to it at all (`getRoute`/`toColonRoutePath` only rewrite `{param}`
  placeholders). Now escaped for the single-quoted context it is emitted
  into via the existing `jsStringLiteralEscape` helper.
 
None of these require unusual configuration - all three fire on an
ordinary `orval` run against an untrusted OpenAPI document with default
settings, and the generated code runs at import time. Existing test
suites for all three packages pass unchanged (474 tests), and verified
manually that legitimate specs (including values containing backticks
and `${...}` sequences) still generate correct, valid output.
 
Claude-Session: https://claude.ai/code/session_013HJgsqm2W5ARr3UwXxCeNN
 
* fix: normalize OpenAPI 3.0 boolean exclusive bounds before validation
 
Follow-up to the previous commit's numeric-constraint validation. A
schema explicitly setting exclusiveMinimum: false / exclusiveMaximum:
false (a valid, if redundant, OpenAPI 3.0 document) was left as the
boolean `false` rather than normalized to undefined, so it was
mistaken for a constraint value and rejected as non-numeric - a
regression for legitimate specs. Booleans now normalize correctly:
true resolves to the paired min/max value (as before), false to
undefined so generation falls through to the ordinary inclusive
bound. Also switches the rejection error's value formatting from
JSON.stringify (which renders NaN/Infinity/-Infinity as "null") to
String, so the error is accurate for those inputs. Adds regression
coverage in both packages for the boolean-false case.
 
Claude-Session: https://claude.ai/code/session_013HJgsqm2W5ARr3UwXxCeNN

Editor assessment

This commit patches CVE-2026-96754 and CVE-2026-96755. The body is very strong: it covers three emission sites, numeric-constraint validation, the backtick re-escaping bug and the exclusive-bound regression, with test results. The subject, however, runs 104 characters and carries generator names plus the PR, which hurts scanning and style hygiene. The content is close to exemplary; trimming the header and moving the generator list into the body would get it there. The regression fix for exclusive bounds is a good sign of care; calling it out in the subject's summary would help readers see the scope.

Browse categories

More fix examples · Back to search