-
Notifications
You must be signed in to change notification settings - Fork 442
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Handle multivalue X-Forwarded-Proto header #5242
Conversation
@brettsam I pushed another change to only register this middleware in linux consumption. It shouldn't be in the CLI or the runtime generically like it was. |
@@ -29,7 +29,7 @@ public async Task Invoke(HttpContext httpContext) | |||
|
|||
if (httpContext.Request.Headers.TryGetValue(ForwardedProtocolHeader, out value)) | |||
{ | |||
httpContext.Request.Scheme = value; | |||
httpContext.Request.Scheme = value.FirstOrDefault(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be .First()
so that if there's an empty value it blows up here rather than causing a NullReferenceException
further down the pipeline? (Unless a null
for request. Scheme
is valid?)
Unless you want to treat empty header values as valid (which seems to be quite the discussion) in which case should it fallback to not overwriting the scheme if there's no value?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point. I don't think a null scheme, but I think it makes sense to not overwrite it if the header happens to be empty for any reason. Thanks @NickDarvey
15abdf2
to
e1b0c2d
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A nit and a small question.
@@ -29,7 +29,11 @@ public async Task Invoke(HttpContext httpContext) | |||
|
|||
if (httpContext.Request.Headers.TryGetValue(ForwardedProtocolHeader, out value)) | |||
{ | |||
httpContext.Request.Scheme = value.FirstOrDefault(); | |||
var scheme = value.FirstOrDefault(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: var
-> string
@@ -29,7 +29,11 @@ public async Task Invoke(HttpContext httpContext) | |||
|
|||
if (httpContext.Request.Headers.TryGetValue(ForwardedProtocolHeader, out value)) | |||
{ | |||
httpContext.Request.Scheme = value.FirstOrDefault(); | |||
var scheme = value.FirstOrDefault(); | |||
if (scheme != null) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we end up with an empty string here as well?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
as NickDarvey mentioned, an empty header value is a malformed header. TryGetValue returns false if the header is passed as empty from the client, so I was assuming aspnet will do validation on these things before passing the request to the application. !string.IsNullOrEmpty()
won't hurt though, even if technically not valid per https://tools.ietf.org/html/rfc7230#section-3.2
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense, just wanted to make sure it's something we had validated/thought about.
e1b0c2d
to
02b4f06
Compare
02b4f06
to
28ba9d9
Compare
Closes #5198