Inefficient Regular Expression Complexity in Nokogiri
Description
Nokogiri is an open source XML and HTML library for Ruby. Nokogiri < v1.13.4 contains an inefficient regular expression that is susceptible to excessive backtracking when attempting to detect encoding in HTML documents. Users are advised to upgrade to Nokogiri >= 1.13.4. There are no known workarounds for this issue.
AI Insight
LLM-synthesized narrative grounded in this CVE's description and references.
Nokogiri < 1.13.4 for Ruby contains a ReDoS vulnerability via an inefficient regex used for HTML encoding detection.
Vulnerability
Nokogiri versions < 1.13.4 contain an inefficient regular expression in the HTML encoding detection routine. This regex is susceptible to excessive backtracking when processing certain crafted inputs, leading to a Regular Expression Denial of Service (ReDoS) condition. The affected component is the HTML document parser's encoding detection logic, which can be triggered when Nokogiri is used to parse HTML documents without explicit encoding specified. [2][4]
Exploitation
An attacker can exploit this vulnerability by supplying a specially crafted HTML document to a Ruby application that uses Nokogiri (< 1.13.4) to parse untrusted HTML input. The attack does not require any authentication or special privileges beyond the ability to deliver the malicious document (e.g., via a web upload, API request, or email attachment). When the vulnerable regex attempts to detect the encoding in the crafted HTML, it enters catastrophic backtracking, causing the CPU usage to spike and the processing to hang for an extended period. [2][4]
Impact
Successful exploitation results in a denial of service. The application processing the crafted HTML will become unresponsive while the regex backtracking consumes excessive CPU resources. This can lead to service degradation or complete unavailability for legitimate users. The vulnerability is classified as a security issue because it allows an unauthenticated remote attacker to disrupt the normal operation of the affected system without requiring any special access. [2]
Mitigation
Users are advised to upgrade to Nokogiri >= 1.13.4 to fix the issue. No known workarounds exist for this vulnerability. Upgrading is the only effective mitigation. The fix was released in version 1.13.4 on April 11, 2022. The vulnerability is not known to be listed in CISA's Known Exploited Vulnerabilities (KEV) catalog at this time. [2][4]
AI Insight generated on May 21, 2026. Synthesized from this CVE's description and the cited reference URLs; citations are validated against the source bundle.
Affected packages
Versions sourced from the GitHub Security Advisory.
| Package | Affected versions | Patched versions |
|---|---|---|
nokogiriRubyGems | < 1.13.4 | 1.13.4 |
Affected products
13- ghsa-coords12 versionspkg:gem/nokogiripkg:rpm/opensuse/ruby3.2-rubygem-nokogiri&distro=openSUSE%20Tumbleweedpkg:rpm/opensuse/rubygem-nokogiri&distro=openSUSE%20Leap%2015.3pkg:rpm/opensuse/rubygem-nokogiri&distro=openSUSE%20Leap%2015.4pkg:rpm/opensuse/rubygem-nokogiri&distro=openSUSE%20Tumbleweedpkg:rpm/suse/rubygem-nokogiri&distro=SUSE%20Linux%20Enterprise%20High%20Availability%20Extension%2015pkg:rpm/suse/rubygem-nokogiri&distro=SUSE%20Linux%20Enterprise%20High%20Availability%20Extension%2015%20SP1pkg:rpm/suse/rubygem-nokogiri&distro=SUSE%20Linux%20Enterprise%20High%20Availability%20Extension%2015%20SP2pkg:rpm/suse/rubygem-nokogiri&distro=SUSE%20Linux%20Enterprise%20Module%20for%20Basesystem%2015%20SP3pkg:rpm/suse/rubygem-nokogiri&distro=SUSE%20Linux%20Enterprise%20Module%20for%20Basesystem%2015%20SP4pkg:rpm/suse/rubygem-nokogiri&distro=SUSE%20OpenStack%20Cloud%20Crowbar%208pkg:rpm/suse/rubygem-nokogiri&distro=SUSE%20OpenStack%20Cloud%20Crowbar%209
< 1.13.4+ 11 more
- (no CPE)range: < 1.13.4
- (no CPE)range: < 1.13.9-1.7
- (no CPE)range: < 1.8.5-150000.3.9.1
- (no CPE)range: < 1.8.5-150400.14.3.1
- (no CPE)range: < 1.13.4-1.1
- (no CPE)range: < 1.8.5-150000.3.9.1
- (no CPE)range: < 1.8.5-150000.3.9.1
- (no CPE)range: < 1.8.5-150000.3.9.1
- (no CPE)range: < 1.8.5-150000.3.9.1
- (no CPE)range: < 1.8.5-150400.14.3.1
- (no CPE)range: < 1.6.1-5.6.1
- (no CPE)range: < 1.6.1-5.6.1
- sparklemotion/nokogiriv5Range: < 1.13.4
Patches
1e444525ef163fix(perf): HTML4::EncodingReader detection
2 files changed · +13 −1
lib/nokogiri/html4/document.rb+1 −1 modified@@ -268,7 +268,7 @@ def start_element(name, attrs = []) end def self.detect_encoding(chunk) - (m = chunk.match(/\A(<\?xml[ \t\r\n]+[^>]*>)/)) && + (m = chunk.match(/\A(<\?xml[ \t\r\n][^>]*>)/)) && (return Nokogiri.XML(m[1]).encoding) if Nokogiri.jruby?
test/html4/test_document_encoding.rb+12 −0 modified@@ -155,6 +155,18 @@ def binopen(file) end end end + + it "does not start backtracking during detection of XHTML encoding" do + # this test is a quick and dirty version + # of the more complete perf test that is on main. + n = 40_000 + redos_string = "<?xml " + (" " * n) + redos_string.encode!("ASCII-8BIT") + start_time = Time.now + Nokogiri::HTML4(redos_string) + elapsed_time = Time.now - start_time + assert_operator(elapsed_time, :<, 1) + end end end end
Vulnerability mechanics
Generated on May 9, 2026. Inputs: CWE entries + fix-commit diffs from this CVE's patches. Citations validated against bundle.
References
18- github.com/advisories/GHSA-crjr-9rc5-ghw8ghsaADVISORY
- lists.fedoraproject.org/archives/list/package-announce%40lists.fedoraproject.org/message/6DHCOWMA5PQTIQIMDENA7R2Y5BDYAIYM/mitrevendor-advisory
- lists.fedoraproject.org/archives/list/package-announce%40lists.fedoraproject.org/message/OUPLBUZVM4WPFSXBEP2JS3R6LMKRTLFC/mitrevendor-advisory
- lists.fedoraproject.org/archives/list/package-announce%40lists.fedoraproject.org/message/XMDCWRQXJQ3TFSETPCEFMQ6RR6ME5UA3/mitrevendor-advisory
- nvd.nist.gov/vuln/detail/CVE-2022-24836ghsaADVISORY
- security.gentoo.org/glsa/202208-29ghsavendor-advisoryWEB
- seclists.org/fulldisclosure/2022/Dec/23ghsamailing-listWEB
- github.com/rubysec/ruby-advisory-db/blob/master/gems/nokogiri/CVE-2022-24836.ymlghsaWEB
- github.com/sparklemotion/nokogiri/commit/e444525ef1634b675cd1cf52d39f4320ef0aecfdghsaWEB
- github.com/sparklemotion/nokogiri/releases/tag/v1.13.4ghsaWEB
- github.com/sparklemotion/nokogiri/security/advisories/GHSA-crjr-9rc5-ghw8ghsaWEB
- groups.google.com/g/ruby-security-ann/c/vX7qSjsvWis/m/TJWN4oOKBwAJghsaWEB
- lists.debian.org/debian-lts-announce/2022/05/msg00013.htmlghsamailing-listWEB
- lists.debian.org/debian-lts-announce/2022/10/msg00018.htmlghsamailing-listWEB
- lists.fedoraproject.org/archives/list/package-announce@lists.fedoraproject.org/message/6DHCOWMA5PQTIQIMDENA7R2Y5BDYAIYMghsaWEB
- lists.fedoraproject.org/archives/list/package-announce@lists.fedoraproject.org/message/OUPLBUZVM4WPFSXBEP2JS3R6LMKRTLFCghsaWEB
- lists.fedoraproject.org/archives/list/package-announce@lists.fedoraproject.org/message/XMDCWRQXJQ3TFSETPCEFMQ6RR6ME5UA3ghsaWEB
- support.apple.com/kb/HT213532ghsaWEB
News mentions
0No linked articles in our index yet.