7
7
import sys
8
8
import urllib .request
9
9
from pathlib import Path
10
+ from urllib .parse import urlparse
10
11
from zipfile import ZipFile
11
12
12
13
from Crypto .Hash import keccak
27
28
Path .mkdir (ARTIFACTS_DIR , parents = True , exist_ok = True )
28
29
29
30
31
+ def validate_url_scheme (url : str ) -> None :
32
+ """Validate that URL uses a safe scheme (http or https only)."""
33
+ parsed = urlparse (url )
34
+ if parsed .scheme not in ("http" , "https" ):
35
+ raise ValueError (f"Unsafe URL scheme '{ parsed .scheme } ' in URL: { url } " )
36
+
37
+
30
38
def halt_old_architecture (path : Path ) -> None :
31
39
if not Path .is_file (path ):
32
40
raise argparse .ArgumentTypeError (
@@ -123,6 +131,7 @@ def install_artifacts(versions: [str], silent: bool = False) -> bool:
123
131
Path .mkdir (artifact_file_dir , parents = True , exist_ok = True )
124
132
if not silent :
125
133
print (f"Installing solc '{ version } '..." )
134
+ validate_url_scheme (url )
126
135
urllib .request .urlretrieve (url , artifact_file_dir .joinpath (f"solc-{ version } " ))
127
136
128
137
verify_checksum (version )
@@ -179,6 +188,7 @@ def verify_checksum(version: str) -> None:
179
188
def get_soliditylang_checksums (version : str ) -> (str , str ):
180
189
(_ , list_url ) = get_url (version = version )
181
190
# pylint: disable=consider-using-with
191
+ validate_url_scheme (list_url )
182
192
list_json = urllib .request .urlopen (list_url ).read ()
183
193
builds = json .loads (list_json )["builds" ]
184
194
matches = list (filter (lambda b : b ["version" ] == version , builds ))
@@ -262,11 +272,13 @@ def get_installable_versions() -> [str]:
262
272
# pylint: disable=consider-using-with
263
273
def get_available_versions () -> [str ]:
264
274
(_ , list_url ) = get_url ()
275
+ validate_url_scheme (list_url )
265
276
list_json = urllib .request .urlopen (list_url ).read ()
266
277
available_releases = json .loads (list_json )["releases" ]
267
278
# pylint: disable=consider-using-with
268
279
if soliditylang_platform () == LINUX_AMD64 :
269
280
(_ , list_url ) = get_url (version = EARLIEST_RELEASE [LINUX_AMD64 ])
281
+ validate_url_scheme (list_url )
270
282
github_json = urllib .request .urlopen (list_url ).read ()
271
283
additional_linux_versions = json .loads (github_json )["releases" ]
272
284
available_releases .update (additional_linux_versions )
@@ -288,6 +300,7 @@ def soliditylang_platform() -> str:
288
300
289
301
def get_latest_release () -> str :
290
302
(_ , list_url ) = get_url ()
303
+ validate_url_scheme (list_url )
291
304
list_json = urllib .request .urlopen (list_url ).read ()
292
305
latest_release = json .loads (list_json )["latestRelease" ]
293
306
return latest_release
0 commit comments