# Refitter allows arbitrary code execution through unescaped OpenAPI paths

Refitter emits OpenAPI path keys unescaped into Refit [Get("...")] attributes, letting a crafted path inject a file class with [ModuleInitializer] that runs at assembly load.

- Payout: Research
- Severity: critical
- Program: Refitter
- Found by: Gal3m, mrostamipoor
- Disclosed: 2026-11-20
- CVE: CVE-2026-63345
- Write-up quality: 7/10
- Original: https://github.com/advisories/GHSA-3fhm-p725-h3g3
- Library page: https://bugbountylibrary.com/r/ghsa%3AGHSA-3fhm-p725-h3g3
- Tags: area:oss domain:oss impact:rce kind:research platform:ghsa sev:critical tech:dotnet technique:chained technique:source-review vuln:command-injection vuln:rce

**Target:** Refitter source generator emitting Refit client attributes from OpenAPI paths
**Root cause:** The paths-object key is interpolated verbatim into the `[Get("<path>")]` attribute string without escaping `"` or `\` or rejecting newlines, unlike the escaped enum/default value sinks. A single-line /-prefixed path passes default OpenAPI validation yet closes the attribute, interface and namespace.
**Steps:**
1. Craft an OpenAPI spec whose path key is a single-line /-prefixed string that closes `[Get("/p")] Task<string> Dummy(); } }`, injects `file class Evil { [System.Runtime.CompilerServices.ModuleInitializer] internal static void Init(){...} }`, then reopens `namespace N2 { public partial interface I2 { [Get("/q")] Task<string> GetU(string id); } }` to keep the file valid.
2. Run Refitter 2.0.0 with default validation (no `--skip-validation`) to generate the client `.cs`.
3. Compile the generated code into a console app and run it; Main need not touch the client.
4. Observe the marker written at assembly load, proving the module initializer executed.
**How found:** Noted that enum/default value sinks are escaped but the path sink is emitted raw; hypothesized a valid single-line /-prefixed path could break out of the attribute string while surviving default OpenAPI validation, then built a spec generator and repro script to confirm execution at assembly load.
**Exploitation:** Attacker supplies or influences the OpenAPI description consumed by Refitter; the generated C# is compiled into the victim application, and the injected [ModuleInitializer] runs when the assembly loads at process startup, executing attacker code with no user interaction.
**Insight:** In code generators, audit every spec-derived string sink separately: escaping applied to one sink (enum/default) does not imply the path/route-template or [Header] sinks are escaped, and validation that only checks path shape still admits quote-breaking payloads.

## Proof of concept (copied exactly from the original report)

**Injected path payload closing attribute and interface**

```
[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);
    }
}
```

