From e414c70198dd027b75312d135e99ae6388a8910e Mon Sep 17 00:00:00 2001 From: liningjie Date: Wed, 3 Jul 2024 17:37:06 +0800 Subject: [PATCH] Fix CVE-2024-39316 --- CVE-2024-39316.patch | 53 ++++++++++++++++++++++++++++++++++++++++++++ rubygem-rack.spec | 9 +++++++- 2 files changed, 61 insertions(+), 1 deletion(-) create mode 100644 CVE-2024-39316.patch diff --git a/CVE-2024-39316.patch b/CVE-2024-39316.patch new file mode 100644 index 0000000..cfd0d9d --- /dev/null +++ b/CVE-2024-39316.patch @@ -0,0 +1,53 @@ +From 412c980450ca729ee37f90a2661f166a9665e058 Mon Sep 17 00:00:00 2001 +From: Dwi Siswanto +Date: Tue, 2 Jul 2024 11:29:28 +0700 +Subject: [PATCH] Merge pull request from GHSA-cj83-2ww7-mvq7 + +* fix: ReDoS in the `parse_http_accept_header` method + +Signed-off-by: Dwi Siswanto + +* fix: optimize HTTP Accept headers parsing + +by: + +* updated `parse_http_accept_header` method to + avoid unnecessary array allocation from `map`. +* used `strip!` to modify strings in place, + avoiding additional string allocations. +* plus, safe navigation for `parameters` to + handle nil cases. + +this improves memory efficiency in header parsing. + +Co-authored-by: Jeremy Evans +Signed-off-by: Dwi Siswanto + +--------- + +Signed-off-by: Dwi Siswanto +Co-authored-by: Jeremy Evans +--- + lib/rack/request.rb | 6 ++++-- + 1 file changed, 4 insertions(+), 2 deletions(-) + +diff --git a/lib/rack/request.rb b/lib/rack/request.rb +index b880b6ec..ccbd07da 100644 +--- a/lib/rack/request.rb ++++ b/lib/rack/request.rb +@@ -642,8 +642,10 @@ module Rack + end + + def parse_http_accept_header(header) +- header.to_s.split(/\s*,\s*/).map do |part| +- attribute, parameters = part.split(/\s*;\s*/, 2) ++ header.to_s.split(',').map do |part| ++ attribute, parameters = part.split(';', 2) ++ attribute.strip! ++ parameters&.strip! + quality = 1.0 + if parameters and /\Aq=([\d.]+)/ =~ parameters + quality = $1.to_f +-- +2.43.0.windows.1 + diff --git a/rubygem-rack.spec b/rubygem-rack.spec index d948d8c..320295f 100644 --- a/rubygem-rack.spec +++ b/rubygem-rack.spec @@ -4,7 +4,7 @@ Name: rubygem-%{gem_name} Version: 2.2.4 Epoch: 1 -Release: 8 +Release: 9 Summary: A modular Ruby webserver interface License: MIT and BSD URL: https://rack.github.io/ @@ -17,6 +17,7 @@ Patch4: Fix-CVE-2024-25126.patch Patch5: Fix-CVE-2022-44570.patch Patch6: Fix-CVE-2022-44571.patch Patch7: Fix-CVE-2022-44572.patch +Patch8: CVE-2024-39316.patch BuildRequires: ruby(release) rubygems-devel ruby >= 2.2.2 git BuildRequires: memcached rubygem(memcache-client) rubygem(minitest) BuildRequires: rubygem(memcache-client) @@ -105,6 +106,12 @@ popd %doc %{gem_instdir}/contrib %changelog +* Wed Jul 3 2024 liningjie - 1:2.2.4-9 +- Type:CVES +- ID:CVE-2024-39316 +- SUG:NA +- DESC:CVE-2024-39316 + * Thu Apr 11 2024 zouzhimin - 1:2.2.4-8 - Type:CVES - ID:CVE-2022-44572 -- Gitee