Skip to main content
Vulnerability Database/CVE-2024-47889

CVE-2024-47889: Action Mailer ReDoS Vulnerability

CVE-2024-47889 is a Regular Expression Denial of Service vulnerability in Action Mailer that can cause severe performance degradation through crafted text input. This article covers technical details, affected versions, and mitigation strategies.

Published:

Disclaimer: This content was generated using AI. While we strive for accuracy, please verify critical information with official sources.

Sources: National Vulnerability Database, CISA KEV, Exploit-DB

CVE-2024-47889 Overview

CVE-2024-47889 is a Regular Expression Denial of Service (ReDoS) vulnerability in the block_format helper of Action Mailer, the email framework shipped with Ruby on Rails. The flaw affects versions starting at 3.0.0 and prior to 6.1.7.9, 7.0.8.5, 7.1.4.1, and 7.2.1.1. Attackers can submit crafted text that causes the helper's regular expressions to backtrack catastrophically, consuming excessive CPU and degrading availability. The weakness is tracked as [CWE-1333] (Inefficient Regular Expression Complexity).

Critical Impact

Carefully crafted input processed by block_format can cause unbounded regex backtracking, resulting in denial-of-service conditions on affected Rails applications running Ruby versions earlier than 3.2.

Affected Products

  • Ruby on Rails Action Mailer 3.0.0 through 6.1.7.8
  • Ruby on Rails Action Mailer 7.0.0 through 7.0.8.4, and 7.1.0 through 7.1.4.0
  • Ruby on Rails Action Mailer 7.2.0 through 7.2.1.0

Discovery Timeline

  • 2024-10-16 - CVE-2024-47889 published to the National Vulnerability Database (NVD)
  • 2026-06-17 - Last updated in NVD database

Technical Details for CVE-2024-47889

Vulnerability Analysis

The block_format helper in actionmailer/lib/action_mailer/mail_helper.rb formats plain-text email bodies, reflowing paragraphs and indenting list markers such as * and #. It performs this indentation using two gsub! calls backed by regular expressions whose structure allows catastrophic backtracking against adversarial input.

When an attacker controls data that flows into a mail template rendered through block_format, such as a user-submitted comment, name, or message body echoed in a notification email, the regex engine can enter an exponential matching path. This holds a worker thread, degrades throughput, and may starve the application of request-handling capacity.

The EPSS score sits at roughly 0.94%, reflecting a moderate probability of exploitation activity. Impact is confined to availability; the issue does not expose data or allow code execution.

Root Cause

The patterns /[ ]*([*]+) ([^*]*)/ and /[ ]*([#]+) ([^#]*)/ combine repeated character classes with negated classes against input that may contain long runs of * or # characters. On Ruby versions prior to 3.2, this triggers quadratic or worse backtracking. Ruby 3.2 introduced regex matching optimizations that mitigate the behavior, which is why applications on Ruby 3.2 or newer, including Rails 8.0.0.beta1, are unaffected.

Attack Vector

Exploitation is remote and unauthenticated when any user-controllable string reaches the block_format helper during email rendering. The attacker submits input containing adversarial sequences of asterisks or hash characters. The subsequent background job or synchronous mailer call consumes excessive CPU during template rendering.

ruby
# Patch from actionmailer/lib/action_mailer/mail_helper.rb
# Replaces backtracking-prone gsub! calls with a single linear scan

      }.join("\n\n")

      # Make list points stand on their own line
-      formatted.gsub!(/[ ]*([*]+) ([^*]*)/) { "  #{$1} #{$2.strip}\n" }
-      formatted.gsub!(/[ ]*([#]+) ([^#]*)/) { "  #{$1} #{$2.strip}\n" }
+      output = +""
+      splits = formatted.split(/(\*+|\#+)/)
+      while line = splits.shift
+        if line.start_with?("*", "#") && splits[0].start_with?(" ")
+          output.chomp!(" ") while output.end_with?(" ")
+          output << "  #{line} #{splits.shift.strip}\n"
+        else
+          output << line
+        end
+      end

-      formatted
+      output
     end

Source: Rails Commit 0e5694f4

Detection Methods for CVE-2024-47889

Indicators of Compromise

  • Sustained CPU saturation on Rails application or background-job workers correlated with mailer rendering activity.
  • Unusually long ActionMailer deliver or render spans in application performance monitoring (APM) traces.
  • Inbound requests or job payloads containing long contiguous runs of * or # characters in fields later rendered in emails.

Detection Strategies

  • Audit mailer templates to identify use of the block_format helper and trace which fields flow into it from untrusted input.
  • Instrument ActionMailer::Base#mail and template rendering with timing thresholds that alert when a single render exceeds a defined budget.
  • Review dependency manifests (Gemfile.lock) for actionmailer versions earlier than 6.1.7.9, 7.0.8.5, 7.1.4.1, or 7.2.1.1 running on Ruby below 3.2.

Monitoring Recommendations

  • Alert on Sidekiq, GoodJob, or Resque worker threads blocked for abnormally long durations during deliver_now or deliver_later calls.
  • Watch web server timeout logs and 5xx error spikes that coincide with mailer-triggering endpoints.
  • Capture and retain inbound payloads that trigger timeout events to support post-incident regex analysis.

How to Mitigate CVE-2024-47889

Immediate Actions Required

  • Upgrade Action Mailer to 6.1.7.9, 7.0.8.5, 7.1.4.1, or 7.2.1.1 depending on your release train.
  • If an immediate upgrade is not possible, apply the upstream patch to actionmailer/lib/action_mailer/mail_helper.rb directly.
  • Upgrade the Ruby runtime to 3.2 or later, which mitigates the backtracking behavior at the regex engine level.

Patch Information

The fix replaces the two vulnerable gsub! calls with a linear tokenization loop. The relevant upstream commits are Rails Commit 0e5694f4, Rails Commit 3612e3eb, Rails Commit 985f1923, and Rails Commit be898cc9. Full details are published in GitHub Security Advisory GHSA-h47h-mwp9-c6q6.

Workarounds

  • Avoid calling the block_format helper in mailer templates until the patch is applied.
  • Upgrade to Ruby 3.2 or newer; Rails applications on this runtime are not affected by the backtracking behavior.
  • Validate and bound the length of user-supplied text fields before they are rendered into mail bodies.
bash
# Update Action Mailer via Bundler to a fixed release
bundle update actionmailer --conservative

# Verify the installed version matches a patched release
bundle info actionmailer | grep -E '6\.1\.7\.9|7\.0\.8\.5|7\.1\.4\.1|7\.2\.1\.1'

# Check the Ruby runtime version (3.2+ mitigates the ReDoS)
ruby -v

Disclaimer: This content was generated using AI. While we strive for accuracy, please verify critical information with official sources.

Sources: National Vulnerability Database, CISA KEV, Exploit-DB

Experience the Most Advanced Cybersecurity Platform

See how the world’s most intelligent, autonomous cybersecurity platform can protect your organization today and into the future.