-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Adding tarfile member sanitization to extractall() * fix formatting issues * Refactored extract_tarfile functions and added unit/functional tests Co-authored-by: Mehmet Nuri Deveci <[email protected]> Co-authored-by: Mohamed Elasmar <[email protected]> Co-authored-by: hnnasit <[email protected]> Co-authored-by: Haresh Nasit <[email protected]> Co-authored-by: Wing Fung Lau <[email protected]>
- Loading branch information
1 parent
8f030c5
commit 40bd90a
Showing
10 changed files
with
118 additions
and
13 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
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
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
Empty file.
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,29 @@ | ||
import os | ||
import tempfile | ||
import shutil | ||
import platform | ||
from pathlib import Path | ||
from tarfile import ExtractError | ||
|
||
from unittest import TestCase | ||
|
||
from samcli.lib.utils.tar import extract_tarfile | ||
|
||
|
||
class TestExtractTarFile(TestCase): | ||
def test_extract_tarfile_unpacks_a_tar(self): | ||
test_tar = Path(__file__).resolve().parents[3].joinpath("functional", "testdata", "lib", "utils", "test.tgz") | ||
test_dir = tempfile.mkdtemp() | ||
extract_tarfile(test_tar, test_dir) | ||
output_files = set(os.listdir(test_dir)) | ||
shutil.rmtree(test_dir) | ||
print(output_files) | ||
self.assertEqual({"test_utils.py"}, output_files) | ||
|
||
def test_raise_exception_for_unsafe_tarfile(self): | ||
tar_filename = "path_reversal_win.tgz" if platform.system().lower() == "windows" else "path_reversal_uxix.tgz" | ||
test_tar = Path(__file__).resolve().parents[3].joinpath("functional", "testdata", "lib", "utils", tar_filename) | ||
test_dir = tempfile.mkdtemp() | ||
self.assertRaisesRegex( | ||
ExtractError, "Attempted Path Traversal in Tar File", extract_tarfile, test_tar, test_dir | ||
) |
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
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