Refitter 2.1.1 through 2.3.1 resolves an escaped remote $ref past its reference guard
Description
Details
Refitter 2.1.1 added src/Refitter.Core/Document/ReferenceGuard.cs; ValidateAsync reads the document as raw text and ExtractReferences (RefPattern at lines 13-15) collects every $ref value before the document is parsed. NJsonSchema then parses it: JsonReferenceResolver.ResolveReferenceAsync sends an http:// or https:// value to JsonSchema.FromUrlAsync, which calls DynamicApis.HttpGetAsync. A JSON document that spells the key as \u0024ref (decoded to $ref) or the URL as http:\/\/host\/schema.json (decoded to http://host/schema.json) is therefore never seen: the regex matches neither the escaped key nor a value beginning with a backslash, and the guard treats the escaped value as a local file path it ignores when the file does not exist. The regex is unchanged in 2.3.1 and in main at 2.4.0-preview.124. The .NET runtime resolution is quoted from NJsonSchema, not executed here; the demo executes the 2.3.1 regex and models the parse-then-fetch in Node.
Proof of Concept
$ printf '%s' '{"openapi":"3.0.0","info":{"title":"t","version":"1"},"paths":{},"components":{"schemas":{"Pet":{"\u0024ref":"http:\/\/127.0.0.1:40961\/schema.json"}}}}' > escaped.json
$ python3 -m http.server 40961 --bind 127.0.0.1
$ refitter --open-api escaped.json # .NET path: NJsonSchema resolves the decoded remote $ref; quoted, not executed on this host
$ node -e 'const R=/["\x27]?\$ref["\x27]?\s*:\s*(?:["\x27]([^"\x27]+)["\x27]|([^\s#][^\s]*))/g;const raw="{\"\\u0024ref\":\"http:\\/\\/127.0.0.1:40961\\/schema.json\"}";const plain="{\"$ref\":\"http://127.0.0.1:40961/schema.json\"}";const saw=s=>[...s.matchAll(R)].map(m=>m[1]??m[2]);console.log("escaped guard matches",saw(raw),"decodes to",JSON.parse(raw)["$ref"]);console.log("plain guard matches",saw(plain));'Impact
The developer or CI host sends the request and writes the remote schema into the generated C#; an attacker-influenced OpenAPI document can therefore reach loopback and internal HTTP services and read their responses into the generated client.
Remediation
No patched release: 2.1.1 through 2.3.1 and 2.4.0-preview.124 carry the raw-text regex; the latest stable is 2.3.1 and affectedProducts names the range.
Disclosure Notes
The .NET runtime path is quoted, not executed: no .NET SDK is installed on the reporting host. The demo executes the 2.3.1 RefPattern and labels its JSON.parse/fetch as a model of NJsonSchema JsonReferenceResolver.ResolveReferenceAsync -> JsonSchema.FromUrlAsync -> DynamicApis.HttpGetAsync. The 2.1.1 guard is a raw-text pre-scan; the original CVE-2026-63184 covers versions before 2.1.1.