Download tasks/aws__aws-cli-10362/solution/patch.diff from Ktanmay21/aws-cli-diff: direct link, hf CLI and curl.
- Browser
- Download file 3.11 kB
-
https://huggingface.co/datasets/Ktanmay21/aws-cli-diff/resolve/f50dbbb4f8bb7e071cea947b3db06ddb842934f4/tasks/aws__aws-cli-10362/solution/patch.diff
- Command line
-
hf download hf://datasets/Ktanmay21/aws-cli-diff@f50dbbb4f8bb7e071cea947b3db06ddb842934f4/tasks/aws__aws-cli-10362/solution/patch.diff
-
curl -L -o patch.diff https://huggingface.co/datasets/Ktanmay21/aws-cli-diff/resolve/f50dbbb4f8bb7e071cea947b3db06ddb842934f4/tasks/aws__aws-cli-10362/solution/patch.diff
3.11 kB
| diff --git a/.changes/next-release/bugfix-s3-45848.json b/.changes/next-release/bugfix-s3-45848.json | |
| new file mode 100644 | |
| index 000000000000..d17fa89a8178 | |
| --- /dev/null | |
| +++ b/.changes/next-release/bugfix-s3-45848.json | |
| +{ | |
| + "type": "bugfix", | |
| + "category": "s3", | |
| + "description": "Fix false negative in parent-directory escape detection that allowed keys like ``/../foo`` to bypass warning during downloads" | |
| +} | |
| diff --git a/awscli/customizations/s3/s3handler.py b/awscli/customizations/s3/s3handler.py | |
| index 72b5c724395d..7fc49c95317d 100644 | |
| --- a/awscli/customizations/s3/s3handler.py | |
| +++ b/awscli/customizations/s3/s3handler.py | |
| def _warn_parent_reference(self, fileinfo): | |
| # normpath() will use the OS path separator so we | |
| # need to take that into account when checking for a parent prefix. | |
| parent_prefix = '..' + os.path.sep | |
| - escapes_cwd = os.path.normpath(fileinfo.compare_key).startswith( | |
| - parent_prefix) | |
| + # Anchor compare_key against '.' (the destination directory root) | |
| + # to avoid false negatives on paths like '/../foo' | |
| + normalized = os.path.normpath('.' + os.path.sep + fileinfo.compare_key) | |
| + escapes_cwd = normalized.startswith(parent_prefix) | |
| if escapes_cwd: | |
| warning = create_warning( | |
| fileinfo.compare_key, "File references a parent directory.") | |
| diff --git a/tests/unit/customizations/s3/test_s3handler.py b/tests/unit/customizations/s3/test_s3handler.py | |
| index b7b578254e21..fedeedeb7009 100644 | |
| --- a/tests/unit/customizations/s3/test_s3handler.py | |
| +++ b/tests/unit/customizations/s3/test_s3handler.py | |
| def test_allow_double_dots_that_dont_escape_cwd(self): | |
| future = self.transfer_request_submitter.submit(fileinfo) | |
| self.assertIsInstance(self.result_queue.get(), DryRunResult) | |
| + def test_warn_and_ignore_on_leading_slash_parent_reference(self): | |
| + fileinfo = self.create_file_info('/../foo.txt') | |
| + future = self.transfer_request_submitter.submit(fileinfo) | |
| + warning_result = self.result_queue.get() | |
| + self.assertIsInstance(warning_result, WarningResult) | |
| + self.assert_no_downloads_happened() | |
| + | |
| + def test_warn_and_ignore_on_leading_slash_stacked_parent_reference(self): | |
| + fileinfo = self.create_file_info('/../../../foo/bar.txt') | |
| + future = self.transfer_request_submitter.submit(fileinfo) | |
| + warning_result = self.result_queue.get() | |
| + self.assertIsInstance(warning_result, WarningResult) | |
| + self.assert_no_downloads_happened() | |
| + | |
| + def test_warn_and_ignore_on_double_leading_slash_parent_reference(self): | |
| + fileinfo = self.create_file_info('//../foo') | |
| + future = self.transfer_request_submitter.submit(fileinfo) | |
| + warning_result = self.result_queue.get() | |
| + self.assertIsInstance(warning_result, WarningResult) | |
| + self.assert_no_downloads_happened() | |
| + | |
| def test_dry_run(self): | |
| self.cli_params['dryrun'] = True | |
| self.transfer_request_submitter = DownloadRequestSubmitter( | |