Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix intent issues in InitialHandler #3532

Open
wants to merge 9 commits into
base: master
Choose a base branch
from

Conversation

Outfluencer
Copy link
Contributor

It is possible to make the server call an infinit amount of events, while an event-callback waits for all Intents to be completed, to change to a new state.

Adding an State for Ping and for Login Events is the simplest way to fix this.

This fixes multiple sending of legacy packets, it is possible to send LegacyPing and while the event call is waiting for all intents to be complete send an Legacy Handshake or a normal handshake and establish a real connection while the legacy ping event is running in the background, because the state is handshake and the channel not closed instanly but waiting for the intents to be completed.

It is also possible to call the PreLoginEvent infinite times, while the first one is waiting for a registered intend, which could potentially crash the server, if exploited.

Also it is possible to send a Ping Packet to the Server befor the server sent the StatusResponse to the client if an intend is registered for the ServerPingEvent. This should not be possible.

It is possible to make the server call an infinit amount of events, while an event-callback waits for all Intents to be completed, to change to a new state.

Adding an State for Ping and for Login Events is the simplest way to fix this.

This fixes multiple sending of legacy packets, it is possible to send LegacyPing and while the event call is waiting for all intents to be complete send an Legacy Handshake or a normal handshake and establish a real connection while the legacy ping event is running in the background, because the state is handshake and the channel not closed instanly.

It is also possible to call the PreLoginEvent infinite times, while the first one is waiting for a registered intend, wich could potentially crash the server, if abused.

Also it was possible to send a Ping Packet to the Server befor the server sent the StatusResponse to the client if an intend is registered for the ServerPingEvent. This should not be possible.
@andreasdc
Copy link

Sounds unsafe.

@Outfluencer
Copy link
Contributor Author

yeah thats why we should fix it haha

}

private boolean canSendKickMessage()
{
return thisState == State.USERNAME || thisState == State.ENCRYPT || thisState == State.FINISHING || thisState == State.CONFIGURING;
return thisState == State.USERNAME || thisState == State.ENCRYPT || thisState == State.FINISHING || thisState == State.CONFIGURING || thisState == State.EVENT_LOGIN;
Copy link
Contributor

@Janmm14 Janmm14 Sep 26, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe we can reorder event_ping before username in the enum and check ordinal >= username.ordinal or so?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think it should be fine now

@Janmm14
Copy link
Contributor

Janmm14 commented Sep 26, 2023

For PING, there is no state problem with async events or ping passthrough in the current code.
Although the state change was at the end of the method, it is outside any callback.

Edit:
We should still not allow clients to send PingPacket before we sent the motd - the enum value EVENT_PING should be renamed.

Maybe we can also rename EVENT_LOGIN enum value. I think PROCESSING instead of EVENT fits better.

@Outfluencer
Copy link
Contributor Author

Outfluencer commented Sep 26, 2023

For PING, there is no state problem with async events or ping passthrough in the current code. Although the state change was at the end of the method, it is outside any callback.

Edit: We should still not allow clients to send PingPacket before we sent the motd - the enum value EVENT_PING should be renamed.

Maybe we can also rename EVENT_LOGIN enum value. I think PROCESSING instead of EVENT fits better.

Why should the EVENT_PING enum be renamed it is exactly the case, the state is set to it only while the Proxy Ping Event is still in progress.

we can use the finishing emun for the PreLoginEvent.
@Outfluencer
Copy link
Contributor Author

Outfluencer commented Sep 26, 2023

I removed the EVENT_LOGIN enum and used the FINISHING enum for the PreLoginEvent as it was appropriate in this case

The finishing enum also was only used before to make it impossible to send a second Encryption response
so we can use it for the LoginRequest as well

@md-5
Copy link
Member

md-5 commented Oct 6, 2023

This needs to be updated due to changes

@Outfluencer
Copy link
Contributor Author

i'm using disconnect method now as i think you more like the look of the word disconnect in the code

…ent is called

this should improve the performace a little but for already closed or closing connections
@Outfluencer
Copy link
Contributor Author

Outfluencer commented Oct 6, 2023

I am using isClosing only for all related to Player Login, because isClosing and isClosed is bassicly the same in Ping protocol as the handler boss only set both onDisconnect after that normal channelwrapper.close method is called that sets both to true.

And i use it instead if isclosed for all login events because, we dont need to handle more for a player who's connection is already scheduled to be closed

@andreasdc
Copy link

Not merged yet?

i thought about it and Janmm14 was right, it sounds better
@Outfluencer
Copy link
Contributor Author

i hope its acceptable now

@andreasdc
Copy link

It's safe to use from my perspective, simple change, but overdescribed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants