CVE-2026-141526: Addressable: Regular Expression Denial of Service in Addressable templates with exploded variables next to other variables
Impact
Within the URI template implementation in Addressable, some templates with exploded variables still generate regular expressions vulnerable to excessive backtracking. GHSA-4w5q-wg7v-w6gp reported expressions with several exploded variables and listed 2.9.1 as patched, but its fix didn't cover these shapes:
1. An exploded expression directly before an expression with exploded variables (e.g., {a}{.a,b,c}), which is cubic in the input length. 2. Several exploded variables in a . or default expression (e.g., {.a,b,c}, which is quadratic, or {c,d,a}, which is cubic). 3. An unexploded variable between exploded ones in a ? or & expression (e.g., {?a,b,c}), which is quadratic in the number of members. 4. An exploded variable followed by unexploded ones in a /, . or default expression (e.g., {a,b,c}-), which is quadratic.
A run of members can be divided among the variables in many ways. When Template#match or Template#extract is called with a maliciously crafted URI, this can result in uncontrolled resource consumption, leading to denial of service. With 2.9.2, {a}{.a,b,c} takes over 6 seconds to reject 800 bytes of input on MRI Ruby 2.7, and over 15 seconds on JRuby.
Users of the URI parsing capabilities in Addressable but not the URI template matching capabilities are unaffected. Users who only call Template#expand are unaffected.
Affected Versions
This vulnerability affects Addressable >= 2.3.0 (note: 2.3.0 and 2.3.1 were yanked; the earliest installable release is 2.3.2), including 2.9.2. It is fixed in 2.10.0, with two exceptions where matching can still take polynomial time on MRI Ruby < 3.3, JRuby and TruffleRuby: when a processor's match method gives a variable its own pattern, since 2.10.0 then keeps every choice open, as earlier versions did, so that the pattern decides the values; and for some templates that combine an exploded variable, or several variables in one expression, with other expressions, such as {+c,d}{&b}.{b}.
The vulnerability is exploitable on Ruby implementations whose regular expression engine backtracks without memoization: MRI Ruby < 3.2 and JRuby. MRI Ruby 3.2 and later and TruffleRuby 40.0 memoize or don't backtrack for the regular expressions that 2.9.0 generated for these shapes. Since 2.9.1, some of them are slow on MRI Ruby 3.2 and TruffleRuby 40.0 for a different reason, described in GHSA-jrfq-gw62-2f3j. Earlier TruffleRuby versions were not tested.
This has been confirmed on the following runtimes with Addressable 2.9.2:
| Runtime | Status | |---------|--------| | MRI Ruby 2.7 | Vulnerable | | MRI Ruby 3.1 | Vulnerable | | MRI Ruby 3.2 | Not affected by this issue | | MRI Ruby 3.3 | Not affected | | MRI Ruby 4.0 | Not affected | | JRuby 9.4 | Vulnerable | | TruffleRuby 40.0 | Not affected by this issue |
Workarounds
- Upgrade to MRI Ruby 3.3 or later, if your application does not use JRuby. - Avoid matching user-supplied input on unpatched versions of the library against templates with an exploded variable and another variable in the same expression, or with an exploded expression directly before another expression. - Limit the length of user-supplied URIs before matching them. Because the cost is polynomial, this only bounds it, but it works on every runtime. - Apply a short timeout, such as Timeout.timeout, around any call to Template#match or Template#extract that processes user-supplied data. It interrupts the matching thread at an arbitrary point, so it isn't safe in every application.
Credits
Found by Bob Aman (@sporkmonger).
For more information
If there are any questions or comments about this advisory: Open an issue
Other sources
Addressable is an alternative implementation to the URI implementation that is part of Ruby's standard library. From 2.3.0 until 2.10.0, Addressable URI templates with exploded variables adjacent to other variables generate ambiguous regular expressions that can backtrack polynomially on MRI Ruby before 3.2 and JRuby. Calling Template#match or Template#extract with a crafted URI can cause uncontrolled resource consumption and denial of service. The remediation does not cover processor-supplied variable patterns or certain templates that combine exploded or multi-variable expressions with other expressions, which can remain polynomial on MRI Ruby before 3.3, JRuby, and TruffleRuby. This issue is fixed in version 2.10.0.
— MITRE
Affected Software
Remediation
Recommended actions to resolve this vulnerability, in priority order.
- Upgrade
Upgrade
rubygems/addressableto a version that resolves this vulnerability.Fixed in 2.10.0 - Upgrade
Upgrade to a fixed release to a version that resolves this vulnerability.
Fixed in 2.10.0 - Upgrade
Upgrade to a fixed release to a version that resolves this vulnerability.
Fixed in 3.3 - Compensating control
Apply a short timeout, such as Timeout.timeout, around calls to Template#match or Template#extract that process user-supplied data.
- Compensating control
Limit the length of user-supplied URIs before matching them.
- Compensating control
On unpatched Addressable versions, avoid matching user-supplied input against templates with an exploded variable and another variable in the same expression, or an exploded expression directly before another expression.
Event History
Frequently Asked Questions
Which deployments are realistically exposed to this denial-of-service issue?
Applications using Addressable URI templates are exposed when they call Template#match or Template#extract on attacker-controlled URIs. The affected template form includes exploded variables adjacent to other variables; versions from 2.3.0 through before 2.10.0 are affected.
What does an attacker need to do to trigger the problem?
An attacker needs to supply a crafted URI that is processed by Template#match or Template#extract against a vulnerable template. No privileges or user interaction are required, but exploitation has high attack complexity because the URI must trigger costly regular-expression backtracking.
Are all Ruby runtimes affected in the same way?
The described ambiguous-regex behavior affects MRI Ruby before 3.2 and JRuby. After upgrading to Addressable 2.10.0, processor-supplied variable patterns and certain templates combining exploded or multi-variable expressions with other expressions can still have polynomial behavior on MRI Ruby before 3.3, JRuby, and TruffleRuby.
What should be done if an immediate upgrade is not possible?
Avoid processing untrusted URIs with Template#match or Template#extract when templates contain exploded variables adjacent to other variables. Also review templates using processor-supplied variable patterns or combinations of exploded or multi-variable expressions with other expressions, since those cases are not fully covered by the remediation.
How can I determine whether my application is affected?
Check whether it uses Addressable versions earlier than 2.10.0 and invokes Template#match or Template#extract. Review the URI templates used by those calls for exploded variables next to other variables, and for the residual template patterns identified in the advisory.