-
Notifications
You must be signed in to change notification settings - Fork 312
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0586329
commit 9c468f3
Showing
10 changed files
with
93 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# Path Traversal Samples | ||
|
||
Copied from https://github.com/jwilk/path-traversal-samples on 2018-08-26. | ||
|
||
License: MIT |
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
class PathTraversalTest < MiniTest::Test | ||
TEST_FILE_ROOT = File.absolute_path('test/data/jwilk-path-traversal-samples') | ||
|
||
def setup | ||
FileUtils.rm_f '/tmp/moo' # with apologies to anyone using this file | ||
end | ||
|
||
def extract_path_traversal_zip(name) | ||
Zip::File.open(File.join(TEST_FILE_ROOT, name)) do |zip_file| | ||
zip_file.each do |entry| | ||
entry.extract | ||
end | ||
end | ||
end | ||
|
||
def in_tmpdir | ||
Dir.mktmpdir do |tmp| | ||
test_path = File.join(tmp, 'test') | ||
Dir.mkdir test_path | ||
Dir.chdir(test_path) do | ||
yield | ||
end | ||
end | ||
end | ||
|
||
def test_leading_slash | ||
in_tmpdir do | ||
extract_path_traversal_zip 'absolute1.zip' | ||
assert !File.exist?('/tmp/moo') | ||
end | ||
end | ||
|
||
def test_multiple_leading_slashes | ||
in_tmpdir do | ||
extract_path_traversal_zip 'absolute2.zip' | ||
assert !File.exist?('/tmp/moo') | ||
end | ||
end | ||
|
||
def test_leading_dot_dot | ||
in_tmpdir do | ||
extract_path_traversal_zip 'relative0.zip' | ||
assert !File.exist?('../moo') | ||
end | ||
end | ||
|
||
def test_non_leading_dot_dot | ||
in_tmpdir do | ||
extract_path_traversal_zip 'relative2.zip' | ||
assert !File.exist?('../moo') | ||
end | ||
end | ||
|
||
def test_file_symlink | ||
in_tmpdir do | ||
extract_path_traversal_zip 'symlink.zip' | ||
assert File.exist?('moo') | ||
assert !File.exist?('/tmp/moo') | ||
end | ||
end | ||
|
||
def test_directory_symlink | ||
in_tmpdir do | ||
extract_path_traversal_zip 'dirsymlink.zip' | ||
assert !File.exist?('/tmp/moo') | ||
end | ||
end | ||
|
||
def test_two_directory_symlinks_a | ||
in_tmpdir do | ||
# Can't create par/moo because the symlink par is skipped. | ||
assert_raises Errno::ENOENT do | ||
extract_path_traversal_zip 'dirsymlink2a.zip' | ||
end | ||
assert File.exist?('cur') | ||
assert_equal '.', File.readlink('cur') | ||
end | ||
end | ||
|
||
def test_two_directory_symlinks_b | ||
in_tmpdir do | ||
extract_path_traversal_zip 'dirsymlink2b.zip' | ||
assert File.exist?('cur') | ||
assert_equal '.', File.readlink('cur') | ||
assert !File.exist?('../moo') | ||
end | ||
end | ||
end |