CVE-2026-141524: Addressable::Template#match and #extract take variable names from the URI, so a URI can add or reassign variables
Impact
Addressable::Template#match and #extract take the name of a variable in a ;, ? or & expression from the URI, not from the template, when the variable isn't exploded. The template /search{?q} matches /search?admin=true and gives {"q" => nil, "admin" => "true"}: the mapping has a variable the template doesn't have, and q is missing its value. The URI can also give its value to another of the template's variables, which takes the first value it's given. /files{;version}/{id} matches /files;id=secret/42 and gives id the value "secret", not the 42 in its place in the path.
A URI Template can only expand such a variable to its own name followed by = (Sections 3.2.7 to 3.2.9 of RFC 6570), and matching assigns the parts of a URI "to the named variables" (Section 1.4). So these URIs aren't expansions of the template, and the mappings name variables that the URI's text doesn't give them.
An application is affected if it matches an untrusted URI against a template with an unexploded ;, ? or & expression, and does one of these:
- uses the mapping's names as a list of the parameters it accepts, for example by passing the whole mapping on to set attributes or to build a database query; - trusts that a variable's value comes from where the template puts it, as with a ; expression before a path variable; - uses a processor whose restore acts on a value by its name, such as recording an identifier. restore is called with the name the URI gives, so a query parameter can make restore act again for a variable the template takes from the path. The processor then records the query's value, while the mapping keeps the path's; - relies on a processor's match pattern to restrict the value of such a variable. Another expression's variable can take the text and give it the restricted variable's name, so the pattern isn't applied.
Exploded variables, such as {?q}, aren't affected: the names they take from the URI are kept inside the variable's value. Templates without ;, ? or & expressions aren't affected, and neither is #expand.
Affected Versions
This vulnerability affects Addressable >= 2.3.0, the first version with RFC 6570 templates. Before 2.3.6, a URI can only add variables to the mapping, which then leaves out the variable whose value the URI took; giving a value to another of the template's variables, and the processor case, start with 2.3.6. It is fixed in 2.10.0, where an unexploded ;, ? or & expression only matches its own variables' names, so these URIs don't match. A processor's match pattern for such a variable then matches only its value, as documented, not the name and = as well, and restore is only called with the template's names.
Workarounds
- After matching, keep only the template's variables, and accept the URI only if they expand back to it. This rejects every URI above. It also rejects some that differ only in how they're written, such as a query with the names in a different order. - Check a processor's restrictions on a variable's value in restore, not only in match. - Don't act on values in a processor's restore, such as by recording them. Act on the mapping after it passes the check above.
Proof of Concept
ruby require "addressable/template"
search = Addressable::Template.new("/search{?q}") p search.extract("/search?admin=true")
files = Addressable::Template.new("/files{;version}/{id}") p files.extract("/files;id=secret/42")
Workaround: keep only the template's variables, and accept the URI only if they expand back to it. def extractstrictly(template, uri) mapping = template.extract(uri) return nil unless mapping mapping = mapping.select { |name, | template.variables.include?(name) } template.expand(mapping).tos == uri ? mapping : nil end p extractstrictly(search, "/search?admin=true") p extractstrictly(files, "/files;id=secret/42") p extractstrictly(files, "/files;version=2/42")
Affected versions print:
{"q" => nil, "admin" => "true"} {"version" => nil, "id" => "secret"} nil nil {"version" => "2", "id" => "42"}
Fixed versions print:
nil nil nil nil {"version" => "2", "id" => "42"}
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::Template#match and #extract accept names supplied by an untrusted URI for unexploded semicolon, query, and continuation expressions instead of limiting matches to variables declared by the template. Variable addition affects the full range, while reassignment of another template variable and processor match or restore effects begin in 2.3.6. An attacker can add mapping keys, reassign a template variable's value, bypass a processor match restriction, or cause processor restore logic to act on a URI-supplied name. 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 - Compensating control
After matching with Addressable::Template, keep only variables declared by the template and accept the URI only if expanding those variables reproduces the original URI.
- Compensating control
Check variable-value restrictions in a processor's restore, not only in match, and do not perform side effects on values handled by restore, such as recording them.
Event History
Frequently Asked Questions
Which applications are exposed to variable reassignment and processor-related effects?
Applications using Addressable versions 2.3.6 through 2.9.x may be exposed to URI-driven reassignment of template variables, processor match restriction bypass, and processor restore behavior acting on URI-supplied names. Variable addition affects the broader range beginning with 2.3.0.
What must an attacker be able to do to exploit this issue?
An attacker must be able to supply an untrusted URI that is processed by Addressable::Template#match or #extract using unexploded semicolon, query, or continuation expressions. No privileges or user interaction are indicated by the supplied vector.
Are applications safe if they use Addressable templates but do not process attacker-controlled URIs?
The described behavior depends on names supplied by an untrusted URI. Applications that do not pass untrusted URIs to the affected template matching or extraction methods are not described as exposed through this issue.
What is the remediation?
Upgrade the Addressable gem to version 2.10.0, which fixes the issue. If an immediate upgrade is not possible, avoid using affected template expressions with untrusted URIs where feasible.