Skip to content

Keep a configured Kestrel endpoint unless --port is given [patch] - #141

Merged
matt-edmondson merged 3 commits into
mainfrom
fix/140-configured-kestrel-endpoint
Nov 4, 2026
Merged

matt-edmondson merged 3 commits into
mainfrom
fix/140-configured-kestrel-endpoint

Conversation

@matt-edmondson

Copy link
Copy Markdown
Contributor

Fixes #140

What changed

GitLfsCache.Tool/Program.cs defaulted --port to 8080 and then wrote Kestrel:Endpoints:Http:Url = http://*:<port> after every other configuration source. So a port or bind address set in appsettings, a --config file or Kestrel__Endpoints__Http__Url was always overwritten, and the proxy always listened on every interface. GitLfsCache.Service links the same file, so the container image was affected too.

  • --port now stays int? all the way into RunAsync.
  • A new Program.ApplyListenPort puts the endpoint into the flag overrides, which are layered over configuration like every other flag:
    • when --port is given, http://*:<port>, which wins over configuration;
    • when it isn't and configuration already has a Kestrel:Endpoints section, urls, http_ports or https_ports, nothing, so the configured endpoint is used;
    • otherwise http://*:8080, the same default as before.
  • The --port help text now says when the 8080 default applies.

GitBranchStateCache#98 has the same defect. It isn't attached to this run, so it isn't changed here.

Tests

New GitLfsCache.Tests/Tool/PortFlagTests.cs covers the issue's acceptance criteria:

  • no flag + configured Kestrel:Endpoints:Http:Url → the configured URL wins
  • no flag + urls / http_ports / https_ports / an HTTPS-only endpoint → no HTTP endpoint is forced
  • --port 9000 → http://*:9000, even over a configured endpoint
  • neither → http://*:8080

To check the tests catch the bug, I temporarily restored the old behaviour (always write http://*:{port ?? 8080}). The two "configured endpoint" tests failed, and they pass with the fix. Full suite: 449 passed, 0 failed.


Generated by Claude Code

The host wrote Kestrel:Endpoints:Http:Url = http://*:<port> after every other configuration
source, with the port defaulting to 8080, so a port or bind address set in appsettings, a
--config file or Kestrel__Endpoints__Http__Url was always overwritten and the proxy listened
on every interface. The endpoint is now written only when --port is given, or when
configuration names no Kestrel endpoint, urls, http_ports or https_ports of its own.

Fixes #140

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017vfJW6NRQ27ovPhjARcxRW

Copy link
Copy Markdown
Contributor Author

SonarCloud Quality Gate: "B Security Rating on New Code"

I can't see which finding this is. The SonarCloud project isn't readable anonymously, and the issues API returns nothing for this PR. The only new non-test code that could plausibly lower the security rating is the endpoint string in Program.ApplyListenPort, $"http://*:{port}". That looks like a match for rule S5332 ("Using clear-text protocols is security-sensitive"). The old line 182 had the same http://*: literal, but this PR moved and rewrote it, so Sonar now counts it as new code.

I haven't changed it, because plain HTTP is deliberate and isn't new behaviour. main already binds http://*:8080, and TLS terminates at the ingress (see the forwarded-headers setup right below). The fix also makes this safer: an operator can now bind to 127.0.0.1 or configure an HTTPS endpoint. Rewording the literal just to get past the scanner would hide the finding without changing anything.

It needs a maintainer's call. Either mark the finding as reviewed/safe in SonarCloud, or tell me you'd prefer a // NOSONAR with that justification, and I'll push it.

All CI test jobs (ubuntu, windows, macos) and CodeQL pass.


Generated by Claude Code

S5332 flagged the http:// endpoints ApplyListenPort writes, which failed the
security rating on new code. They are the proxy's own listen addresses, the
same plain-HTTP default main already uses, so suppress the rule on that one
method with the reason.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017vfJW5jpiuVuBRXSgitSY1
@sonarqubecloud

sonarqubecloud Bot commented Nov 4, 2026

Copy link
Copy Markdown

@matt-edmondson
matt-edmondson merged commit 0c2a377 into main Nov 4, 2026
15 checks passed
@matt-edmondson
matt-edmondson deleted the fix/140-configured-kestrel-endpoint branch November 4, 2026 02:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants