Add logging for mismatched Websocket Origin

This commit is contained in:
Thijmen Stavenuiter 2021-01-20 18:05:00 +01:00
parent f9d94197d5
commit ea20237166

View File

@ -6,12 +6,18 @@ import io.netty.channel.ChannelFutureListener;
import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.MessageToMessageCodec; import io.netty.handler.codec.MessageToMessageCodec;
import io.netty.handler.codec.http.websocketx.*; import io.netty.handler.codec.http.websocketx.*;
import org.krews.plugin.nitro.main;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.net.URI; import java.net.URI;
import java.net.URISyntaxException; import java.net.URISyntaxException;
import java.util.List; import java.util.List;
public class WebSocketCodec extends MessageToMessageCodec<WebSocketFrame, ByteBuf> { public class WebSocketCodec extends MessageToMessageCodec<WebSocketFrame, ByteBuf> {
private static final Logger LOGGER = LoggerFactory.getLogger(WebSocketCodec.class);
@Override @Override
protected void encode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception { protected void encode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception {
out.add(new BinaryWebSocketFrame(in).retain()); out.add(new BinaryWebSocketFrame(in).retain());
@ -53,6 +59,7 @@ public class WebSocketCodec extends MessageToMessageCodec<WebSocketFrame, ByteBu
if(origin.equals(entry)) return true; if(origin.equals(entry)) return true;
} }
} }
LOGGER.info("Origin not allowed: " + origin);
return false; return false;
} }
} }