Skip to content
DoS Disclosed report Intermediate

RDoc::MethodAttr is vulnerable to Regular Expression Denial of Service (ReDoS)

A regular expression in RDoc's method attribute parser contains overlapping repeating groups, so certain crafted input triggers catastrophic backtracking. An attacker who can supply such a string to the block_params parser could make it consume 100% CPU for an extremely long time, causing denial of service.

sighook Follow

Originally disclosed on HackerOne

  • Disclosed after 21 months

The method block_params in class RDoc::MethodAttr uses a regular expression that is vulnerable to Denial of Service due to catastrophic backtracking.

The regular expression is:

([A-Z:a-z0-9_]+)\.([a-z0-9_]+)(\s*\(\s*[a-z0-9_.,\s]*\s*\)\s*)?

Source: https://github.com/ruby/ruby/blob/master/lib/rdoc/method_attr.rb#L265

The ReDoS requence is: (\s*\(\s*[a-z0-9_.,\s]*\s*\)\s*). It contains three overlapping repeating groups (repeated characters are 0x20, 0xa0, [09-0d]), so the worst-case complexity is cubic as there are 3 infinitely repeating groups. Cubic complexity here means that if the vulnerable part of the string is doubled in length, the execution time should be about 8 times longer (2^3).

PoC

I have not found a way to exploit this vulnerability directly from the file documentation (by running rdoc), however directly it is very easy:

Ruby
use 'rdoc'
RDoc::MethodAttr.new(nil, nil).block_params = '0.0(' + ' '*3456 + '0'

The client's code that relies on AnyMethod is also vulnerable since it inherits MethodAttr:

Ruby
use 'rdoc'
RDoc::AnyMethod.new(nil, nil).block_params = '0.0(' + ' '*3456 + '0'

If an attacker provides a malicious string to AnyMethod|MethodAttr's block_params documentation parser, it will get stuck processing the input for an extremely long time, consuming 100% CPU.

Impact

An attacker could cause an effective denial of service, by crafting an input which exploits catastrophic backtracking for the regular expression.

The original report as published on HackerOne, by sighook. Images and videos are our own copies; raw HTML is shown as text. View it on HackerOne.

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

The regular expression contains three overlapping repeating groups that can match the same whitespace characters, giving cubic worst-case backtracking.

Impact

An attacker could cause an effective denial of service by supplying a crafted string to the block_params parser, though the reporter did not find a way to trigger it directly through running rdoc on file documentation.

What the attacker needed

Attacker-controlled string reaches block_params; direct library use or a future rdoc path

How it was found

  1. Create an RDoc MethodAttr or AnyMethod object.
  2. Assign a crafted string to its block_params that places a long run of whitespace inside the bracketed section.
  3. Observe that processing the input takes an extremely long time and consumes 100% CPU.

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.

A regular expression is a pattern used to match text. Some patterns can be written so that, on certain inputs, the matching engine tries a huge number of combinations and effectively hangs. Here a crafted string with many spaces inside brackets makes the parser burn CPU, so the program stops responding.

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.

More by sighook

View all

10 more disclosed reports, best first.

More from Ruby

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Denial of service

The lesson behind this report.

A request that exhausts resources or crashes a component. Many programs forbid testing it; reports usually show it from code, not by attacking.