LowGHSA-h78h-gj97-g737CVE-2026-141529

Addressable::Template builds its regexp in quadratic time for patterns with non-ASCII characters or many adjacent expressions

Published 1 Dec 2026 · Updated 2 Dec 2026

Affected package

addressableRubyGems
Affected
>=2.9.1 <2.10.0
Fixed in
2.10.0
Update to the fixed version for your release line, for example:bundle update --conservative addressable # Gemfile: '>= 2.10.0'

We confirm your address first. See our privacy policy.

Which addressable does your project really install?

Drop your Gemfile.lock hereWe find the exact addressable version you install, even when another package pulls it in, and tell you if it’s affected and what to run. Free, no sign-up.

Works for private projects: the file is read in memory to run the scan and then dropped. Also reads Gemfile.

Public repo?

Look after several Rails or Ruby apps? Indie watches up to 15 repos, private ones too, for $5 a month. See Indie

Details

Impact

Addressable::Template builds a regular expression from its pattern the first time it's needed, by #match, #extract, #to_regexp, #variables (and its aliases #keys and #names), #variable_defaults or #freeze. When the pattern has non-ASCII characters, or a long run of expressions with no literal text between them (such as {a}{b}{c}), building it takes time quadratic in the pattern's length. A non-ASCII pattern of a few hundred kilobytes takes seconds on MRI and longer on JRuby. A run of 5,000 expressions, 15 KB, takes about 4 seconds on MRI and 8 seconds on JRuby. Other templates build in linear time.

The cost is in the pattern, not in the URI being matched, so only an application that builds templates from untrusted input is affected. Matching untrusted URIs against the application's own templates isn't. The regular expression is cached on the template, so the cost is paid once per template, except that #match and #extract with a processor build it on every call. #expand and #partial_expand don't build it and aren't affected.

Templates from untrusted sources are uncommon, and the attacker needs a pattern of many kilobytes to cause a delay of seconds, so attack complexity is high.

Affected Versions

This vulnerability affects Addressable >= 2.9.1. Version 2.9.1 added a step that looks at what follows each expression. It finds each expression's position by character offset, and for each expression it looks through every later expression with no literal text before it, so either kind of pattern makes building the regular expression quadratic. It is fixed in 2.10.0, where the step works in byte offsets and in a single pass.

Workarounds

  • Don't match, extract, list the variables of or freeze templates from untrusted sources, or limit their length.
  • Reject templates with non-ASCII characters, or pct-encode those characters before building the template, and reject templates with long runs of expressions next to each other.

Proof of Concept

require "addressable/template"

[10_000, 20_000].each do |count|
  template = Addressable::Template.new("é{a}" * count)
  started = Process.clock_gettime(Process::CLOCK_MONOTONIC)
  template.to_regexp
  elapsed = Process.clock_gettime(Process::CLOCK_MONOTONIC) - started
  puts "%6d expressions: %.2fs" % [count, elapsed]
end

On affected versions, doubling the number of expressions roughly triples to quadruples the time. On fixed versions, and with a in place of é on any version, it roughly doubles.

The same holds for expressions next to each other, at smaller sizes:

require "addressable/template"

[2_500, 5_000].each do |count|
  template = Addressable::Template.new("{a}" * count)
  started = Process.clock_gettime(Process::CLOCK_MONOTONIC)
  template.to_regexp
  elapsed = Process.clock_gettime(Process::CLOCK_MONOTONIC) - started
  puts "%6d expressions: %.2fs" % [count, elapsed]
end

On affected versions, doubling the number of expressions quadruples the time. On fixed versions, and with a{a} in place of {a} on any version, it roughly doubles.

Credits

Found by Bob Aman (@sporkmonger).

For more information

If ther are any questions or comments about this advisory:

Is GHSA-h78h-gj97-g737 in any of your client repos?

Checking one package by hand is fine. Checking it across forty client projects is not. NPMscan reads the lockfiles in every GitHub repo you pick, finds each project with an affected addressable, and gives you the command that fixes it.

More advisories for addressable

  • LowCVE-2026-141532Addressable URI#origin= takes the host from the userinfo · 2 Dec 2026
  • LowCVE-2026-141536Addressable URI#request_uri returns control characters unencoded with possible HTTP request splitting · 1 Dec 2026
  • LowCVE-2026-141535Addressable URI#hostname strips brackets from hosts that aren't IP literals · 1 Dec 2026
  • LowCVE-2026-141537Addressable URI normalization takes quadratic time on long runs of combining marks · 1 Dec 2026
  • MediumCVE-2026-141538Addressable URI userinfo setters store delimiters raw, so the serialized URI names a different host · 1 Dec 2026
  • MediumCVE-2026-141539Addressable native IDNA backend truncates a host at a pct-encoded NUL when normalizing · 1 Dec 2026
All 22 advisories for addressable

References

Advisory data from OSV.dev (opens OSV.dev in a new tab), refreshed daily.