{"id":"GHSA-h78h-gj97-g737","summary":"Addressable::Template builds its regexp in quadratic time for patterns with non-ASCII characters or many adjacent expressions","details":"### Impact\n\n`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.\n\nThe 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.\n\nTemplates 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.\n\n### Affected Versions\n\nThis vulnerability affects Addressable \u003e= 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.\n\n### Workarounds\n\n- Don't match, extract, list the variables of or freeze templates from untrusted sources, or limit their length.\n- 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.\n\n### Proof of Concept\n\n```ruby\nrequire \"addressable/template\"\n\n[10_000, 20_000].each do |count|\n  template = Addressable::Template.new(\"é{a}\" * count)\n  started = Process.clock_gettime(Process::CLOCK_MONOTONIC)\n  template.to_regexp\n  elapsed = Process.clock_gettime(Process::CLOCK_MONOTONIC) - started\n  puts \"%6d expressions: %.2fs\" % [count, elapsed]\nend\n```\n\nOn 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.\n\nThe same holds for expressions next to each other, at smaller sizes:\n\n```ruby\nrequire \"addressable/template\"\n\n[2_500, 5_000].each do |count|\n  template = Addressable::Template.new(\"{a}\" * count)\n  started = Process.clock_gettime(Process::CLOCK_MONOTONIC)\n  template.to_regexp\n  elapsed = Process.clock_gettime(Process::CLOCK_MONOTONIC) - started\n  puts \"%6d expressions: %.2fs\" % [count, elapsed]\nend\n```\n\nOn 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.\n\n### Credits\n\nFound by Bob Aman (@sporkmonger).\n\n### For more information\n\nIf ther are any questions or comments about this advisory:\n* [Open an issue](https://github.com/sporkmonger/addressable/issues)","aliases":["CVE-2026-141529"],"modified":"2026-12-02T00:00:04.145236802Z","published":"2026-12-01T23:48:42Z","database_specific":{"github_reviewed":true,"github_reviewed_at":"2026-12-01T23:48:42Z","nvd_published_at":"2026-12-01T21:17:12Z","cwe_ids":["CWE-407"],"severity":"LOW"},"references":[{"type":"WEB","url":"https://github.com/sporkmonger/addressable/security/advisories/GHSA-h78h-gj97-g737"},{"type":"ADVISORY","url":"https://nvd.nist.gov/vuln/detail/CVE-2026-141529"},{"type":"WEB","url":"https://github.com/sporkmonger/addressable/commit/ebe911f8623bcc664d2e6df079c96c325ad181c8"},{"type":"PACKAGE","url":"https://github.com/sporkmonger/addressable"},{"type":"WEB","url":"https://github.com/sporkmonger/addressable/releases/tag/addressable-2.10.0"}],"affected":[{"package":{"name":"addressable","ecosystem":"RubyGems","purl":"pkg:gem/addressable"},"ranges":[{"type":"ECOSYSTEM","events":[{"introduced":"2.9.1"},{"fixed":"2.10.0"}]}],"versions":["2.9.1","2.9.2"],"database_specific":{"source":"https://github.com/github/advisory-database/blob/main/advisories/github-reviewed/2026/12/GHSA-h78h-gj97-g737/GHSA-h78h-gj97-g737.json","last_known_affected_version_range":"\u003c= 2.9.2"}}],"schema_version":"1.9.2","severity":[{"type":"CVSS_V3","score":"CVSS:3.1/AV:N/AC:H/PR:N/UI:N/S:U/C:N/I:N/A:L"}]}