mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
Fix StartTLS stripping vulnerability
Reported by Alexandr Savca in https://hackerone.com/reports/1178562 Co-authored-by: Shugo Maeda <shugo@ruby-lang.org>
This commit is contained in:
parent
3ca1399150
commit
a21a3b7d23
3 changed files with 39 additions and 2 deletions
|
@ -1216,12 +1216,14 @@ module Net
|
|||
end
|
||||
resp = @tagged_responses.delete(tag)
|
||||
case resp.name
|
||||
when /\A(?:OK)\z/ni
|
||||
return resp
|
||||
when /\A(?:NO)\z/ni
|
||||
raise NoResponseError, resp
|
||||
when /\A(?:BAD)\z/ni
|
||||
raise BadResponseError, resp
|
||||
else
|
||||
return resp
|
||||
raise UnknownResponseError, resp
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -3717,6 +3719,10 @@ module Net
|
|||
class ByeResponseError < ResponseError
|
||||
end
|
||||
|
||||
# Error raised upon an unknown response from the server.
|
||||
class UnknownResponseError < ResponseError
|
||||
end
|
||||
|
||||
RESPONSE_ERRORS = Hash.new(ResponseError)
|
||||
RESPONSE_ERRORS["NO"] = NoResponseError
|
||||
RESPONSE_ERRORS["BAD"] = BadResponseError
|
||||
|
|
|
@ -127,6 +127,16 @@ class IMAPTest < Test::Unit::TestCase
|
|||
imap.disconnect
|
||||
end
|
||||
end
|
||||
|
||||
def test_starttls_stripping
|
||||
starttls_stripping_test do |port|
|
||||
imap = Net::IMAP.new("localhost", :port => port)
|
||||
assert_raise(Net::IMAP::UnknownResponseError) do
|
||||
imap.starttls(:ca_file => CA_FILE)
|
||||
end
|
||||
imap
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def start_server
|
||||
|
@ -784,6 +794,27 @@ EOF
|
|||
end
|
||||
end
|
||||
|
||||
def starttls_stripping_test
|
||||
server = create_tcp_server
|
||||
port = server.addr[1]
|
||||
start_server do
|
||||
sock = server.accept
|
||||
begin
|
||||
sock.print("* OK test server\r\n")
|
||||
sock.gets
|
||||
sock.print("RUBY0001 BUG unhandled command\r\n")
|
||||
ensure
|
||||
sock.close
|
||||
server.close
|
||||
end
|
||||
end
|
||||
begin
|
||||
imap = yield(port)
|
||||
ensure
|
||||
imap.disconnect if imap && !imap.disconnected?
|
||||
end
|
||||
end
|
||||
|
||||
def create_tcp_server
|
||||
return TCPServer.new(server_addr, 0)
|
||||
end
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
# define RUBY_VERSION_MINOR RUBY_API_VERSION_MINOR
|
||||
#define RUBY_VERSION_TEENY 4
|
||||
#define RUBY_RELEASE_DATE RUBY_RELEASE_YEAR_STR"-"RUBY_RELEASE_MONTH_STR"-"RUBY_RELEASE_DAY_STR
|
||||
#define RUBY_PATCHLEVEL 190
|
||||
#define RUBY_PATCHLEVEL 191
|
||||
|
||||
#define RUBY_RELEASE_YEAR 2021
|
||||
#define RUBY_RELEASE_MONTH 7
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue