mirror of
https://github.com/jekyll/jekyll.git
synced 2026-04-28 03:01:03 -04:00
Jekyll.sanitized_path: escape tildes before sanitizing a questionable path
This commit is contained in:
@@ -153,8 +153,9 @@ module Jekyll
|
||||
def sanitized_path(base_directory, questionable_path)
|
||||
return base_directory if base_directory.eql?(questionable_path)
|
||||
|
||||
questionable_path.insert(0, '/') unless questionable_path.start_with?('/')
|
||||
clean_path = File.expand_path(questionable_path, "/")
|
||||
clean_path = clean_path.sub(/\A\w\:\//, '/')
|
||||
clean_path.sub!(/\A\w\:\//, '/')
|
||||
|
||||
unless clean_path.start_with?(base_directory.sub(/\A\w\:\//, '/'))
|
||||
File.join(base_directory, clean_path)
|
||||
|
||||
0
test/source/~hi.txt
Normal file
0
test/source/~hi.txt
Normal file
@@ -15,4 +15,13 @@ class TestPathSanitization < JekyllUnitTest
|
||||
assert_equal "/tmp/foobar/jail/..c:/..c:/..c:/etc/passwd", Jekyll.sanitized_path("/tmp/foobar/jail", "..c:/..c:/..c:/etc/passwd")
|
||||
end
|
||||
end
|
||||
|
||||
should "escape tilde" do
|
||||
assert_equal source_dir("~hi.txt"), Jekyll.sanitized_path(source_dir, "~hi.txt")
|
||||
assert_equal source_dir("files", "~hi.txt"), Jekyll.sanitized_path(source_dir, "files/../files/~hi.txt")
|
||||
end
|
||||
|
||||
should "remove path traversals" do
|
||||
assert_equal source_dir("files", "hi.txt"), Jekyll.sanitized_path(source_dir, "f./../../../../../../files/hi.txt")
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user