From 86641016878f17b641ebe1907d8a76df7ace34b2 Mon Sep 17 00:00:00 2001 From: jianglai Date: Thu, 2 Aug 2018 12:14:22 -0700 Subject: [PATCH] Make web WHOIS more resilient to malformed requests We are seeing some web WHOIS HTTP(S) requests made to our endpoints without the Host header specified. This is an error according to the HTTP/1.1 spec. However we do not want to spam our logs with errors that are outside of our control. Do not throw and return a 400 response instead. Also re-worked the logic a bit to only return HSTS headers if we send a redirect response, not any other error responses. The tests are re-arrange to correspond with the logical flow in the code. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=207143230 --- .../handler/WebWhoisRedirectHandler.java | 18 ++- .../handler/WebWhoisRedirectHandlerTest.java | 143 ++++++++++++------ 2 files changed, 108 insertions(+), 53 deletions(-) diff --git a/java/google/registry/proxy/handler/WebWhoisRedirectHandler.java b/java/google/registry/proxy/handler/WebWhoisRedirectHandler.java index b0b77062a..7e4b9a635 100644 --- a/java/google/registry/proxy/handler/WebWhoisRedirectHandler.java +++ b/java/google/registry/proxy/handler/WebWhoisRedirectHandler.java @@ -22,6 +22,7 @@ import static io.netty.handler.codec.http.HttpHeaderNames.LOCATION; import static io.netty.handler.codec.http.HttpHeaderValues.KEEP_ALIVE; import static io.netty.handler.codec.http.HttpHeaderValues.TEXT_PLAIN; import static io.netty.handler.codec.http.HttpMethod.GET; +import static io.netty.handler.codec.http.HttpResponseStatus.BAD_REQUEST; import static io.netty.handler.codec.http.HttpResponseStatus.FORBIDDEN; import static io.netty.handler.codec.http.HttpResponseStatus.FOUND; import static io.netty.handler.codec.http.HttpResponseStatus.METHOD_NOT_ALLOWED; @@ -30,6 +31,7 @@ import static io.netty.handler.codec.http.HttpResponseStatus.OK; import static io.netty.handler.codec.http.HttpVersion.HTTP_1_1; import com.google.common.base.Splitter; +import com.google.common.base.Strings; import com.google.common.flogger.FluentLogger; import io.netty.channel.ChannelFuture; import io.netty.channel.ChannelFutureListener; @@ -88,6 +90,8 @@ public class WebWhoisRedirectHandler extends SimpleChannelInboundHandler