Skip to content

Commit d16e994

Browse files
committed
🍒 pick 62eea6f: 🔒🥅 Ensure STARTTLS tagged response was handled [backport #664]
Taking a "belt-and-suspenders" approach to a STARTTLS stripping attack: This handles `STARTTLS` as a special-case: if the `STARTTLS` handler did not run, for _whatever_ reason, an exception _must_ be raised and the connection dropped. _No_ command should ever receive a tagged `OK` prior to completely sending the command. But `STARTTLS` is security-sensitive enough to warrant this special-case handler.
1 parent f96ab6c commit d16e994

1 file changed

Lines changed: 9 additions & 0 deletions

File tree

lib/net/imap.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1014,9 +1014,11 @@ def logout
10141014
# unsolicited untagged response immeditely _after_ #starttls completes.
10151015
#
10161016
def starttls(options = {}, verify = true)
1017+
handled = false
10171018
error = nil
10181019
ok = send_command("STARTTLS") do |resp|
10191020
if resp.kind_of?(TaggedResponse) && resp.name == "OK"
1021+
handled = true
10201022
begin
10211023
# for backward compatibility
10221024
certs = options.to_str
@@ -1032,6 +1034,13 @@ def starttls(options = {}, verify = true)
10321034
disconnect
10331035
raise error
10341036
end
1037+
unless handled
1038+
disconnect
1039+
raise InvalidResponseError,
1040+
"STARTTLS handler was bypassed, although server responded %p" % [
1041+
ok.raw_data.chomp
1042+
]
1043+
end
10351044
ok
10361045
end
10371046

0 commit comments

Comments
 (0)