Escape spec-controlled strings in generated template literals and object keys

fix: escape spec-controlled strings in generated template literals and object keys (#3692)
Escape spec-controlled strings in generated template literals and object keys8ef1bf-fix-escape-spec-controlled-strings-in-generated-template-cve-2026-62681-cve-2026-62682-cve-2026-71864-cve-2026-71865-cve-2026-71866-cve-2026-71867-cve-2026-71868-cve-2026-71869-cve-2026-71871-cve-2026-72716-cve-2026-72717fixescape spec controlled strings generated template

Committed by aqeelat

commit message
fix: escape spec-controlled strings in generated template literals and object keys (#3692)

* fix(core,zod): escape spec-controlled strings in generated template literals
 
Unescaped spec values (servers[].url, path segments, schema defaults)
were baked into generated template literals, allowing code injection via
backtick or ${ in an attacker-controlled OpenAPI spec.
 
Uses jsesc with quotes: 'backtick' to escape at three boundaries:
- getRoute(): raw OpenAPI path before param processing
- getFullRoute(): resolved server URL after variable substitution
- formatDefaultValue(): schema default values in zod generation
 
Addresses: GHSA-88f2-fpv8-89q2, GHSA-w727-8j6c-2rj4,
GHSA-3575-w9fc-c2j6, GHSA-2h9g-j24r-h63g, GHSA-8j6p-r8jg-mxqh,
GHSA-p4cg-3328-rvfg
 
* fix(zod): escape object keys via JSON.stringify in zod.object generation
 
Unescaped schema property and parameter names were emitted as
double-quoted keys in zod.object({...}), allowing computed property key
injection via " in the name.
 
Replaces "${key}" with JSON.stringify(key) at all 5 render sites.
 
Addresses: GHSA-6437-gxhq-pqv8, GHSA-653q-5476-x79g, GHSA-6mr6-jvcr-2f25
 
* fix(core): escape single-quoted object keys in getKey via jsStringLiteralEscape
 
Unescaped schema property names were wrapped in single quotes by getKey(),
allowing computed property key injection via ' in the name in MSW mock output.
 
Wraps the key body with jsStringLiteralEscape before quoting.
 
Addresses: GHSA-2w86-xfrc-g85r
 
* fix(query,zod): escape raw route prefix and prove backtick-in-key safety
 
mutation-generator.ts passed a raw spec path prefix to getFullRoute,
bypassing getRoute's escaping. Wrap with getRoute to close the gap.
 
Add test proving JSON.stringify-wrapped object keys are safe against
backtick injection (backtick is harmless inside double-quoted strings).
 
* fix: escape object-default keys and add ${} path test
 
- Escape object-default keys with JSON.stringify in zod schema defaults
  (same fix as zod.object keys)
- Add test verifying ${globalThis.X} in path segments is not
  re-interpreted as interpolation
- Update existing test expectations for quoted object keys
 
* fix(core): prevent ${} re-interpretation in getRoutePath and escape single quotes in getRouteAsArray
 
getRoutePath: after jsesc escapes ${ to \${, the remaining {evil} was
mistaken for an OpenAPI path param and re-converted to ${evil}. Add
early-return when { is preceded by $.
 
getRouteAsArray: segments wrapped in single-quoted strings without
escaping '. A spec path containing ' would break out. Now escapes
single quotes at both wrap sites.
 
* fix(core): handle ${} in getRoutePath and escaped tags in getRouteAsArray
 
getRoutePath: skip past ${...} block and continue processing remaining
suffix so later {param} segments are still converted.
 
getRouteAsArray: add (?<!\) to split/match regexes so jsesc-escaped
${...} is treated as literal text, preventing standalone backslash
from breaking single-quote wrapping.
 
* fix(core): escape per-segment in getRoute to preserve params after ${...}

Editor assessment

This commit patches CVE-2026-62681, CVE-2026-62682, CVE-2026-71864, CVE-2026-71865, CVE-2026-71866, CVE-2026-71867, CVE-2026-71868, CVE-2026-71869, CVE-2026-71871, CVE-2026-72716 and CVE-2026-72717. The subject states the goal well, escaping spec-controlled strings in template literals and object keys, and the opening paragraph explains the backtick and dollar-brace injection vector and the jsesc remedy. The rest is an unedited stack of eight sub-commit messages, each restating addresses for a long list of GHSA identifiers, pushing the body past several thousand characters and turning it into a merge log. The substance is present, the presentation is not.

Browse categories

More fix examples · Back to search