79% vs 51%: independent neobanks lag on app security. Read the report

Deep Dive

Deep Dive

Refitter OpenAPI Code Injection RCE (CVE-2026-63344)

A crafted OpenAPI description makes Refitter emit a C# module initializer, so the generated client runs attacker code at startup; fixed in 2.1.2.

TL;DR

  • Refitter copies OpenAPI paths, header names and content-type keys into C# attribute strings without escaping quotes, so a crafted description injects a [ModuleInitializer] that runs when the generated assembly loads.
  • Three advisories cover the path, header-name and content-type sinks. GitHub rates each Critical; the CVE records score each CVSS v4.0 8.6 High with user interaction required.
  • Refitter before 2.1.2 is affected. The fix shipped in 2.1.2 on 2026-07-29, and 2.4.0 is current. No in-the-wild exploitation has been reported, and the CVEs are not in CISA KEV as of 2026-11-20.
  • Upgrade to 2.1.2 or later, regenerate every client, and treat OpenAPI descriptions from outside your repository as code you have to review.

Am I affected?

All of these must hold:

  • You run Refitter before 2.1.2, as the global tool or a project package.
  • You generate a client from an OpenAPI description that an attacker controls or can influence.
  • The generated C# is compiled into an assembly that you or your build pipeline loads.

Refitter is a code generator for .NET. It turns an OpenAPI description into an interface that uses the Refit library. The vulnerability is in the generator, not in the generated HTTP client at run time. Default OpenAPI validation does not block the payload, so --skip-validation is not needed.

OpenAPI descriptions rarely stay inside one repository. Teams import them from a partner, a customer, a public API or an internal service catalog, and they update them when the remote API changes. A description that is fetched by a build job, stored in a shared repository or generated from a documentation site is attacker-influenced if any of those paths can be changed.

The generator runs on the build host, so the code it emits is compiled with the build host's permissions.

Refitter version Affected Fixed version
Before 2.1.2 Yes 2.1.2
2.1.2 and later No Fixed

Check the tool and every project that references the package:

dotnet tool list --global
refitter --version
dotnet list package | grep -i refitter

The global tool list shows the installed Refitter version. The project command shows a package reference in the current solution. A version earlier than 2.1.2 needs the upgrade, even if the project last regenerated its client months ago.

How do I fix it?

Upgrade Refitter to 2.1.2 or later and regenerate every client. The fix is in the generator, so a client generated by an older version stays unsafe until it is regenerated.

  1. Update the global tool: bash dotnet tool update --global Refitter
  2. Update a project package to 2.1.2 or later: bash dotnet add package Refitter --version 2.1.2
  3. Regenerate each client with the fixed tool and commit the regenerated files. Compare the diff with the old client before you commit it.
  4. Review the OpenAPI descriptions you generate from. Treat a description from a partner, a customer or a public URL as source code, and review changes to its paths, header names and content types.
  5. If a description has to come from an untrusted source, generate in a disposable environment and inspect the output before it reaches a build that has secrets.

What is the root cause?

Refitter writes C# source text by interpolating values from the OpenAPI document into attribute strings. It does not escape the values for a C# string literal. A double quote in a path, a header name or a content-type key ends the attribute string, and the rest of the value becomes C# source.

The path sink at version 2.0.0 builds the verb attribute like this:

code.AppendLine($"{Separator}{Separator}[{verb}(\"{op.Path}\")]")

The content-type sink builds the Headers attribute like this:

headers.Add($"\"Accept: {string.Join(", ", uniqueContentTypes)}\"");
headers.Add($"\"Content-Type: {contentType}\"");

The header-parameter sink builds the Header attribute like this:

return $"{ParameterShared.JoinAttributes($"Header(\"{p.Name}\")")}{ParameterShared.GetParameterType(p, settings)} {variableName}";

Each value comes from the OpenAPI document. The generator trusts it to be a plain string, so it never escapes a quote, a backslash or a control character.

The three advisories cover three different places where the same mistake appears. The path sink is the route template in the verb attribute. The content-type sink is the Accept and Content-Type values in the Headers attribute. The header sink is the parameter name in the Header attribute.

A fix in one sink would not close the other two, which is why the release changes all three and adds a validator that checks the whole document.

C# has no safe way to place an arbitrary string inside an attribute literal without escaping it. A quote ends the literal, a backslash starts an escape sequence, and a newline ends the line. The generator writes the value with string interpolation, so the compiler sees whatever the document contains as source text.

The injected text only has to be valid C# and keep the file balanced, which the file class and the reopened namespace achieve.

