Skip to main content
Menu
Advisories

Import-time RCE in @orval/effect enum generator via raw non-string member emission

GHSA-F96W-763G-HG7VPublished Updated GitHub

Description

@orval/effect's enum generator at packages/effect/src/index.ts:643-665 reads schema.enum directly from an untrusted OpenAPI document and, in the non-all-string branch, emits each member as a raw JS expression inside a top-level export const … = S.Literal(<expr>) in the generated *.schemas.ts module. A single-element array enum member (["<payload>"]) stringifies via template interpolation to a bare expression (Array.prototype.toString joins without brackets/quotes), yielding executable code evaluated when the victim imports or builds the generated module → arbitrary code execution in the codegen/build/runtime process.

Root Cause

In the enum emission block, the .every(isString) guard decides between the safe all-string path (which escapes via jsStringLiteralEscape) and the oneOf/literal branch, which uses the ternary isString(value) ? '…escaped…' : value (:658) — the else arm emits the raw member value. renderConstructor('literal', value) splices it into a template literal ` S.Literal(${arg as string}) (:1049) with no JSON.stringify / toJsLiteral / escaping. JSON Schema permits enum members of any type, so a non-string member (array/number/boolean) reaches the raw-emission arm; a one-element array ["<expr>"] interpolates to the bare <expr>`.

The parallel @orval/core enum generator was hardened on 2026-10-03 (commit afbb243, GHSA-v36f-hqj9-q8rr) by routing all members through getEnumMembers → isSchemaEnumValue and serializing via toJsLiteral. That fix touched only packages/core; @orval/effect has its own independent enum reader and remains unpatched.

Impact

Import-time arbitrary code execution in the victim's codegen/build/runtime process when they generate orval clients from an attacker-controlled OpenAPI spec with output.client: 'effect'. Specs are untrusted input by design (remote $ref, third-party registries, downloads). In CI auto-regeneration pipelines (UI:N), the ceiling is CRITICAL.

Proof of Concept

components:
  schemas:
    Pet:
      type: object
      properties:
        status:
          type: string
          enum:
            - ["require('node:child_process').execSync('touch /tmp/orval-effect-pwned')"]

Run orval with output.client: 'effect'. The generated *.schemas.ts contains:

export const PetStatus = S.Literal(require('node:child_process').execSync('touch /tmp/orval-effect-pwned'))

Importing or building this module executes the payload.

Attack Chain

  1. Entry — Attacker publishes/serves an OpenAPI spec with a schema whose enum holds a one-element array member wrapping a JS payload string.
  • Guard: none on spec ingestion (specs are untrusted input).
  • Bypass proof: orval performs no JSON-Schema type/consistency validation of enum members against type.
  1. Routing to the vulnerable branch — resolveEffectType returns 'string'; the case 'string' branch does if (schema.enum) break; (:433-436) and falls through to the shared enum block at :643 (schema.enum && type !== 'array' is true).
  • Guard: uniqueEnumValues.every((v) => isString(v)) at :646 — intended to keep the safe all-string path.
  • Bypass proof: the array member is not a string, so .every(isString) is false; control flows to the else/oneOf branch at :651-663.
  1. Raw emission at the sink — Each member is pushed as ['literal', isString(value) ? '…escaped…' : value] (:658); array member takes the : value (raw) arm. renderConstructor('literal', value) returns ` S.Literal(${arg as string}) (:1049`).
  • Guard: none — no jsStringLiteralEscape/JSON.stringify/toJsLiteral on the raw arm.
  • Bypass proof (empirical): node -e "const v=['x']; console.log('S.Literal(' + v + ')');" → S.Literal(x). One-element array interpolation drops brackets and quotes, leaving the bare expression.
  1. Impact — The string is written into a top-level export const <Name>Body = S.Literal(<expr>) (:1720-1750). When the victim imports/builds the generated module, <expr> is evaluated as the argument to S.Literal(...) → arbitrary JS execution.

Bypass Evidence

Simulating index.ts:658 + :1049 on the PoC member yields:

S.Literal(require('node:child_process').execSync('touch /tmp/orval-effect-pwned'))

Confirmed syntactically valid and executable. Mixed enum ["active", ["+(process.exit(1))"]] → S.Literal('active'), S.Literal(+(process.exit(1))) (both executable). Verified against latest release tag v8.40.0 (= HEAD 0336088); git log v8.40.0..HEAD -- packages/effect/src/index.ts is empty.

Dedup: the three nearest advisories do not cover this path:

  • GHSA-v36f-hqj9-q8rr — @orval/core stringifyEnumValue. Fix commit afbb243 touches packages/core only; no changes to packages/effect.
  • GHSA-q7f2-jg6j-r867 — @orval/effect default template-literal sink. Different sink.
  • GHSA-w4x4-mpp4-4854 — @orval/core factory numeric/boolean enum. Different package + file.

Sibling enum emitters are safe: @orval/zod uses getEnumMembers (filters non-primitives); @orval/mock uses formatEnumMember with JSON.stringify fallback. Only @orval/effect reads schema.enum raw.

Affected Versions

@orval/effect and orval <= 8.40.0 (vulnerable code present on latest release tag; no post-release fix on main).

Suggested Fix

Route enum members through the same hardening used in @orval/core (GHSA-v36f-hqj9-q8rr): filter non-primitives via isSchemaEnumValue and emit all members via toJsLiteral/JSON.stringify. Minimal patch — replace :658:

['literal', toJsLiteral(value)]

and reject or stringify non-primitive members at the start of the enum block.

Credit

zx (Jace) — GitHub: @manus-use

Affected versions

References

GitHub · orval-labs/orval