Skip to content

Commit 4848153

Browse files
committed
🐛 Fix empty SASL-IR to send "="
As per RFC-4959 and RFC-9051: > To send a zero-length initial response, the client MUST send a single > pad character ("="). This indicates that the response is present, but > is a zero- length string.
1 parent b00141c commit 4848153

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

lib/net/imap.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1247,7 +1247,8 @@ def authenticate(mechanism, *creds, sasl_ir: true, **props, &callback)
12471247
cmdargs = ["AUTHENTICATE", mechanism]
12481248
if sasl_ir && capable?("SASL-IR") && auth_capable?(mechanism) &&
12491249
SASL.initial_response?(authenticator)
1250-
cmdargs << [authenticator.process(nil)].pack("m0")
1250+
response = authenticator.process(nil)
1251+
cmdargs << (response.empty? ? "=" : [response].pack("m0"))
12511252
end
12521253
result = send_command(*cmdargs) do |resp|
12531254
if resp.instance_of?(ContinuationRequest)

test/net/imap/test_imap.rb

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -847,6 +847,24 @@ def test_id
847847
end
848848
end
849849

850+
test("#authenticate sends '=' as the initial reponse " \
851+
"when the initial response is an empty string") do
852+
with_fake_server(
853+
preauth: false, cleartext_auth: true,
854+
sasl_ir: true, sasl_mechanisms: %i[EXTERNAL],
855+
) do |server, imap|
856+
server.on "AUTHENTICATE" do |cmd|
857+
server.state.authenticate(server.config.user)
858+
cmd.done_ok
859+
end
860+
imap.authenticate("EXTERNAL")
861+
cmd = server.commands.pop
862+
assert_equal "AUTHENTICATE", cmd.name
863+
assert_equal %w[EXTERNAL =], cmd.args
864+
assert_empty server.commands rescue pp server.commands.pop
865+
end
866+
end
867+
850868
test("#authenticate never sends an initial response " \
851869
"when the server doesn't explicitly support the mechanism") do
852870
with_fake_server(

0 commit comments

Comments
 (0)