Skip to content

Commit 31bc13d

Browse files
authored
Merge commit from fork
* Don't pass message on to next handler on authentication failures * Add change log * Formatting nit
1 parent 0b8ac54 commit 31bc13d

File tree

3 files changed

+28
-1
lines changed

3 files changed

+28
-1
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
type = "s"
2+
message = "Fixed authentication issue for HTTP inputs. [GHSA-q7g5-jq6p-6wvx](https://github.com/Graylog2/graylog2-server/security/advisories/GHSA-q7g5-jq6p-6wvx)"

graylog2-server/src/main/java/org/graylog2/inputs/transports/netty/HttpHandler.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ protected void channelRead0(ChannelHandlerContext ctx, HttpRequest request) thro
6161
final String suppliedAuthHeaderValue = request.headers().get(authorizationHeader);
6262
if (isBlank(suppliedAuthHeaderValue) || !suppliedAuthHeaderValue.equals(authorizationHeaderValue)) {
6363
writeResponse(channel, keepAlive, httpRequestVersion, HttpResponseStatus.UNAUTHORIZED, origin);
64+
return;
6465
}
6566
}
6667

graylog2-server/src/test/java/org/graylog2/inputs/transports/netty/HttpHandlerTest.java

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@
1616
*/
1717
package org.graylog2.inputs.transports.netty;
1818

19+
import io.netty.buffer.ByteBuf;
20+
import io.netty.channel.ChannelHandlerContext;
21+
import io.netty.channel.SimpleChannelInboundHandler;
1922
import io.netty.channel.embedded.EmbeddedChannel;
2023
import io.netty.handler.codec.http.DefaultFullHttpRequest;
2124
import io.netty.handler.codec.http.DefaultHttpRequest;
@@ -235,7 +238,8 @@ private void testAuthentication(String expectedAuthHeader, String expectedAuthHe
235238

236239
httpRequest.content().writeBytes(GELF_MESSAGE);
237240

238-
channel = new EmbeddedChannel(new HttpHandler(true, expectedAuthHeader, expectedAuthHeaderValue, "/gelf"));
241+
final DownstreamHandler downstreamHandler = new DownstreamHandler();
242+
channel = new EmbeddedChannel(new HttpHandler(true, expectedAuthHeader, expectedAuthHeaderValue, "/gelf"), downstreamHandler);
239243
channel.writeInbound(httpRequest);
240244
channel.finish();
241245

@@ -248,5 +252,25 @@ private void testAuthentication(String expectedAuthHeader, String expectedAuthHe
248252
assertThat(headers.get(ACCESS_CONTROL_ALLOW_CREDENTIALS)).isEqualTo("true");
249253
assertThat(headers.get(ACCESS_CONTROL_ALLOW_HEADERS)).isEqualTo("Authorization, Content-Type");
250254
assertThat(headers.get(CONNECTION)).isEqualTo(HttpHeaderValues.CLOSE.toString());
255+
if (expectedStatus == HttpResponseStatus.ACCEPTED) {
256+
assertThat(downstreamHandler.received).isTrue();
257+
}else if (expectedStatus == HttpResponseStatus.UNAUTHORIZED) {
258+
assertThat(downstreamHandler.received).isFalse();
259+
} else {
260+
throw new AssertionError("Unexpected status: " + expectedStatus);
261+
}
262+
}
263+
264+
/**
265+
* Downstream handler for confirming that authorization failures halt message flow, and that message flow continues
266+
* for authentication successes.
267+
*/
268+
private class DownstreamHandler extends SimpleChannelInboundHandler<ByteBuf> {
269+
public boolean received = false;
270+
271+
@Override
272+
protected void channelRead0(ChannelHandlerContext channelHandlerContext, io.netty.buffer.ByteBuf httpRequest) throws Exception {
273+
this.received = true;
274+
}
251275
}
252276
}

0 commit comments

Comments
 (0)