Skip to content

Commit

Permalink
Merge pull request #290 from Shopify/dominiqueflaaa.prevent-ReDoS
Browse files Browse the repository at this point in the history
Configure Regexp timeout
  • Loading branch information
DominiqueFlaaa authored Oct 8, 2024
2 parents d697625 + 5d30276 commit 2e53778
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 7 deletions.
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,12 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
- Security in case of vulnerabilities.

## [Unreleased]

- Nil.
---

## [1.11.1] - 2024-10-02
- Configure regexp timeout in Worldwide#Phone [#290](https://github.com/Shopify/worldwide/pull/290)

## [1.11.0] - 2024-10-02
- Add address1_regex to regions [#281](https://github.com/Shopify/worldwide/pull/281)
- Add address1_regex for BE, CL, MX, ES, IL [#282](https://github.com/Shopify/worldwide/pull/282)
Expand Down
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ GIT
PATH
remote: .
specs:
worldwide (1.11.0)
worldwide (1.11.1)
activesupport (>= 7.0)
i18n
phonelib (~> 0.8)
Expand Down
13 changes: 9 additions & 4 deletions lib/worldwide/phone.rb
Original file line number Diff line number Diff line change
Expand Up @@ -137,14 +137,19 @@ def split_extension(input)
number = input.downcase

["ext", "x", ";"].each do |separator|
if number.include?(separator)
m = number.match(Regexp.new("(?<base>[0-9a-z +-]*)\\s*#{separator}\\.?\\s*(?<ext>.*)"))
return [m["base"], m["ext"]] unless m.nil?
end
next unless number.include?(separator)

m = number.match(Regexp.new(
"(?<base>[0-9a-z +-]*)\\s*#{separator}\\.?\\s*(?<ext>.*)",
timeout: 1,
))
return [m["base"], m["ext"]] unless m.nil?
end

# If we get this far, then we have not found an extension, and assume that the full input is just a public number
[input, nil]
rescue Regexp::TimeoutError
[input, nil]
end

# Convert exotic characters to ASCII
Expand Down
2 changes: 1 addition & 1 deletion lib/worldwide/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

module Worldwide
VERSION = "1.11.0"
VERSION = "1.11.1"
end

0 comments on commit 2e53778

Please sign in to comment.