Skip to content

Commit 5b283e0

Browse files
committed
test_cwl11 tar usage: plug possible security issue in Python 3.12+
1 parent b073c32 commit 5b283e0

File tree

1 file changed

+17
-6
lines changed

1 file changed

+17
-6
lines changed

schema_salad/tests/test_cwl11.py

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@
66

77
import os
88
import shutil
9+
import sys
910
import tarfile
10-
from typing import Any, Dict, Generator, Tuple, Union
11+
from typing import TYPE_CHECKING, Any, Dict, Generator, Tuple, Union, cast
1112

1213
import pytest
1314
import requests
@@ -20,6 +21,10 @@
2021

2122
from .util import get_data
2223

24+
if TYPE_CHECKING:
25+
from http.client import HTTPResponse
26+
27+
2328
test_dir_name = "tests/"
2429

2530
SchemaType = Tuple[Loader, Union[Names, SchemaParseException], Dict[str, Any], Loader]
@@ -30,12 +35,18 @@ def cwl_v1_2_schema(
3035
tmp_path_factory: TempPathFactory,
3136
) -> Generator[SchemaType, None, None]:
3237
tmp_path = tmp_path_factory.mktemp("cwl_v1_2_schema")
33-
with requests.get(
34-
"https://github.com/common-workflow-language/cwl-v1.2/archive/v1.2.0.tar.gz",
35-
stream=True,
36-
).raw as specfileobj:
38+
with cast(
39+
"HTTPResponse",
40+
requests.get(
41+
"https://github.com/common-workflow-language/cwl-v1.2/archive/v1.2.0.tar.gz",
42+
stream=True,
43+
).raw,
44+
) as specfileobj:
3745
tf = tarfile.open(fileobj=specfileobj)
38-
tf.extractall(path=tmp_path) # this becomes cwl-v1.2-1.2.0
46+
if sys.version_info > (3, 12):
47+
tf.extractall(path=tmp_path, filter="data") # this becomes cwl-v1.2-1.2.0
48+
else:
49+
tf.extractall(path=tmp_path) # this becomes cwl-v1.2-1.2.0
3950
path = str(tmp_path / "cwl-v1.2-1.2.0/CommonWorkflowLanguage.yml")
4051
yield load_schema(path)
4152
shutil.rmtree(os.path.join(tmp_path))

0 commit comments

Comments
 (0)