How is it exploited?

  1. The attacker supplies an OpenAPI description with a malicious path key, header parameter name or content-type key. The value stays on one line, so the default OpenAPI parser accepts it.
  2. Refitter interpolates the value into a [Get("...")], [Header("...")] or [Headers("...")] attribute. The quote in the value closes the attribute string.
  3. The rest of the value closes the enclosing interface and namespace, declares a top-level file class with a [ModuleInitializer] method, and reopens a namespace and interface so the generated file still compiles.
  4. The application or CI job compiles the generated file into an assembly. The .NET runtime runs every [ModuleInitializer] when it loads that assembly, before the application's Main method.
  5. The injected method runs with the permissions of the process that loads the assembly. In a build agent, that process can read source, secrets and signing material.

The advisory for the path sink gives this payload shape:

[Get("/p")] Task<string> Dummy(); } }
file class Evil { [System.Runtime.CompilerServices.ModuleInitializer]
  internal static void Init(){ /* attacker code */ } }
namespace N2 { public partial interface I2 { [Get("/q")]
        Task<string> GetU(string id);
    }
}

The reproduce.sh in each advisory generates a client with default validation, compiles it into a console application, and shows a marker written when the assembly loads. The application's Main method never calls the generated client.

A .NET module initializer is a static method that the runtime calls when it loads the module, before any other code in the assembly. The runtime does not need the application to call the generated interface, and it does not need a request to the remote API. Compiling the generated file is enough.

In a build pipeline, that moment is usually the compile step, which runs on an agent that holds package-feed tokens, signing keys and deployment credentials.

How does the attack flow?

A value from the OpenAPI description escapes its C# string literal, becomes a module initializer in the generated file, and runs when the assembly loads.

