Fix RPL_LOGGEDIN Prematurely Triggering CAP END #391
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This will fix Issue #390.
The bug is that per the SASL spec, sending CAP END before the IRCd has finalized your SASL authentication is treated as a SASL Abort and the authentication will fail. The 900 (RPL_LOGGEDIN numeric does not necessarily mean the IRCd has completely finished handling the SASL, and therefore, sending CAP END upon the receipt of RPL_LOGGEDIN can trigger a race condition where SASL authentication will fail.
This was observed after much frustration trying to code a bot that was attempting to SASL PLAIN on a nefarious2 IRCd and I noticed that when I installed breakpoints around the SASL AUTHENTICATE commands, it seemed to work fine, but reverted to not working upon removing said breakpoints.
The solution is to simply remove the CAP END's parent IF block in the RPL_LOGGEDIN handler. Upon testing, the race condition has seemingly been removed.
All unit tests continue to pass with this change.