Repository navigation
Harden KnownProxies/KnownNetworks for non-IP transports - #67817
Conversation
There was a problem hiding this comment.
Pull request overview
This PR hardens ForwardedHeadersMiddleware so that when KnownProxies/KnownNetworks (trusted-proxy enforcement) is configured, forwarded headers are not applied if the request arrives over a transport that does not provide a peer IP (e.g., Unix domain sockets / named pipes). This closes a security gap where enforcement could be bypassed when RemoteIpAddress is unavailable.
Changes:
- Update
ForwardedHeadersMiddleware.ApplyForwardersto fail closed (stop processing) when trusted-proxy enforcement is enabled but the immediate peer IP is not available. - Add new tests covering fail-closed behavior for
KnownProxiesandKnownIPNetworkswhenRemoteIpAddressisnull. - Add a test intended to preserve behavior when enforcement is explicitly disabled (but it currently needs a small fix to actually disable the defaults).
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| src/Middleware/HttpOverrides/src/ForwardedHeadersMiddleware.cs | Fail-closed behavior when enforcement is enabled but no remote peer IP is available. |
| src/Middleware/HttpOverrides/test/ForwardedHeadersMiddlewareTest.cs | New coverage for non-IP transports; one new test needs to explicitly clear default KnownProxies to match its intent. |
Co-authored-by: Copilot Autofix powered by AI <[email protected]>
|
@halter73 and @BrennanConroy please take a look. This needs to go through API review. |
BrennanConroy
left a comment
There was a problem hiding this comment.
General idea looks good, should this be true by default? Also, needs to go through API review.
|
It could be And bunch of our tests would have to set |
|
@BrennanConroy @halter73 I sent the API review request for this thing. Take a look and if you are ok, we can get this merged |
halter73
left a comment
There was a problem hiding this comment.
The implementation looks good, but this is a behavioral breaking change for non-IP transports using the default options. Given the timing, I think we should target .NET 12 so it gets a full preview cycle rather than land it late in .NET 11. We should also add a breaking-change announcement in dotnet/AspNetCore.Docs, covering the default behavior, clearing both allowlists for trusted non-IP-only deployments, and branching the middleware for mixed transports. If we believe the security impact warrants shipping sooner or backporting, that should be an explicit decision with the same announcement in place.
|
@halter73 Definitely 12. |
|
/ba-g Failures are unrelated. |
|
Documented in dotnet/AspNetCore.Docs#38164. |
Fixes #67816