Skip to content

Commit 0fc9272

Browse files
authored
Merge pull request #1109 from TrellixVulnTeam/main
CVE-2007-4559 Patch
2 parents 7ebd114 + 91c19d7 commit 0fc9272

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1919

2020
### Changed
2121

22+
* Patched [CVE-2007-4559](https://github.com/advisories/GHSA-gw9q-c7gh-j9vm) vulnerability.
2223
* Updated workflows to v2.
2324
* Fixed attribute error in `compas_rhino.conversions.ellipse_to_compas`.
2425
* Changed deepcopy of `RhinoBrep` to use the native `Rhino.Geometry` mechanism.

src/compas/__init__.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,26 @@ def get_bunny(localstorage=None):
303303
urlretrieve(url, destination)
304304

305305
with tarfile.open(destination) as file:
306-
file.extractall(localstorage)
306+
307+
def is_within_directory(directory, target):
308+
309+
abs_directory = os.path.abspath(directory)
310+
abs_target = os.path.abspath(target)
311+
312+
prefix = os.path.commonprefix([abs_directory, abs_target])
313+
314+
return prefix == abs_directory
315+
316+
def safe_extract(tar, path=".", members=None, numeric_owner=False):
317+
318+
for member in tar.getmembers():
319+
member_path = os.path.join(path, member.name)
320+
if not is_within_directory(path, member_path):
321+
raise Exception("Attempted Path Traversal in Tar File")
322+
323+
tar.extractall(path, members, numeric_owner=numeric_owner)
324+
325+
safe_extract(file, localstorage)
307326

308327
os.remove(destination)
309328

0 commit comments

Comments
 (0)