Ruby - Regular Expression Denial of Service Vulnerability of Date Parsing Methods
The date gem's parsing methods use regular expressions that are vulnerable to regular expression denial of service (ReDoS). An attacker could supply crafted input to cause excessive CPU consumption and effectively deny service to applications that parse untrusted dates.
- Triaged in 14 hours
- Fixed in 15 hours
- Paid in 15 hours
- Disclosed after 15 hours
Summary by the program
Ruby has released date gem version 3.2.1, 3.1.2, 3.0.2, and 2.0.1 that include a security fix for a regular expression denial of service vulnerability (ReDoS) on date parsing methods. An attacker can exploit this vulnerability to cause an effective DoS attack.
Details Date’s parsing methods including Date.parse are using Regexps internally, some of which are vulnerable against regular expression denial of service. Applications and libraries that apply such methods to untrusted input may be affected.
The fix limits the input length up to 128 bytes by default instead of changing the regexps. This is because Date gem uses many Regexps and it is possible that there are still undiscovered vulnerable Regexps. For compatibility, it is allowed to remove the limitation by explicitly passing limit keywords as nil like Date.parse(str, limit: nil), but note that it may take a long time to parse.
Please update the date gem to version 3.2.1, 3.1.2, 3.0.2, and 2.0.1, or later. You can use gem update date to update it. If you are using bundler, please add gem "date", ">= 3.2.1" to your Gemfile.
Affected versions date gem 2.0.0 or prior (which are bundled versions with Ruby 2.6 series) date gem 3.0.1 or prior (which are bundled versions with Ruby 2.7 series) date gem 3.1.1 or prior (which are bundled versions with Ruby 3.0 series) date gem 3.2.0 or prior
Credits Thanks to svalkanov for discovering this issue.
History Originally published at 2021-11-15 08:00:00 (UTC)
https://www.ruby-lang.org/en/news/2021/11/15/date-parsing-method-regexp-dos-cve-2021-41817/
The report
Official report: https://www.ruby-lang.org/en/news/2021/11/15/date-parsing-method-regexp-dos-cve-2021-41817/ CVE-2021-41817
Here are the details from the official article:
Date’s parsing methods including Date.parse are using Regexps internally, some of which are vulnerable against regular expression denial of service. Applications and libraries that apply such methods to untrusted input may be affected.
The fix limits the input length up to 128 bytes by default instead of changing the regexps. This is because Date gem uses many Regexps and it is possible that there are still undiscovered vulnerable Regexps. For compatibility, it is allowed to remove the limitation by explicitly passing limit keywords as nil like Date.parse(str, limit: nil), but note that it may take a long time to parse.
Please update the date gem to version 3.2.1, 3.1.2, 3.0.2, and 2.0.1, or later. You can use gem update date to update it. If you are using bundler, please add gem "date", ">= 3.2.1" to your Gemfile.
Please let me know if any additional information is needed
Impact
Full DoS when date parsing methods are used with untrusted input
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Root cause
Likely, the regular expressions used internally by the date parsing methods have catastrophic backtracking, allowing crafted input to consume excessive CPU time.
Impact
An attacker could cause a full denial of service when date parsing methods are used with untrusted input.
What the attacker needed
Application parses untrusted date input
The fix
The issue was fixed by limiting input length to 128 bytes by default in updated gem versions, rather than changing the regular expressions.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
Some date-parsing functions in Ruby use patterns to match text. Certain patterns can take a very long time when given specially crafted input, so an attacker could make the application hang or slow down. This is called a denial of service because legitimate users can no longer use the service.
What is DoS?
A request that exhausts resources or crashes a component. Many programs forbid testing it; reports usually show it from code, not by attacking.