Repository navigation
Fix #155, #201: Send a long SMTP initial response after the challenge - #215
Merged
jmehrens merged 4 commits intoOct 18, 2026
Merged
Conversation
…onse after the challenge The AUTH command was always sent with the initial response, if the mechanism has one. With an XOAUTH2 access token of about a thousand characters or more the command line exceeds the SMTP limit of 512 octets (RFC 5321), and servers such as Google's reject it with "500 5.5.2 Line too long" or "555 5.5.2 Syntax error, command line too long". RFC 4954 requires the client not to send the initial response in that case, but to send it in reply to the first, empty, challenge. Do so both for the built-in mechanisms and for SASL, when the AUTH command with the initial response would be longer than the limit. Shorter initial responses are still sent with the AUTH command. Signed-off-by: Sharang Gupta <sharang@sharanggupta.dev>
jmehrens
requested changes
Oct 17, 2026
jmehrens
left a comment
Contributor
There was a problem hiding this comment.
Update the changes.txt to include your bug number and title.
Signed-off-by: Sharang Gupta <sharang@sharanggupta.dev>
Subtract the fixed parts and the mechanism from the line length limit and compare the initial response with what is left, so that no sum of lengths can overflow. Test the limit and add eclipse-ee4j#155 and eclipse-ee4j#201 to the changes. Signed-off-by: Sharang Gupta <sharang@sharanggupta.dev>
Contributor
Author
jmehrens
approved these changes
Oct 18, 2026
Contributor
|
@bbottema let me know if it is okay to merge this given what you are working on. |
Contributor
|
@jmehrens yes, please go ahead and merge it. I'll handle any conflicts in my branches. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Fixes #155 and #201.
What
The SMTP provider always sends the initial response of a mechanism with the
AUTHcommand. With XOAUTH2 the initial response contains the access token,, and tokens of a thousand characters or more occur, for example with Google Workspace domain-wide delegation as in #201. The command line then exceeds the SMTP limit of 512 octets including CRLF (RFC 5321, section 4.5.3.1.4), and servers reject it:500 5.5.2 Line too longin SMTP Sasl authentication failed : password is too long #155, with SASL;555-5.5.2 Syntax error, command line too longfrom Google in SMTP XOAUTH2 authentication fails with large access tokens #201, through the Jenkins email-ext plugin.RFC 4954, section 4, covers this case: if the initial response would make the
AUTHcommand exceed the line length limit, the client must not send it with the command. It must sendAUTH <mechanism>alone and give the response in reply to the server's first, empty334challenge, a line that has no such limit.How
SMTPTransport.fitsAuthCommand(mech, ir)checks whetherAUTH <mech> <ir>fits in 510 characters, which is the 512 octets without the CRLF.SMTPTransport.Authenticator.authenticate(), used by PLAIN, XOAUTH2 and the other built-in mechanisms, andSMTPSaslAuthenticator.authenticate()both defer an initial response that does not fit. They sendAUTH <mech>, then the initial response in reply to the first334. What follows is unchanged, including the530/STARTTLS retry.Tests
SMTPOAuth2Testuses a newSMTPOAuth2Handler. The handler rejects command lines longer than 510 characters with500 5.5.2 Line too long, as the servers above do, and accepts the token either with theAUTHcommand or after a334. It connects with a short token and with a 1500-character token, each with and without SASL. Onmasterboth long-token tests fail (AuthenticationFailedException: 500 5.5.2 Line too long, andfailed to connectwith SASL), and all four pass with this change.The CI build (
clean verifywith the copyright check and theoss-release,staging,build-onlyprofiles) passes locally on JDK 17.