# GHSA-4J53-7M38-656F: @orval/axios: code injection via unescaped OpenAPI response status key in generated empty-response condition

- Database: GitHub
- Severity: CVSS 8.8 (High)
- Published: 2026-09-13
- Modified: 2026-09-18

## Affected versions

- @orval/axios (npm): 8.32.0 only

## Description

## Summary

`@orval/axios` (introduced in 8.32.0) generates axios client code that emits an OpenAPI response status key into an unquoted JavaScript expression position without numeric parsing or escaping. When the empty-response normalization feature is enabled, the raw response key from the input specification is spliced verbatim into a generated `.then(...)` predicate. An attacker who authors or controls the OpenAPI document consumed by a victim's codegen can craft a status key that breaks out of the intended numeric comparison and injects arbitrary JavaScript, which executes in the consuming process when the generated operation is called and its promise resolves. Reachability requires two documented, non-default generator settings, so this is a high-severity issue rather than the critical default-config import-time class of the related sibling sinks.

## Root Cause

The status-discriminated empty-response feature builds a runtime condition string from response status keys taken directly from the input specification. In `getEmptyResponseStatusCondition`, the local helper `conditionFor` special-cases only wildcard keys matching `/^[1-5]XX$/i`; every other key falls through to a template that concatenates the raw key into an expression position with no numeric coercion (`Number`/`parseInt`) and no escaping. The value originates from `getResReqTypes`, which copies the response object key verbatim, and `getResponse`, which routes any key beginning with `2` into the success type set. Because the key is emitted in expression position rather than inside a string literal, a crafted key becomes live code. The sibling `@orval/mock` (MSW) generator guards the structurally identical emission with an unconditional `assertSafeStatusCode` numeric parse; the axios generator ships no equivalent guard.

```text
Affected package: @orval/axios (npm), version 8.32.0
getEmptyResponseStatusCondition (packages/axios/src/index.ts:170-208), local helper conditionFor at :176-188; bare emission `response.status === ${key}` at :187
normalizeEmptyAxiosResponse (packages/axios/src/index.ts:210-217) wraps the condition into a `.then(...)` arrow
generateAxiosImplementation splices the result into the client body at :371 when override.axios.includeHttpResponseReturnType is true (non-mutator branch)
```

## Impact

An attacker who controls the OpenAPI document processed by the victim achieves arbitrary JavaScript execution in the process that runs the generated axios client (typically a developer machine, test runner, or CI/build job). Two developer-side settings must be active for the sink to be reachable: `input.unsafeDisableValidation: true`, which skips the specification validator that otherwise rejects non-numeric status keys, and `output.override.axios.includeHttpResponseReturnType: true`, which is the flag that appends the empty-response normalization. Under these documented, non-default settings, exploitation is deterministic and requires no further attacker effort once the malicious specification is consumed. Execution occurs at call time (when the generated operation function runs and its promise resolves), not at import time, which adds friction relative to the module-level import-time variants in this project. The demonstrated primitive is full code execution (confirmed by executing the verbatim generator output); consequential impact includes disclosure, modification, or destruction of any data reachable by the codegen process and lateral movement from CI credentials available to that process.

## Proof of Concept

`Reproduction executes the two generator functions copied verbatim from the shipped source against a synthetic response definition and evaluates the emitted string. No orval installation is required to demonstrate the sink primitive; a full end-to-end run additionally requires the two non-default settings above.`

Steps:
1. Define an OpenAPI operation with a content-less (no `content`) success response whose status key is `2 || (globalThis.__pwned = require('child_process').execSync('id').toString()) || false`.
2. Configure orval with `output.client: 'axios'`, `output.override.axios.includeHttpResponseReturnType: true`, and `input.unsafeDisableValidation: true` (the last is required so the validator does not reject the non-numeric key).
3. Run codegen, then invoke the generated operation so its promise resolves.

```javascript
// getEmptyResponseStatusCondition + normalizeEmptyAxiosResponse copied verbatim from
// packages/axios/src/index.ts, driven with a malicious "void" success key.
const key = "2 || (globalThis.__pwned = require('child_process').execSync('id').toString()) || false";
const condition = `(response.status === ${key})`;        // bare emission, no coercion
const generated = `.then((response) => ${condition} ? { ...response, data: undefined } : response)`;
const fn = new Function('axios', 'url', 'options', `return axios.get(url, options)${generated};`);
// invoking fn(...) and resolving the promise runs the injected expression
```

```text
return axios.get(url, options).then((response) =>
      (response.status === 2 || (globalThis.__pwned = require('child_process').execSync('id').toString()) || false)
        ? { ...response, data: undefined } : response,
    );
INJECTED CODE RAN. `id` output: uid=1000(ubuntu) gid=1000(ubuntu) groups=1000(ubuntu),...
```

## Attack Chain

