Public research

TypeBox

CVE-2026-77356 · GHSA-976x-prgx-qv35
Generated validation-code injection

High, 7.8 · Public source snapshot: November 12, 2026

Original portfolio report · Public advisory · Public advisory

Shared credits and the scope of my investigation are documented below.

CVE-2026-77356 · GHSA-976x-prgx-qv35 · TypeBox · High

Public security research by Charles Vosburgh (the-vibe-dev).

Field Value
Project @sinclair/typebox
Ecosystem npm / Node.js
Severity High
CVSS 7.8 — CVSS:3.1/AV:L/AC:L/PR:L/UI:N/S:U/C:H/I:H/A:H
Public affected range >=0.24.0 <=0.34.51
Fixed releases 0.24.52, 0.25.25, 0.26.9, 0.27.12, 0.28.22, 0.29.8, 0.30.6, 0.31.30, 0.32.37, 0.33.24, 0.34.52
Weakness CWE-94 — Improper Control of Generation of Code
Public PoC Yes — published with the GHSA
Credit Charles Vosburgh (the-vibe-dev) — researcher and reporter

TypeBox 0.x could cross a critical data/code boundary when schema-controlled strings were inserted into JavaScript generated by TypeCompiler. An application that allowed a less-trusted value to become part of a TypeBox schema and then JIT-compiled that schema could cause the value to be interpreted as JavaScript rather than data.

The public proof of concept uses an attacker-influenced format value passed to Type.String({ format }). Vulnerable compiler versions embed that value directly into generated validation source. The injected statement executes when the compiled validator is invoked and can run with the permissions of the Node.js process.

This is not a default remote compromise of every TypeBox application. Exploitation requires a downstream application to map less-trusted input into a schema field that reaches the 0.x compiler. Applications that construct static developer-controlled schemas do not expose that prerequisite.

Security invariant: Every schema-derived string inserted into generated JavaScript must be emitted as a complete data literal by a centralized, context-correct serializer.

TypeBox's 0.x compiler converts schema objects into JavaScript source and evaluates the generated source using the JavaScript Function constructor. That design makes source emission security-critical: values originating in a schema must be serialized as JavaScript constants rather than concatenated into source text.

One initially identified path involved literal strings. The vulnerable implementation escaped only single quotes before surrounding the result with handwritten quotes:

