CVE-2022-23517 Overview
CVE-2022-23517 is a Denial of Service vulnerability affecting rails-html-sanitizer, the component responsible for sanitizing HTML fragments in Ruby on Rails applications. Certain configurations of rails-html-sanitizer versions prior to 1.4.4 use an inefficient regular expression that is susceptible to excessive backtracking when attempting to sanitize certain SVG attributes. This Regular Expression Denial of Service (ReDoS) vulnerability may lead to denial of service through CPU resource consumption.
Critical Impact
Attackers can craft malicious SVG input that causes excessive CPU consumption, leading to denial of service in Rails applications that sanitize user-supplied HTML content.
Affected Products
- RubyOnRails Rails HTML Sanitizers (versions prior to 1.4.4)
- Debian Linux 10.0
Discovery Timeline
- 2022-12-14 - CVE-2022-23517 published to NVD
- 2025-11-03 - Last updated in NVD database
Technical Details for CVE-2022-23517
Vulnerability Analysis
This vulnerability is classified as CWE-1333 (Inefficient Regular Expression Complexity). The issue resides in how rails-html-sanitizer processes SVG attributes that allow URL references. The vulnerable code path uses a regular expression pattern to sanitize these attributes, but the pattern is susceptible to catastrophic backtracking when processing specially crafted input strings.
When the sanitizer encounters SVG elements with attributes listed in SVG_ATTR_VAL_ALLOWS_REF, it attempts to scrub potentially dangerous URL values using a regex-based replacement. The problematic regular expression /url\s*\(\s*[^#\s][^)]+?\)/m can exhibit exponential time complexity on certain malicious inputs, causing the application to hang while consuming excessive CPU cycles.
Root Cause
The root cause is the use of an inefficient regular expression pattern for attribute value sanitization. The regex /url\s*\(\s*[^#\s][^)]+?\)/m contains patterns that can trigger excessive backtracking when confronted with deliberately crafted input strings. This is a classic ReDoS (Regular Expression Denial of Service) pattern where the computational cost grows exponentially with input length.
Attack Vector
An attacker can exploit this vulnerability by submitting HTML content containing specially crafted SVG elements with malicious attribute values to any Rails application endpoint that sanitizes user input using vulnerable versions of rails-html-sanitizer. The attack requires no authentication and can be executed remotely over the network. The malicious input triggers the inefficient regex processing, causing the server to become unresponsive as it consumes CPU resources attempting to complete the sanitization.
The following patch from the official security fix demonstrates the vulnerable code and its remediation:
attr_node.remove
end
end
+
if Loofah::HTML5::SafeList::SVG_ATTR_VAL_ALLOWS_REF.include?(attr_name)
- attr_node.value = attr_node.value.gsub(/url\s*\(\s*[^#\s][^)]+?\)/m, ' ') if attr_node.value
+ Loofah::HTML5::Scrub.scrub_attribute_that_allows_local_ref(attr_node)
end
+
if Loofah::HTML5::SafeList::SVG_ALLOW_LOCAL_HREF.include?(node.name) && attr_name == 'xlink:href' && attr_node.value =~ /^\s*[^#\s].*/m
attr_node.remove
end
Source: GitHub Commit
Detection Methods for CVE-2022-23517
Indicators of Compromise
- Unusual CPU spikes on application servers processing user-submitted HTML content
- Elevated response times or timeouts on endpoints that sanitize HTML input
- Application worker processes stuck in CPU-bound states during HTML sanitization operations
- High memory consumption alongside CPU usage in Ruby processes handling HTML content
Detection Strategies
- Monitor application performance metrics for anomalous CPU usage patterns, particularly on endpoints accepting HTML or SVG input
- Implement request timeout thresholds to detect and terminate long-running sanitization operations
- Review application dependencies using bundle audit or similar tools to identify vulnerable rails-html-sanitizer versions
- Use application performance monitoring (APM) tools to track time spent in HTML sanitization methods
Monitoring Recommendations
- Configure alerting for sustained high CPU utilization on Rails application servers
- Implement rate limiting on endpoints that accept and sanitize HTML content
- Set up dependency scanning in CI/CD pipelines to catch vulnerable gem versions before deployment
- Monitor for patterns of malformed SVG submissions that could indicate exploitation attempts
How to Mitigate CVE-2022-23517
Immediate Actions Required
- Upgrade rails-html-sanitizer to version 1.4.4 or later immediately
- Review and audit all application endpoints that accept HTML input for proper timeout configurations
- Implement request size limits on endpoints that process user-submitted HTML content
- Consider deploying a web application firewall (WAF) rule to filter potentially malicious SVG content
Patch Information
The vulnerability has been patched in rails-html-sanitizer version 1.4.4. The fix replaces the vulnerable regex-based approach with a call to Loofah::HTML5::Scrub.scrub_attribute_that_allows_local_ref(), which handles the attribute sanitization without the ReDoS vulnerability. For detailed patch information, see the GitHub Security Advisory and the official commit. Debian users should apply updates per the Debian LTS Security Announcement.
Workarounds
- Implement request timeouts at the application server level (e.g., Puma, Unicorn) to terminate long-running requests
- Add input validation to reject SVG content entirely if not required by the application
- Deploy upstream timeouts at the load balancer or reverse proxy level
- Restrict HTML sanitization to trusted users only where feasible
# Update rails-html-sanitizer in your Gemfile
bundle update rails-html-sanitizer
# Verify the installed version
bundle show rails-html-sanitizer
# Should show version 1.4.4 or later
# Run bundle audit to check for known vulnerabilities
gem install bundler-audit
bundle audit check --update
Disclaimer: This content was generated using AI. While we strive for accuracy, please verify critical information with official sources.