1. **Exposure:** A victim runs orval codegen (a local or CI build tool) against an OpenAPI document authored or supplied by the attacker. This is the same attacker model as the project's other specification-injection advisories.
2. **Control:** The attacker fully controls a response status key string. `getResReqTypes` copies the response object key verbatim into `{ value: 'void', key }` for a content-less response, and `getResponse` routes any key beginning with `2` into the success type set, with no sanitization or coercion.
3. **Path:** With `input.unsafeDisableValidation: true`, the specification validator is skipped, so the non-numeric key is not rejected. The key reaches `getEmptyResponseStatusCondition`, passes the `value === 'void'` filter (a content-less response is `void`), and is passed to `conditionFor`.
4. **Guard:** `conditionFor` only special-cases keys matching `/^[1-5]XX$/i`; the crafted key does not match and falls through to `response.status === ${key}` at line 187, an unquoted expression position with no numeric parse and no `assertSafeStatusCode`-equivalent guard.
5. **Primitive:** `normalizeEmptyAxiosResponse` wraps the unguarded condition into a `.then((response) => <condition> ? {...} : response)` arrow, which `generateAxiosImplementation` appends to the generated client body at line 371 when `override.axios.includeHttpResponseReturnType` is true (non-mutator branch).
6. **Result:** When the generated operation function is invoked and its promise resolves, the arrow evaluates the injected expression, executing attacker-chosen JavaScript in the consuming process.

## Bypass Evidence

The relevant guard is the in-generator numeric-parse control that the maintainers apply to the structurally identical sink in `@orval/mock` (MSW): `assertSafeStatusCode`, which is called unconditionally. The axios generator ships no such guard: a fresh `npm pack @orval/axios@8.32.0` shows zero occurrences of `assertSafeStatusCode` in `package/dist/index.mjs`, while the bare emission `response.status === ${key}` is present at `dist/index.mjs:84`, and both `getEmptyResponseStatusCondition` and `normalizeEmptyAxiosResponse` are present and wired together in the shipped artifact.

The strongest attempt to invalidate this finding is the argument that the required `input.unsafeDisableValidation: true` setting makes it a self-inflicted "disabled security control" rather than a vulnerability. That argument fails on the maintainers' own evidence. The MSW fix for the sibling sink explicitly records the same precondition ("the default validator already rejects such a key, so this needs `input.unsafeDisableValidation: true` to reach") and the maintainers fixed it anyway, stating that relying on an external validator to prevent code injection is a thin defence. Every sibling emission sink in the project is guarded in-generator regardless of validation (numeric parse for status keys, `jsesc` for defaults, sanitization for names). `unsafeDisableValidation` is documented as a specification-correctness tolerance switch, not a declaration that the specification author is trusted to inject code. The maintainers' security boundary for this emission class is the in-generator guard, which is absent in axios. A second attempt to invalidate the finding, testing whether the default validator alone is sufficient, confirms it rejects the malicious key, which is why the finding is scoped strictly to the documented non-default configuration and rated HIGH rather than critical.

## Affected Versions

- `Ecosystem: npm`
- `Package: @orval/axios`
- `Confirmed affected range: >= 8.32.0, <= 8.32.0`
- `Latest release checked: 8.32.0 (npm, current latest)`
- `Fix status: not fixed`

The vulnerable feature (`getEmptyResponseStatusCondition`, `normalizeEmptyAxiosResponse`, and the `includeHttpResponseReturnType` empty-response normalization) was introduced by the commit that added status-discriminated response generation, which is contained only in tag `v8.32.0`. Fresh `npm pack` of `@orval/axios@8.31.0` and `@8.30.0` contain zero occurrences of these functions, confirming the feature is absent before 8.32.0. No fix has been released; the current development head remains vulnerable. The range is therefore a single released version.

## Suggested Fix

Enforce that a spec-derived response status value can only ever be emitted as a validated numeric literal. In `conditionFor`, parse the key with a strict numeric check (rejecting or coercing any non-status key) before building `response.status === <n>`, mirroring the unconditional `assertSafeStatusCode` guard already used by the `@orval/mock` MSW generator, so the guard fires independently of `input.unsafeDisableValidation`. The remediation must cover both the fall-through branch in `conditionFor` and the `default`-key path, and it should be applied at the emission point rather than relying on upstream specification validation. As an interim mitigation without a code change, consumers should avoid combining `output.override.axios.includeHttpResponseReturnType: true` with `input.unsafeDisableValidation: true`, and should only run codegen against trusted OpenAPI documents.

Reported by zx (GitHub: @manus-pi).

## References

- https://github.com/orval-labs/orval/security/advisories/GHSA-4j53-7m38-656f

Page: https://cve.now/GHSA-4J53-7M38-656F

Wrong or missing data? Send feedback: POST https://cve.now/api/v1/feedback (see https://cve.now/agents#feedback).
