Skip to content

Commit

Permalink
Merge branch 'fix-directory-traversal-1.2' into 1.2
Browse files Browse the repository at this point in the history
  • Loading branch information
philr committed Jul 19, 2022
2 parents 394c381 + ac3ee68 commit b98c32e
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 4 deletions.
2 changes: 1 addition & 1 deletion lib/tzinfo/ruby_data_source.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def initialize
# Raises InvalidTimezoneIdentifier if the timezone is not found or the
# identifier is invalid.
def load_timezone_info(identifier)
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__')

Expand Down
1 change: 1 addition & 0 deletions test/assets/payload.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
raise 'This should never be executed'
8 changes: 7 additions & 1 deletion test/tc_ruby_data_source.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,15 @@ def test_load_timezone_info_does_not_exist

def test_load_timezone_info_invalid
assert_raises(InvalidTimezoneIdentifier) do
@data_source.load_timezone_info('../Definitions/UTC')
@data_source.load_timezone_info('../definitions/UTC')
end
end

def test_load_timezone_info_directory_traversal
test_data_depth = TZINFO_TEST_DATA_DIR.scan('/').size
payload_path = File.join(TESTS_DIR, 'assets', 'payload')
assert_raises(InvalidTimezoneIdentifier) { Timezone.get("foo\n#{'/..' * (test_data_depth + 4)}#{payload_path}") }
end

def test_load_timezone_info_nil
assert_raises(InvalidTimezoneIdentifier) do
Expand Down
2 changes: 1 addition & 1 deletion test/tc_timezone.rb
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ 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_nil
Expand Down
2 changes: 1 addition & 1 deletion test/tc_zoneinfo_data_source.rb
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ def test_load_timezone_info_does_not_exist

def test_load_timezone_info_invalid
assert_raises(InvalidTimezoneIdentifier) do
@data_source.load_timezone_info('../Definitions/Europe/London')
@data_source.load_timezone_info('../zoneinfo/Europe/London')
end
end

Expand Down

0 comments on commit b98c32e

Please sign in to comment.