mirror of
https://github.com/google/nomulus.git
synced 2025-05-15 00:47:11 +02:00
Handle malformed proxy protocol header
If the proxy protocol header contains a malformatted string, such as "PROXY UNKNOWN", instead of throwing and killing the connection, use the TCP source IP as the remote IP. Also changed how the header is read from the buffer, to avoid a potential Netty resource leak. Originally the header is read into another ByteBuf, which needs be be explicit released in order for Netty to reclaim its memory (http://netty.io/wiki/reference-counted-objects.html). Now we just read it into a byte array and let JVM GC it. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=188047084
This commit is contained in:
parent
b39e6c0d7e
commit
00bf8a999f
2 changed files with 47 additions and 8 deletions
|
@ -49,6 +49,20 @@ public class ProxyProtocolHandlerTest {
|
|||
assertThat(channel.isActive()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSuccess_proxyHeaderMalformed_singleFrame() {
|
||||
header = String.format("PROXY UNKNOWN\r\n");
|
||||
String message = "some message";
|
||||
// Header processed, rest of the message passed along.
|
||||
assertThat(channel.writeInbound(Unpooled.wrappedBuffer((header + message).getBytes(UTF_8))))
|
||||
.isTrue();
|
||||
assertThat(((ByteBuf) channel.readInbound()).toString(UTF_8)).isEqualTo(message);
|
||||
// Header malformed.
|
||||
assertThat(channel.attr(REMOTE_ADDRESS_KEY).get()).isNull();
|
||||
assertThat(channel.pipeline().get(ProxyProtocolHandler.class)).isNull();
|
||||
assertThat(channel.isActive()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSuccess_proxyHeaderPresent_multipleFrames() {
|
||||
header = String.format(HEADER_TEMPLATE, 4, "172.0.0.1", "255.255.255.255", "234", "123");
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue