Exponential Regex Backtracking in Nokogiri CSS Selector Tokenizer - High Severity Vulnerability

nokogiri Updated 06 May 2026

Summary

06/05/2026
HIGH
Yes i
High
7.5

GHSA-c4rq-3m3g-8wgx: Nokogiri CSS selector tokenizer has regular expression backtracking. Affects nokogiri versions < 1.19.3. Fixed in 1.19.3. How to fix ↓

Free scan

Check if this vulnerability affects your application

Upload a manifest or SBOM and we'll show whether you're affected, plus every other risky package in the same scan.

Check my app free

No signup required · Results in about 60 seconds

Upload your dependency manifest or SBOM

Drag & drop your file here or

Java Javascript PHP Python Go Rust Ruby Dart C/C++ Elixir CycloneDX SPDX

Upload a supported dependency manifest or SBOM. No installation or source-code access required.

See supported files and SBOM formats
SBOM sbom.json · bom.json · bom.xml · *.spdx.json · *.cdx.json · *.cdx.xml
Java pom.xml · gradle.lockfile · buildscript-gradle.lockfile
Javascript package-lock.json · yarn.lock · pnpm-lock.yaml
PHP composer.lock
Python poetry.lock · requirements.txt · Pipfile.lock
Go go.mod
Rust Cargo.lock
Ruby Gemfile.lock
Dart pubspec.lock
C/C++ conan.lock
Elixir mix.lock
Enter your work email to receive your report link.

Verify your email to view the full report and start 30 days of continuous monitoring. No credit card required.

Sponsored Devnack Penetration testing for web, API and mobile Manual testing by engineers who build software, not an auditor's checklist. Trusted by teams at Swift and Google Talk to Devnack

Background

Nokogiri is a popular Ruby library used for parsing HTML and XML documents. It provides a powerful CSS selector engine that allows developers to query and manipulate document structures easily. However, the library's CSS selector tokenizer has been found to be vulnerable to regular expression backtracking, which can lead to performance issues and denial of service under certain conditions.

Vulnerability Detail

The vulnerability arises from the construction of regular expressions in Nokogiri's CSS selector tokenizer, which can result in exponential backtracking when processing adversarial selectors. This can be triggered by specific patterns in user-supplied input, leading to significant performance degradation. The affected methods include Nokogiri::CSS.xpath_for, Node#css, Node#at_css, Searchable#search, and CSS::Parser#parse. If exploited, an attacker can cause a denial of service by injecting malicious input into these methods.

How To Fix

Latest published version: 1.19.4 as of 22 Oct 2026

gem install nokogiri -v 1.19.4

Upgrading to it may include breaking changes; the version below is the minimum fixed release for this vulnerability.

If you need the minimum change

1.19.3

This is the first release that contains the fix.

gem install nokogiri -v 1.19.3

Tip — Not sure which version your app runs? Vulert can match this fix to it. Scan free →

Workaround

If upgrading is not feasible, consider the following workarounds: 1. Avoid using attacker-controlled text in CSS selectors. Ensure that only developer-authored selectors are passed to Nokogiri. 2. Set a global timeout for regular expressions in Ruby 3.2+ or JRuby 9.4+ by adding the following line to your code: 'Regexp.timeout = 1' (where '1' is the timeout in seconds).

Conclusion

The Nokogiri CSS selector tokenizer vulnerability poses a significant risk due to its potential for causing denial of service through exponential regex backtracking. It is crucial for developers to upgrade to the patched version or implement workarounds to safeguard their applications.

See every vulnerability recorded for nokogiri →

Share this vulnerability

FAQ

The CVSS score of this vulnerability is 7.5, indicating a high severity level.

All versions of Nokogiri prior to 1.19.3 are affected by this vulnerability.

You can use Vulert's playground at Vulert Scanner to check if your application is affected by this vulnerability without needing to sign up.

If exploited, this vulnerability can lead to denial of service, causing your application to become unresponsive due to excessive resource consumption.

Yes, you can mitigate the risk by avoiding user-controlled input in CSS selectors and setting a timeout for regular expressions.

Related vulnerabilities

Recent vulnerabilities recorded for nokogiri.

How To Fix

Latest published version: 1.19.4 as of 22 Oct 2026

gem install nokogiri -v 1.19.4

Upgrading to it may include breaking changes; the version below is the minimum fixed release for this vulnerability.

If you need the minimum change

1.19.3

This is the first release that contains the fix.

gem install nokogiri -v 1.19.3

Tip — Not sure which version your app runs? Vulert can match this fix to it. Scan free →

Subscribe to Vulert on Telegram
Daily digest of new CVEs, critical and high severity, affected packages and fixes — plus a weekly roundup.
Join the channel →
Help improve this record
Report an issue or send feedback