Skip to content

Commit

Permalink
Kick existing connection out if a new one connects from the same IP a…
Browse files Browse the repository at this point in the history
…nd port.

This is only active for cookie enabled connections as it could become an attack vector with spoofed packets.
  • Loading branch information
SupremeMortal committed Jul 24, 2024
1 parent e241646 commit ced5eee
Showing 1 changed file with 6 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,12 @@ public RakServerChannel(DatagramChannel channel, Consumer<RakChannel> childConsu
* @return RakChildChannel instance of new channel.
*/
public RakChildChannel createChildChannel(InetSocketAddress address, long clientGuid, int protocolVersion, int mtu) {
if (this.childChannelMap.containsKey(address)) {
RakChildChannel existingChannel = this.childChannelMap.get(address);
if (this.config().getSendCookie() && existingChannel != null) {
// We know this player is coming from this IP address due to the cookie, so we can safely close the existing channel.
existingChannel.close();
} else if (existingChannel != null) {
// Could be spoofed, so we don't close the existing channel.
return null;
}

Expand Down

0 comments on commit ced5eee

Please sign in to comment.