namespace LiteralString {
  export function Escape(content: string) {
    return content.replace(/'/g, "\\'")
  }
}

The generated comparison then used the escaped value directly:

yield `(${value} === '${LiteralString.Escape(schema.const)}')`

Escaping only one character is insufficient for a JavaScript source context. A backslash combined with a quote can change how the generated string literal is parsed.

The first patch series hardened that path, but follow-on testing found a second source-generation path involving the schema format property. In affected releases the compiler emitted:

yield `format('${schema.format}', ${value})`

Because schema.format was still concatenated directly into generated source, a crafted format string could terminate the intended string literal and inject JavaScript statements.

The public PoC demonstrates the boundary with a benign process-global marker. Compilation alone leaves the marker unchanged. Invoking the compiled validator changes it, locating the effect in the generated function rather than schema construction or module loading.

The final fix centralizes string emission through a helper that first canonicalizes the value with JSON.stringify and then returns a complete JavaScript string constant:

function StringConstant(value: string): string {
  if (!IsString(value)) throw Error('ConstantString: Not a String')
  const canonical = JSON.stringify(value).slice(1, -1)
  const escaped = canonical.replace(/'/g, "\\'")
  return `'${escaped}'`
}

The format path then becomes:

yield `format(${StringConstant(schema.format)}, ${value})`

The same design was applied across other string-bearing compiler paths, including literals, member keys, required keys, format names, known-key arrays, and custom kind names. Older maintained branches also received fixes for direct regular-expression source interpolation.

Root cause

The compiler had multiple independent string emitters, each responsible for escaping values before inserting them into generated JavaScript. That made the security invariant distributed and easy to fix incompletely. Hardening one emitter did not protect a separate direct interpolation site.

The correct boundary is architectural: schema-controlled values should pass through one auditable serializer that returns a complete source literal. Callers should never add another layer of handwritten quoting around partially escaped data.

flowchart TD
    A[Less-trusted input influences a TypeBox schema]
    B[Application compiles the schema with TypeCompiler]
    C[Schema string is concatenated into generated JavaScript]
    D[Generated validator is invoked]
    E[Injected JavaScript executes in the Node.js process]
    A --> B --> C --> D --> E

The practical prerequisites are therefore:

  1. The application uses an affected TypeBox 0.x release.
  2. A less-trusted actor can influence a string-valued schema property.
  3. The application compiles that schema with TypeCompiler.
  4. The resulting validator is invoked.

The PoC is already public in GHSA-976x-prgx-qv35 and is not duplicated as a separate artifact in this repository.

The published test uses a harmless state marker to distinguish compilation from execution. In vulnerable samples the marker remains unchanged after compilation and changes only after Check() executes the generated validator. In the fixed releases the same public trigger leaves the marker unchanged.

I validated the public format-name PoC across representative affected versions and every listed line-specific fixed release. The trigger reproduced on sampled affected branches including 0.24.51, 0.25.24, 0.26.8, 0.31.29, 0.32.36, 0.33.23, 0.34.50, and 0.34.51. It did not alter state on the eleven listed fixed releases.

The public format trigger is not evidence for every historical source variant. In sampled 0.27.x through 0.30.x releases, the format PoC remained negative while public source and fixing diffs showed a separate generated-regexp interpolation path. Those are treated as source-verified variants rather than as runtime results from the format PoC.

The demonstrated primitive is arbitrary JavaScript execution inside the Node.js process that compiles and invokes the attacker-influenced schema. The resulting confidentiality, integrity, and availability impact is bounded by the privileges and reachable resources of that process.

The important deployment qualification is reachability. TypeBox schemas are commonly developer-authored, and TypeScript applications do not automatically expose schema construction to remote users. A remote exploit therefore depends on a downstream application taking less-trusted data and using it to construct a schema that is subsequently JIT-compiled.

The published advisory rates the issue High, CVSS 7.8.

The public advisory range is:

@sinclair/typebox >= 0.24.0 and <= 0.34.51

Fixed releases for the maintained 0.x lines are:

0.24.52
0.25.25
0.26.9
0.27.12
0.28.22
0.29.8
0.30.6
0.31.30
0.32.37
0.33.24
0.34.52

The exact npm artifacts for the last affected release on each maintained line and all eleven fixed releases were inspected. The public format PoC was also run against the fixed releases and produced no state change.

No distinct introducing commit was independently established for the entire advisory range. The exact 0.24.0 npm artifact was inspected as the earliest release in the public affected interval; that should not be read as proof that a single source commit introduced every affected code-generation path.

Upgrade to the fixed release for the maintained 0.x line, or migrate to TypeBox 1.x where compatible.

For maintainers of code-generating systems, the stronger remediation lesson is to centralize all data-to-source conversion. Regression tests should cover backslashes, quotes, line terminators, literal strings, property/member keys, format names, custom kind names, regex-related keys, and any other schema value that can reach generated source.

A useful regression assertion is not merely that the validator returns the expected boolean. It should also assert that an attacker-controlled marker or side effect remains absent before and after compilation and invocation.

Date Event
2026-07-11 Initial 0.x patch series began landing.
2026-07-16 Follow-on hardening completed across maintained 0.x lines.
2026-08-21 GHSA-976x-prgx-qv35 and CVE-2026-77356 published with the public PoC.
2026-08-26 Affected/fixed release matrix and public paths re-reviewed.

CVE-2026-77356 / GHSA-976x-prgx-qv35 is a generated-code injection vulnerability in TypeBox 0.x. The core failure was allowing schema-controlled strings to cross from data into JavaScript source without one centralized source-literal boundary. Follow-on testing was important because the initial escape fix protected one emitter but left another direct interpolation path intact.

The issue is exploitable when a downstream application allows less-trusted data to influence a compiled TypeBox schema. Under that prerequisite, injected JavaScript executes with the privileges of the Node.js process.

Broader lesson: Generated code needs one auditable data-to-source boundary. Patch-by-patch escaping at individual emitters invites follow-on variants.

  • https://github.com/sinclairzx81/sinclair-typebox/security/advisories/GHSA-976x-prgx-qv35
  • https://api.github.com/repos/sinclairzx81/sinclair-typebox/security-advisories/GHSA-976x-prgx-qv35

Charles Vosburgh (the-vibe-dev) — researcher and reporter.

Research was AI-assisted for source mapping, hypothesis generation, release comparison, and evidence organization. I performed the final validation, disclosure coordination, severity calibration, and publication review.

This write-up documents a publicly disclosed vulnerability for defensive research, remediation, regression testing, and authorized assessment. Do not use the PoC or technical details against systems without explicit permission.