107 lines
4.1 KiB
Diff
107 lines
4.1 KiB
Diff
From 5fbc1d45f17e4bff7cc61a78a7d788aa32ff390a Mon Sep 17 00:00:00 2001
|
|
From: Hiroshi SHIBATA <hsbt@ruby-lang.org>
|
|
Date: Thu, 29 Jun 2023 22:24:35 +0900
|
|
Subject: [PATCH] CVE-2023-36617 for Ruby 3.1 (#7996)
|
|
|
|
* Bump up v0.12.2
|
|
|
|
* Merge URI-0.10.3 for Bundler
|
|
---
|
|
.../vendor/uri/lib/uri/rfc2396_parser.rb | 4 ++--
|
|
.../vendor/uri/lib/uri/rfc3986_parser.rb | 2 +-
|
|
lib/uri/rfc2396_parser.rb | 4 ++--
|
|
lib/uri/rfc3986_parser.rb | 2 +-
|
|
test/uri/test_parser.rb | 22 +++++++++++++++++++
|
|
5 files changed, 28 insertions(+), 6 deletions(-)
|
|
|
|
diff --git a/lib/bundler/vendor/uri/lib/uri/rfc2396_parser.rb b/lib/bundler/vendor/uri/lib/uri/rfc2396_parser.rb
|
|
index e48e164..09ed407 100644
|
|
--- a/lib/bundler/vendor/uri/lib/uri/rfc2396_parser.rb
|
|
+++ b/lib/bundler/vendor/uri/lib/uri/rfc2396_parser.rb
|
|
@@ -491,8 +491,8 @@ module Bundler::URI
|
|
ret = {}
|
|
|
|
# for Bundler::URI::split
|
|
- ret[:ABS_URI] = Regexp.new('\A\s*' + pattern[:X_ABS_URI] + '\s*\z', Regexp::EXTENDED)
|
|
- ret[:REL_URI] = Regexp.new('\A\s*' + pattern[:X_REL_URI] + '\s*\z', Regexp::EXTENDED)
|
|
+ ret[:ABS_URI] = Regexp.new('\A\s*+' + pattern[:X_ABS_URI] + '\s*\z', Regexp::EXTENDED)
|
|
+ ret[:REL_URI] = Regexp.new('\A\s*+' + pattern[:X_REL_URI] + '\s*\z', Regexp::EXTENDED)
|
|
|
|
# for Bundler::URI::extract
|
|
ret[:URI_REF] = Regexp.new(pattern[:URI_REF])
|
|
diff --git a/lib/bundler/vendor/uri/lib/uri/rfc3986_parser.rb b/lib/bundler/vendor/uri/lib/uri/rfc3986_parser.rb
|
|
index 2029cfd..e11f622 100644
|
|
--- a/lib/bundler/vendor/uri/lib/uri/rfc3986_parser.rb
|
|
+++ b/lib/bundler/vendor/uri/lib/uri/rfc3986_parser.rb
|
|
@@ -95,7 +95,7 @@ module Bundler::URI
|
|
QUERY: /\A(?:%\h\h|[!$&-.0-;=@-Z_a-z~\/?])*\z/,
|
|
FRAGMENT: /\A(?:%\h\h|[!$&-.0-;=@-Z_a-z~\/?])*\z/,
|
|
OPAQUE: /\A(?:[^\/].*)?\z/,
|
|
- PORT: /\A[\x09\x0a\x0c\x0d ]*\d*[\x09\x0a\x0c\x0d ]*\z/,
|
|
+ PORT: /\A[\x09\x0a\x0c\x0d ]*+\d*[\x09\x0a\x0c\x0d ]*\z/,
|
|
}
|
|
end
|
|
|
|
diff --git a/lib/uri/rfc2396_parser.rb b/lib/uri/rfc2396_parser.rb
|
|
index 76a8f99..00c66cf 100644
|
|
--- a/lib/uri/rfc2396_parser.rb
|
|
+++ b/lib/uri/rfc2396_parser.rb
|
|
@@ -497,8 +497,8 @@ module URI
|
|
ret = {}
|
|
|
|
# for URI::split
|
|
- ret[:ABS_URI] = Regexp.new('\A\s*' + pattern[:X_ABS_URI] + '\s*\z', Regexp::EXTENDED)
|
|
- ret[:REL_URI] = Regexp.new('\A\s*' + pattern[:X_REL_URI] + '\s*\z', Regexp::EXTENDED)
|
|
+ ret[:ABS_URI] = Regexp.new('\A\s*+' + pattern[:X_ABS_URI] + '\s*\z', Regexp::EXTENDED)
|
|
+ ret[:REL_URI] = Regexp.new('\A\s*+' + pattern[:X_REL_URI] + '\s*\z', Regexp::EXTENDED)
|
|
|
|
# for URI::extract
|
|
ret[:URI_REF] = Regexp.new(pattern[:URI_REF])
|
|
diff --git a/lib/uri/rfc3986_parser.rb b/lib/uri/rfc3986_parser.rb
|
|
index 3c89311..cde3ea7 100644
|
|
--- a/lib/uri/rfc3986_parser.rb
|
|
+++ b/lib/uri/rfc3986_parser.rb
|
|
@@ -101,7 +101,7 @@ module URI
|
|
QUERY: /\A(?:%\h\h|[!$&-.0-;=@-Z_a-z~\/?])*\z/,
|
|
FRAGMENT: /\A(?:%\h\h|[!$&-.0-;=@-Z_a-z~\/?])*\z/,
|
|
OPAQUE: /\A(?:[^\/].*)?\z/,
|
|
- PORT: /\A[\x09\x0a\x0c\x0d ]*\d*[\x09\x0a\x0c\x0d ]*\z/,
|
|
+ PORT: /\A[\x09\x0a\x0c\x0d ]*+\d*[\x09\x0a\x0c\x0d ]*\z/,
|
|
}
|
|
end
|
|
|
|
diff --git a/test/uri/test_parser.rb b/test/uri/test_parser.rb
|
|
index 03de137..81c2210 100644
|
|
--- a/test/uri/test_parser.rb
|
|
+++ b/test/uri/test_parser.rb
|
|
@@ -63,4 +63,26 @@ class URI::TestParser < Test::Unit::TestCase
|
|
assert_equal("\u3042", p1.unescape('%e3%81%82'.force_encoding(Encoding::US_ASCII)))
|
|
assert_equal("\xe3\x83\x90\xe3\x83\x90", p1.unescape("\xe3\x83\x90%e3%83%90"))
|
|
end
|
|
+
|
|
+ def test_rfc2822_parse_relative_uri
|
|
+ pre = ->(length) {
|
|
+ " " * length + "\0"
|
|
+ }
|
|
+ parser = URI::RFC2396_Parser.new
|
|
+ assert_linear_performance((1..5).map {|i| 10**i}, pre: pre) do |uri|
|
|
+ assert_raise(URI::InvalidURIError) do
|
|
+ parser.split(uri)
|
|
+ end
|
|
+ end
|
|
+ end
|
|
+
|
|
+ def test_rfc3986_port_check
|
|
+ pre = ->(length) {"\t" * length + "a"}
|
|
+ uri = URI.parse("http://my.example.com")
|
|
+ assert_linear_performance((1..5).map {|i| 10**i}, pre: pre) do |port|
|
|
+ assert_raise(URI::InvalidComponentError) do
|
|
+ uri.port = port
|
|
+ end
|
|
+ end
|
|
+ end
|
|
end
|
|
--
|
|
2.27.0
|
|
|