# GHSA-G9M6-R3RX-75H3: Code injection (RCE) via patternProperties regex key verbatim-emitted into generated normalizers (jane-php/json-schema)

- Database: GitHub
- Severity: critical (stated by ghsa, no CVSS score)
- Published: 2026-11-20
- Modified: 2026-11-20

## Affected versions

- jane-php/json-schema (Packagist): fixed in 8.1.3

## Description

## Summary
jane-php's generated JSON (de)normalizers emit the `patternProperties` regex **key** from an input JSON-Schema / OpenAPI document into generated PHP as a raw `'/.../'` string literal through a php-parser `Name` node (not a `Scalar\String_` node). php-parser prints a `Name` node **verbatim**, so the quote auto-escaping that protects every other schema-text sink never runs. The only sanitization applied to the attacker-controlled key is `str_replace('/', '\\/', $pattern)`, which escapes the regex delimiter and nothing else — single quotes pass through unescaped. A `patternProperties` key containing single quotes closes the `'/.../'` literal and injects arbitrary PHP into executable expression position inside the generated `normalize()` / `denormalize()` method bodies (CWE-94). When the generated SDK is loaded and a model is (de)serialized, the injected code executes.

This is the same vulnerability CLASS as CVE-2026-63411/63412/63413 (attacker-controlled schema text → generated PHP → RCE) but a **distinct, unreported sink**: a different package (`jane-php/json-schema`), different files (Normalizer generators / `PatternMultipleType`), a different breakout mechanism (single-quote string-literal breakout via a `Name` node, not a PHPDoc `*/` breakout), and a different entry field (schema `patternProperties` key, not an OpenAPI parameter name/description). The PHPDoc fix commit `0ea379dea` does not touch any of these files.

## Root Cause
At four sink sites the regex is built as a raw PHP string and wrapped in a `Name` node:
```php
new Expr\ConstFetch(new Name("'/" . str_replace('/', '\\/', $pattern) . "/'"))
```
Because php-parser pretty-prints a `Name` node literally (no escaping), and `str_replace` only touches `/`, a key such as `'.phpinfo().'` produces `preg_match('/'.phpinfo().'/', (string) $key)` — valid, executable PHP.

Sink sites (paths on v8.1.2):
- `src/Component/JsonSchema/Generator/Normalizer/DenormalizerGenerator.php:277` (`createPatternPropertiesDenormalizationStatements`)
- `src/Component/JsonSchema/Generator/Normalizer/NormalizerGenerator.php:276` (`createPatternPropertiesNormalizationStatements`)
- `src/Component/JsonSchema/Guesser/Guess/PatternMultipleType.php:74` (`createDenormalizationStatement`)
- `src/Component/JsonSchema/Guesser/Guess/PatternMultipleType.php:115` (`createNormalizationStatement`)

## Impact
Arbitrary PHP code execution. The injected expression runs inside the generated normalizer whenever the SDK is used (de)serialization of the corresponding model). In a typical workflow (a developer / CI runs jane against a shared, third-party, or URL-fetched OpenAPI/JSON-Schema document), this yields RCE on the build/runtime host. Same impact class the maintainer rated CRITICAL for the sibling PHPDoc sink.

## Proof of Concept
Schema:
```json
{"type":"object","patternProperties":{"'.phpinfo().'":{"type":"string"}}}
```
Generating a normalizer for this schema emits (verbatim):
```php
if (preg_match('/'.phpinfo().'/', (string) $key)) { ... }
```
which is valid PHP and executes `phpinfo()` when the generated normalizer is loaded. A `chr()`-encoded `file_put_contents(...)` payload embedded in the key was generated via the exact sink, the output was `require`d, and the marker file was written to disk — confirming arbitrary code execution (verified with php-parser v5.6.1 / v5.9.0, within jane's `^5.1`).

Note: a single-quote-containing payload must avoid inner single quotes (they collide with the outer literal). Use a numeric index (`'.system($_GET[0]).'`), `chr()`, or `base64_decode()` instead of `$_GET['c']`.

## Attack Chain
1. **Entry** — Attacker supplies a schema with an object whose `patternProperties` has a malicious KEY, e.g. `{"type":"object","patternProperties":{"'.phpinfo().'":{"type":"string"}}}`.
   - Guard: `TypeArrayValidator` (OpenApi3). Bypass proof: it is purely diagnostic — only flags `type:[...]` arrays and treats `patternProperties` children as property names; no charset/format check on the key (`TypeArrayValidator.php` `PROPERTY_MAP_KEYS` whitelists traversal, validates nothing). Key accepted unchanged.
2. **Propagation** — key flows guesser → `ClassGuess` → `Jane.php` rekey → generator.
   - Guard: none. Bypass proof: every hop uses `$pattern` as a verbatim array key (`ObjectGuesser::resolveAdditionalProperties` ObjectGuesser.php:92-96; `PatternPropertiesGuesser::addType` PatternPropertiesGuesser.php:45-46; `Jane.php:85-89`; `ClassGuess::getExtensionsType()` ClassGuess.php:111). No `Naming::cleaning()` on extension keys.
3. **Sink emission** — generator builds `new Expr\ConstFetch(new Name("'/" . str_replace('/', '\\/', $pattern) . "/'"))` at the 4 sink sites above.
   - Guard: `str_replace('/', '\\/', ...)`. Bypass proof: payload contains no `/`; it uses `'` (single quote), which `str_replace` does not touch.
4. **Pretty-print** — php-parser prints the node.
   - Guard: AST `Scalar\String_` auto-escaping (the PHPDoc-sink primary defense). Bypass proof: sink uses a `Name` node, not `Scalar\String_`; ran php-parser — key `'.phpinfo().'` prints VERBATIM as `preg_match('/'.phpinfo().'/', (string) $key)` and re-parses as valid PHP.
5. **Execution** — generated normalizer is loaded and the model is (de)serialized → injected expression executes. Live PoC: chr()-encoded `file_put_contents` in the key → generated code `require`d → marker file written. RCE confirmed.

## Bypass Evidence
```
KEY: '.phpinfo().'       → preg_match('/'.phpinfo().'/', (string) $key)        → VALID PHP: YES
KEY: '.system($_GET[0]).'→ preg_match('/'.system($_GET[0]).'/', (string) $key) → VALID PHP: YES
KEY: '.print_r(1).'      → preg_match('/'.print_r(1).'/', (string) $key)       → VALID PHP: YES
LIVE: chr()-encoded file_put_contents payload in key → generated code require'd → marker file WRITTEN ⇒ RCE CONFIRMED
```

## Affected Versions
`<= 8.1.2` (all releases). Sink present since 7.0.0 (introduced in commit `806687e99`); verified present on latest release tag v8.1.2; no fix on any released tag or on HEAD. Fix commit `0ea379dea` (PHPDoc `*/` hardening) does not touch any of the 4 sink files. The vulnerable component is `jane-php/json-schema`; `jane-php/open-api-common`, `jane-php/open-api-3`, and `jane-php/open-api-3-1` inherit the sink via class inheritance.

## Suggested Fix
Emit the regex through an auto-escaped literal — `new Scalar\String_('/' . str_replace('/', '\\/', $pattern) . '/')` — or `preg_quote($pattern, '/')`, at all four sink sites.

---
Reported by **zx (Jace)** — GitHub: @manus-use

## References

- https://github.com/janephp/janephp/security/advisories/GHSA-g9m6-r3rx-75h3

Page: https://cve.now/GHSA-G9M6-R3RX-75H3

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