flowchart LR A["Attacker-influenced
OpenAPI description"] --> B["Refitter inserts the value
into an attribute string"] B --> C["A quote closes
the attribute and namespace"] C --> D["Injected file class
with ModuleInitializer"] D --> E["Generated client
compiles"] E --> F["Initializer runs
at assembly load"]

What can an attacker do?

The attacker runs code in the process that loads the generated assembly. In a developer workstation or a CI runner, that code can read environment variables, source files, package feeds and build secrets, and can change the build output.

Every condition has to hold:

  • The victim runs an affected Refitter version.
  • The victim generates a client from a description the attacker controls or influences.
  • The generated code is compiled and loaded.
  • The attacker can place a payload that survives the OpenAPI parser and the C# compiler.

The CVE records score the flaws CVSS v4.0 8.6 with UI:A, because a person has to generate and build the client. The advisory authors estimate a higher impact when the build runs unattended. No in-the-wild exploitation has been reported.

A developer workstation and a build agent expose different things. A workstation has the developer's source checkout, SSH keys and browser sessions. A build agent has the tokens that publish packages, sign binaries and deploy to production, and it often has network access to the artifact registry and the cloud account. The same injected initializer runs in both places, so the impact depends on where the generated client is compiled.

Why does the fix work?

The fix escapes every spec-derived value before it enters an attribute string, and it rejects unsafe values during the default validation pass. The path change is:

- code.AppendLine($"{Separator}{Separator}[{verb}(\"{op.Path}\")]")
+ code.AppendLine($"{Separator}{Separator}[{verb}(\"{ParameterShared.EscapeString(op.Path)}\")]")

The content-type and header-name sinks use the same EscapeString call. EscapeString now also converts control characters to \uXXXX, so a newline or another control byte cannot break the line:

- sb.Append(c);
+ if (char.IsControl(c))
+     sb.Append($"\\u{(int)c:X4}");
+ else
+     sb.Append(c);

The release also adds AttributeStringValidator, which rejects a path, header name, content-type key or API-key security-scheme name that contains a quote, a backslash or a control character:

internal static bool ContainsUnsafeCharacters(string? value) =>
    value != null && value.Any(c => c is '"' or '\\' || char.IsControl(c));

The validator runs inside the default OpenAPI validation, so the payload now fails with a clear error. The escaping remains in place for anyone who passes --skip-validation, so the generated string is still safe.

The validator checks paths, header parameter names, content-type keys and API-key security-scheme names, which are the attribute sinks the advisories found. It does not change the OpenAPI parser or the Refit library. A description that uses a quote for a legitimate reason now fails validation instead of producing broken code, so a build that used to pass may need the description corrected.

How do I check if I was compromised?

A generated Refit client should not contain a module initializer or a top-level file class. Search the generated sources:

grep -RIn --include='*.cs' -E 'ModuleInitializer|file class' <generated-client-directory>

Also review the descriptions you generated from. Look for a quote, a backslash or a control character in a path key, a header parameter name or a content-type key. Those characters are what the payload needs. In a JSON description they appear as escape sequences, so search for any backslash escape:

grep -RIn -E '\\["\\bfnrtu]' <openapi-specs-directory>

For a YAML description, convert it to JSON first, for example with yq -o=json, and run the same search on the output.

A hit is a lead, not proof. A legitimate generated client can contain a ModuleInitializer if you added one yourself, and a description can contain an escaped quote for a legitimate reason. Check the commit that added the generated file and the description revision it came from. No vendor indicators of compromise have been published.

Timeline

  • 2026-07-29: Refitter 2.1.2 is released with the escaping and the validation fix.
  • 2026-10-30: The three CVE records are published.
  • 2026-11-20 00:06 UTC: The three GitHub advisories are published with the reproduction scripts.

Fix shipped 114 days before the public advisories
Figure 1: Refitter shipped the fix 114 days before the public advisories. Source: Refitter releases and GitHub advisories, checked November 20, 2026.

FAQ

Does default validation block the payload? No. The advisories say no --skip-validation is required. The malicious value survives the default OpenAPI validation and reaches the generator.

Is Refitter 2.1.2 enough? Yes. 2.1.2 contains the escaping and the validator. The current release is 2.4.0, so upgrading to the latest version also works.

Is the generated client dangerous at run time? Only if it was generated by an affected version from a malicious description. The injected initializer runs when the assembly loads, before the client makes any HTTP request. Regenerate the client with a fixed tool to remove it.

Was it exploited in the wild? No in-the-wild exploitation has been reported. The advisories include public reproduction scripts, so the technique is public.

Do I need to rotate secrets? Rotate every secret the build or developer process could read if you find an injected initializer or cannot rule one out. The payload runs with the permissions of that process.

What if the description is trusted? A description from your own repository is still an input that changes. Review changes to its paths, header names and content types, and regenerate with a fixed tool. Trusting the source is not a substitute for the fix.

Does regenerating remove an injected initializer? Yes, if the new client is generated by 2.1.2 or later from a description that passes validation. Delete the old generated files before you regenerate, and check the diff for a file class or a ModuleInitializer that you did not add.

Find vulnerable Refitter versions with Ostorlab

Ostorlab's software composition analysis and SBOM inventory the packages and tools your projects and build images use, so you can find the Refitter versions that need the upgrade. See how Ostorlab SCA and SBOM work.

References

  • GitHub advisory GHSA-p32v-8v8j-j534, "Refitter allows arbitrary code execution through unescaped OpenAPI content-type values" (2026-11-20). https://github.com/christianhelle/refitter/security/advisories/GHSA-p32v-8v8j-j534 (checked November 20, 2026)
  • GitHub advisory GHSA-3fhm-p725-h3g3, "Refitter allows arbitrary code execution through unescaped OpenAPI paths" (2026-11-20). https://github.com/christianhelle/refitter/security/advisories/GHSA-3fhm-p725-h3g3 (checked November 20, 2026)
  • GitHub advisory GHSA-58x9-vjvp-6mx8, "Refitter allows code execution through unescaped OpenAPI header parameter names" (2026-11-20). https://github.com/christianhelle/refitter/security/advisories/GHSA-58x9-vjvp-6mx8 (checked November 20, 2026)
  • CVE record CVE-2026-63344. https://www.cve.org/CVERecord?id=CVE-2026-63344 (checked November 20, 2026)
  • CVE record CVE-2026-63345. https://www.cve.org/CVERecord?id=CVE-2026-63345 (checked November 20, 2026)
  • CVE record CVE-2026-63346. https://www.cve.org/CVERecord?id=CVE-2026-63346 (checked November 20, 2026)
  • Refitter 2.1.2 release, "Fix RCE attribute injection in generated Refit clients" (2026-07-29). https://github.com/christianhelle/refitter/releases/tag/2.1.2 (checked November 20, 2026)
  • Fix pull request #1178, escape spec-derived attribute strings and add the validator. https://github.com/christianhelle/refitter/pull/1178 (checked November 20, 2026)
  • Fix commit ab4d8e439d6f0ee82ad49ee15323978d70fe5a67, "fix: escape spec-derived media types in Headers attribute". https://github.com/christianhelle/refitter/commit/ab4d8e439d6f0ee82ad49ee15323978d70fe5a67 (checked November 20, 2026)
  • Fix commit 793d2632899c2022511dfc15e30725ef69073973, "fix: escape OpenAPI path in Refit verb attribute". https://github.com/christianhelle/refitter/commit/793d2632899c2022511dfc15e30725ef69073973 (checked November 20, 2026)
  • Fix commit 63a19b03699a9c267d6fab5f758ec26484db83a1, "fix: escape header parameter and security scheme names". https://github.com/christianhelle/refitter/commit/63a19b03699a9c267d6fab5f758ec26484db83a1 (checked November 20, 2026)
  • NuGet package Refitter, 12,794,526 total downloads and current version 2.4.0. https://www.nuget.org/packages/Refitter (checked November 20, 2026)
  • CISA Known Exploited Vulnerabilities catalog, catalog version 2026.11.18. https://www.cisa.gov/sites/default/files/feeds/known_exploited_vulnerabilities.json (checked November 20, 2026)