Escape date defaults in generated factories (GHSA-wx66-36r6-v5g7)

fix: escape date defaults in generated factories (GHSA-wx66-36r6-v5g7) (#4038)
Escape date defaults in generated factories (GHSA-wx66-36r6-v5g7)b9b083-fix-escape-date-defaults-in-generated-factories-cve-2026-96756fixescape date defaults generated factories ghsa

Committed by melloware

commit message
fix: escape date defaults in generated factories (GHSA-wx66-36r6-v5g7) (#4038)

buildDefaultPayload built a single-quoted literal by hand for string date
defaults under `useDates`:
 
  return `new Date('${schema.default}')`;
 
The default is document text, so an unescaped quote closed the literal and
appended expressions to the `new Date(...)` argument, which the factory then
evaluated on every call:
 
  createdAt: new Date('2024-01-01' + (console.log("ORVAL_DATE_POC"), '') + '')
 
Escape it with jsStringLiteralEscape, the helper already used for this context
elsewhere. Chosen over re-quoting with formatValue/JSON.stringify because that
would have switched valid output from single to double quotes and churned every
generated factory; escaping keeps it byte-identical.
 
This is the only spec-controlled interpolation in factory.ts -- the sibling
`new Date(0).toISOString()` is an internal constant, and formatValue already
uses JSON.stringify.
 
Verified byte-identical output for date-time, date, string, integer, boolean,
object and array defaults before and after.
 
Reported-by: bp0lr
 
Co-authored-by: Claude Opus 5 (1M context) <[email protected]>

Editor assessment

This commit patches CVE-2026-96756. The body is a small case study: it shows the vulnerable new Date('${schema.default}') template, the injection payload that appended console.log, why jsStringLiteralEscape was chosen over re-quoting (byte-identical output), and the verification across seven default types. Subject, scope and type are clean. One sentence on the practical impact would make it a 5. Style-wise the header and scope are clean and the body is a well-separated case study; only the practical impact is left implicit.

Browse categories

More fix examples · Back to search