Skip to content

Commit a9d5777

Browse files
authored
fix: set filter="data" explicitly (#2278)
1 parent aa2ccb3 commit a9d5777

2 files changed

Lines changed: 8 additions & 8 deletions

File tree

  • apiserver/paasng

apiserver/paasng/paasng/platform/sourcectl/package/client.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,9 @@ def read_file(self, file_path: str) -> bytes:
112112

113113
def export(self, local_path: str):
114114
"""导出指定当前 Tar 包到local_path"""
115-
self.tar.extractall(local_path)
115+
# set filter="data" explicitly to fix CVE-2007-4559
116+
# see https://docs.python.org/3.11/library/tarfile.html#tarfile-extraction-filter
117+
self.tar.extractall(local_path, filter="data") # type: ignore[call-arg]
116118

117119
def close(self):
118120
"""关闭文件句柄"""
@@ -192,16 +194,12 @@ def list(self, tarfile_like: bool = True) -> List[str]:
192194
@staticmethod
193195
def _is_invalid_file_format_error(message: str) -> bool:
194196
"""Check if the stderr message indicates an invalid file format."""
195-
if re.search(r"tar:.* not look like a tar archive", message):
196-
return True
197-
return False
197+
return bool(re.search(r"tar:.* not look like a tar archive", message))
198198

199199
@staticmethod
200200
def _is_not_found_error(message: str) -> bool:
201201
"""Check if the stderr message indicates a file not found."""
202-
if re.search(r"tar:.*: Not found in archive", message):
203-
return True
204-
return False
202+
return bool(re.search(r"tar:.*: Not found in archive", message))
205203

206204

207205
class ZipClient(BasePackageClient):

apiserver/paasng/tests/paasng/platform/smart_app/conftest.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,9 @@ def zip_path(contents):
5353
@pytest.fixture()
5454
def untar_path(tar_path):
5555
with tarfile.open(tar_path) as tar, generate_temp_dir() as worker_dir:
56-
tar.extractall(worker_dir)
56+
# set filter="data" explicitly to fix CVE-2007-4559
57+
# see https://docs.python.org/3.11/library/tarfile.html#tarfile-extraction-filter
58+
tar.extractall(worker_dir, filter="data") # type: ignore[call-arg]
5759
yield worker_dir
5860

5961

0 commit comments

Comments
 (0)