[前][次][番号順一覧][スレッド一覧]

ruby-changes:66715

From: usa <ko1@a...>
Date: Wed, 7 Jul 2021 19:38:25 +0900 (JST)
Subject: [ruby-changes:66715] 95ba9053e2 (ruby_2_6): Fix StartTLS stripping vulnerability

https://git.ruby-lang.org/ruby.git/commit/?id=95ba9053e2

From 95ba9053e20ad8d113af37b3f1f4cbfff1f6a8f1 Mon Sep 17 00:00:00 2001
From: usa <usa@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>
Date: Wed, 7 Jul 2021 10:38:10 +0000
Subject: Fix StartTLS stripping vulnerability

Reported by Alexandr Savca in https://hackerone.com/reports/1178562

Co-authored-by: Shugo Maeda <shugo@r...>


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_6@67950 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
---
 lib/net/imap.rb            |  8 +++++++-
 test/net/imap/test_imap.rb | 39 +++++++++++++++++++++++++++++++++++++++
 version.h                  |  2 +-
 3 files changed, 47 insertions(+), 2 deletions(-)

diff --git a/lib/net/imap.rb b/lib/net/imap.rb
index 1c7e89b..91df89b 100644
--- a/lib/net/imap.rb
+++ b/lib/net/imap.rb
@@ -1215,12 +1215,14 @@ module Net https://github.com/ruby/ruby/blob/trunk/lib/net/imap.rb#L1215
       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
 
@@ -3716,6 +3718,10 @@ module Net https://github.com/ruby/ruby/blob/trunk/lib/net/imap.rb#L3718
     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
diff --git a/test/net/imap/test_imap.rb b/test/net/imap/test_imap.rb
index 936f4e0..81928cb 100644
--- a/test/net/imap/test_imap.rb
+++ b/test/net/imap/test_imap.rb
@@ -127,6 +127,24 @@ class IMAPTest < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/net/imap/test_imap.rb#L127
         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
+    th = Thread.new do
+      yield
+    end
+    @threads << th
+    sleep 0.1 until th.stop?
   end
 
   def test_unexpected_eof
@@ -762,6 +780,27 @@ EOF https://github.com/ruby/ruby/blob/trunk/test/net/imap/test_imap.rb#L780
     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
diff --git a/version.h b/version.h
index 668fd5d..89eacef 100644
--- a/version.h
+++ b/version.h
@@ -1,6 +1,6 @@ https://github.com/ruby/ruby/blob/trunk/version.h#L1
 #define RUBY_VERSION "2.6.8"
 #define RUBY_RELEASE_DATE "2021-07-07"
-#define RUBY_PATCHLEVEL 204
+#define RUBY_PATCHLEVEL 205
 
 #define RUBY_RELEASE_YEAR 2021
 #define RUBY_RELEASE_MONTH 7
-- 
cgit v1.1


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]