Skip to main content
Menu
Advisories

@orval/hono: Unescaped single-quote injection in generateHonoRoute() and getContext() — broken TypeScript in generated files

GHSA-G4MF-Q5HW-F9J9Published Updated GitHub

Description

Orval Hono Generator: Unescaped Single-Quote Injection in Route Registration and Context Types

Summary

@orval/hono@8.28.1 (current latest) produces syntactically broken and potentially exploitable TypeScript/JavaScript when an OpenAPI spec contains a single quote (') in a static path segment. Two separate code-generation sites embed the Hono-specific getRoute() output into single-quoted string literals without escaping, making them vulnerable to string-literal injection.

The recently-published batch of CVEs (GHSA-*) patched injection in the HTTP client generators but missed these two sites in the Hono generator. One site has an unreleased fix in the repository source; the other is unfixed even in source.

Affected package and version

@orval/hono@8.28.1 (npm, current latest)

Vulnerable sites

Site 1: generateHonoRoute() — route registration in generated .ts files

// @orval/hono/dist/index.mjs, line 394-397
const generateHonoRoute = ({ operationName, verb }, pathRoute) => {
  const path = getRoute(pathRoute);
  return `\n  .${verb.toLowerCase()}('${path}', ...${operationName}Handlers)`;
  //                                    ^^^^^^ no jsStringLiteralEscape
};

getRoute() converts {param} → :param but passes static path segments through unchanged. If a static segment contains ', the generated route registration string literal breaks.

Status: A fix (jsStringLiteralEscape(path)) exists in the repository source but has not been released to npm.

Site 2: getContext() — path type parameter in generated .context.ts files

// @orval/hono/dist/index.mjs, line 674
return `export type ${pascal(verbOption.typeName)}Context<E extends Env = any> = Context<E, '${getRoute(verbOption.pathRoute)}'${...}>`;
//                                                                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ no jsStringLiteralEscape

Same getRoute() call, same unescaped embedding, in the TypeScript type alias for the Hono context type. A single quote in the static path breaks the type string literal and allows arbitrary TypeScript to be injected into the generated *.context.ts file.

Status: Unfixed in repository source as of this report.

Contrast with the secured path

generateHonoRoute() in the repository source (not yet published) correctly applies the escape:

// packages/hono/src/index.ts, line 180 (source, not in npm 8.28.1)
return `\n  .${verb.toLowerCase()}('${jsStringLiteralEscape(path)}', ...${operationName}Handlers)`;

The getContext() function does not apply the same escape.

Runtime PoC

Environment

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

Spec (malicious.yaml)

openapi: "3.0.0"
info:
  version: 1.0.0
  title: Malicious Spec
paths:
  /api/v1/it's-endpoint/{id}:
    get:
      operationId: getItem
      parameters:
        - name: id
          in: path
          required: true
          schema:
            type: string
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                type: object

Config (orval.config.ts)

import { defineConfig } from 'orval';
export default defineConfig({
  poc: {
    output: { mode: 'single', target: 'src/generated.ts', client: 'hono' },
    input: { target: './malicious.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 (route registration)

const app = new Hono()

  .get('/api/v1/it's-endpoint/:id', ...getItemHandlers)

;

The ' in it's terminates the string literal. s-endpoint/:id', ...getItemHandlers) is outside the string, producing a syntax error.

Generated src/generated.context.ts (type declarations)

export type GetItemContext<E extends Env = any> = Context<E, '/api/v1/it's-endpoint/:id', { in: { param: {
 id: string,
 }, }, out: { param: {
 id: string,
 }, } }>

Same break: ' in it's closes the type literal early. Everything between it' and the next unescaped ' is outside the type string — injected content at the TypeScript level.

Type-level injection demo

For path /api/v1/'; type Injected = any //, the generated context type becomes:

export type GetItemContext<E extends Env = any> = Context<E, '/api/v1/'; type Injected = any //'...>

Which parses as:

  • (broken) export type GetItemContext<...> = Context<E, '/api/v1/'
  • (injected) type Injected = any
  • (commented out) //rest of original template

Arbitrary TypeScript type declarations can be injected into generated type files.

Impact

Any project that runs orval against an OpenAPI spec containing ' in a static path segment will receive generated code with broken string literals. The generated files will not compile cleanly. In environments using esbuild, swc, or babel (which do not enforce TypeScript type-checking before emit), injected JavaScript expressions or declarations may be included in the compiled output.

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

Fix

Apply jsStringLiteralEscape() to the getRoute() result before embedding it in single-quoted string literals, at both call sites:

Site 1 (already in source, needs release):

return `\n  .${verb.toLowerCase()}('${jsStringLiteralEscape(path)}', ...${operationName}Handlers)`;

Site 2 (not yet fixed):

return `export type ${pascal(verbOption.typeName)}Context<E extends Env = any> = Context<E, '${jsStringLiteralEscape(getRoute(verbOption.pathRoute))}'${...}>`;

jsStringLiteralEscape is already imported from @orval/core in packages/hono/src/index.ts.

Affected versions

References

GitHub · orval-labs/orval