Skip to content

Commit

Permalink
Merge branch 'fix-directory-traversal-0.3' into 0.3
Browse files Browse the repository at this point in the history
  • Loading branch information
philr committed Jul 19, 2022
2 parents 587af76 + cccfad8 commit 01bcca5
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/tzinfo/timezone.rb
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ def self.default_dst
def self.get(identifier)
instance = @@loaded_zones[identifier]
unless instance
raise InvalidTimezoneIdentifier, 'Invalid identifier' if identifier !~ /^[A-Za-z0-9\+\-_]+(\/[A-Za-z0-9\+\-_]+)*$/
raise InvalidTimezoneIdentifier, 'Invalid identifier' if identifier !~ /\A[A-Za-z0-9+\-_]+(\/[A-Za-z0-9+\-_]+)*\z/
identifier = identifier.gsub(/-/, '__m__').gsub(/\+/, '__p__')
begin
# Use a temporary variable to avoid an rdoc warning
Expand Down
1 change: 1 addition & 0 deletions test/in_load_path/payload.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
raise 'This should never be executed'
7 changes: 6 additions & 1 deletion test/tc_timezone.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
$:.unshift File.join(File.dirname(__FILE__), "..", "lib")
$:.unshift File.join(File.dirname(__FILE__), "in_load_path")
require 'test/unit'
require File.join(File.dirname(__FILE__), 'test_utils')
require 'tzinfo'
Expand Down Expand Up @@ -97,7 +98,11 @@ def test_get_not_exist
end

def test_get_invalid
assert_raises(InvalidTimezoneIdentifier) { Timezone.get('../Definitions/UTC') }
assert_raises(InvalidTimezoneIdentifier) { Timezone.get('../definitions/UTC') }
end

def test_get_directory_traversal
assert_raises(InvalidTimezoneIdentifier) { Timezone.get("foo\n/../../../payload") }
end

def test_get_nil
Expand Down

0 comments on commit 01bcca5

Please sign in to comment.