From 4263c0d15a582b46d75aac57cd26a47d33941a53 Mon Sep 17 00:00:00 2001 From: Hiroshi SHIBATA Date: Fri, 21 Feb 2025 16:29:36 +0900 Subject: [PATCH 1/3] Truncate userinfo with URI#join, URI#merge and URI#+ --- lib/uri/generic.rb | 6 +++++- test/uri/test_generic.rb | 11 +++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/lib/uri/generic.rb b/lib/uri/generic.rb index 69698c4..7d0b889 100644 --- a/lib/uri/generic.rb +++ b/lib/uri/generic.rb @@ -1141,7 +1141,11 @@ def merge(oth) end # RFC2396, Section 5.2, 7) - base.set_userinfo(rel.userinfo) if rel.userinfo + if rel.userinfo + base.set_userinfo(rel.userinfo) + else + base.set_userinfo(nil) + end base.set_host(rel.host) if rel.host base.set_port(rel.port) if rel.port base.query = rel.query if rel.query diff --git a/test/uri/test_generic.rb b/test/uri/test_generic.rb index 3897c3d..30f9cbf 100644 --- a/test/uri/test_generic.rb +++ b/test/uri/test_generic.rb @@ -164,6 +164,17 @@ def test_parse # must be empty string to identify as path-abempty, not path-absolute assert_equal('', url.host) assert_equal('http:////example.com', url.to_s) + + # sec-2957667 + url = URI.parse('http://user:pass@example.com').merge('//example.net') + assert_equal('http://example.net', url.to_s) + assert_nil(url.userinfo) + url = URI.join('http://user:pass@example.com', '//example.net') + assert_equal('http://example.net', url.to_s) + assert_nil(url.userinfo) + url = URI.parse('http://user:pass@example.com') + '//example.net' + assert_equal('http://example.net', url.to_s) + assert_nil(url.userinfo) end def test_parse_scheme_with_symbols From 58adef476ef4b5e6deefaf92e7594ab29396c624 Mon Sep 17 00:00:00 2001 From: Hiroshi SHIBATA Date: Fri, 21 Feb 2025 18:16:28 +0900 Subject: [PATCH 2/3] Fix merger of URI with authority component https://hackerone.com/reports/2957667 Co-authored-by: Nobuyoshi Nakada --- lib/uri/generic.rb | 19 +++++++------------ test/uri/test_generic.rb | 7 +++++++ 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/lib/uri/generic.rb b/lib/uri/generic.rb index 7d0b889..f7eed57 100644 --- a/lib/uri/generic.rb +++ b/lib/uri/generic.rb @@ -1133,21 +1133,16 @@ def merge(oth) base.fragment=(nil) # RFC2396, Section 5.2, 4) - if !authority - base.set_path(merge_path(base.path, rel.path)) if base.path && rel.path - else - # RFC2396, Section 5.2, 4) - base.set_path(rel.path) if rel.path + if authority + base.set_userinfo(rel.userinfo) + base.set_host(rel.host) + base.set_port(rel.port || base.default_port) + base.set_path(rel.path) + elsif base.path && rel.path + base.set_path(merge_path(base.path, rel.path)) end # RFC2396, Section 5.2, 7) - if rel.userinfo - base.set_userinfo(rel.userinfo) - else - base.set_userinfo(nil) - end - base.set_host(rel.host) if rel.host - base.set_port(rel.port) if rel.port base.query = rel.query if rel.query base.fragment=(rel.fragment) if rel.fragment diff --git a/test/uri/test_generic.rb b/test/uri/test_generic.rb index 30f9cbf..4b5e12c 100644 --- a/test/uri/test_generic.rb +++ b/test/uri/test_generic.rb @@ -267,6 +267,13 @@ def test_merge assert_equal(u0, u1) end + def test_merge_authority + u = URI.parse('http://user:pass@example.com:8080') + u0 = URI.parse('http://new.example.org/path') + u1 = u.merge('//new.example.org/path') + assert_equal(u0, u1) + end + def test_route url = URI.parse('http://hoge/a.html').route_to('http://hoge/b.html') assert_equal('b.html', url.to_s) From b079fb331eba7254d13e5e3c7e1853f9b28fc63a Mon Sep 17 00:00:00 2001 From: Hiroshi SHIBATA Date: Wed, 26 Feb 2025 16:11:31 +0900 Subject: [PATCH 3/3] Bump up v0.12.4 --- lib/uri/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/uri/version.rb b/lib/uri/version.rb index 7da021d..c93c97c 100644 --- a/lib/uri/version.rb +++ b/lib/uri/version.rb @@ -1,6 +1,6 @@ module URI # :stopdoc: - VERSION_CODE = '001203'.freeze + VERSION_CODE = '001204'.freeze VERSION = VERSION_CODE.scan(/../).collect{|n| n.to_i}.join('.').freeze # :startdoc: end