Forwarded Headers Middleware: Ignore XForwardedHeaders from Unknown Proxy #61530
+82
−9
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Forwarded Headers Middleware: Ignore XForwardedHeaders from Unknown Proxy
Fixes a bug where, under some conditions,
XForwardedPrefix
,XForwardedProto
andXForwardedHost
headers could be tampered with.Description
This PR makes sure that XForwarded-Headers are only interpreted when they come from a known proxy. As suggested by the documentation..
If the
ForwardedHeaders.XForwardedFor
flag inForwardedHeadersOptions
isn't set. TheForwardedHeadersMiddleware
doesn't check if the request comes from a known proxy.This means that with the following
ForwardedHeadersOptions
(or any other combination whereForwardedHeaders.XForwardedFor
is missing):the respective
X-Forwarded
-headers will be always processed by the middleware which have some (security related?) side effects:XForwardedPrefix
setscontext.Request.PathBase
XForwardedProto
setscontext.Request.Scheme
XForwardedHost
setscontext.Request.Host
With
ForwardedHeadersOptions
set toForwardedHeaders.All
no side effects would have been executed.Fixes #61449
This observation has been reported by me via the
MSRC
-Portal but was classified as a product bug. The following information may be related: aspnet/Announcements#295