-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Block requests with multiple Host headers #1060
Block requests with multiple Host headers #1060
Conversation
} else if (zuulRequest.getHeaders().getAll(HttpHeaderNames.HOST.toString()).size() > 1) { | ||
LOG.debug( | ||
"Duplicate Host headers. clientRequest = {} , uri = {}, info = {}", | ||
clientRequest.toString(), |
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.
s/.toString()//
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.
LGTM
zuulRequest.getContext(), | ||
ZuulStatusCategory.FAILURE_CLIENT_BAD_REQUEST); | ||
zuulRequest.getContext().setError(ze); | ||
zuulRequest.getContext().setShouldSendErrorResponse(true); |
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.
This will continue the filter chain processing, and actually write a response to the client.
Is that desirable?
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.
Yes, I believe so, but interested in hearing your thoughts. The other option would be to close the connection without a response (we do this a few lines above). It seems best to let the client know what they did wrong.
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.
I'm not aware of a good spec for this case.
My general preference is to not continue filter processing and expend resources writing back a response, when we treat a request as malicious.
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.
For this change, I'm inclined to provide the client a 400 response given that it could impact non-malicious requests. For example, a client or upstream proxy may be accidentally adding the Host header twice. Closing the connection without a response would make it very difficult to troubleshoot this change when it rolls out. I think the better client experience outweighs the extra resource spend here.
@@ -159,6 +158,19 @@ private void channelReadInternal(final ChannelHandlerContext ctx, Object msg) th | |||
ZuulStatusCategory.FAILURE_CLIENT_BAD_REQUEST); | |||
zuulRequest.getContext().setError(ze); | |||
zuulRequest.getContext().setShouldSendErrorResponse(true); | |||
} else if (zuulRequest.getHeaders().getAll(HttpHeaderNames.HOST.toString()).size() > 1) { |
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.
This should be HOST.getName()
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.
HOST is an AsciiString
, that method doesn't resolve for it.
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.
edit: com.netflix.zuul.message.http.HttpHeaderNames
No description provided.