@@ -425,9 +425,13 @@ def lisa_download_logs(
425425 is_azure_blob = parsed .hostname and parsed .hostname .endswith (
426426 ".blob.core.windows.net"
427427 )
428+ # If the URL already carries a SAS token, the URL itself is the
429+ # credential — skip the Azure SDK / DefaultAzureCredential path
430+ # and let the plain HTTPS download below use the SAS URL directly.
431+ has_sas = "sig=" in (parsed .query or "" )
428432
429433 # Azure blob prefix (virtual directory) — list + download all
430- if is_azure_blob and not auth_token :
434+ if is_azure_blob and not auth_token and not has_sas :
431435 path_parts = [p for p in parsed .path .strip ("/" ).split ("/" ) if p ]
432436 if len (path_parts ) >= 2 :
433437 container = path_parts [0 ]
@@ -1272,7 +1276,8 @@ def _parse_portal_storage_url(url: str) -> Optional[dict[str, str]]:
12721276 Returns ``None`` if the URL is not a portal storage URL.
12731277 """
12741278 parsed = urlparse (url )
1275- if not parsed .hostname or not parsed .hostname .endswith ("portal.azure.com" ):
1279+ host = (parsed .hostname or "" ).rstrip ("." ).lower ()
1280+ if host != "portal.azure.com" :
12761281 return None
12771282 if not parsed .fragment :
12781283 return None
@@ -1397,25 +1402,32 @@ def _extract_archive(download_path: str, download_dir: str) -> str:
13971402
13981403 if tarfile .is_tarfile (download_path ):
13991404 os .makedirs (extract_dir , exist_ok = True )
1405+ abs_extract = os .path .abspath (extract_dir )
14001406 with tarfile .open (download_path ) as tf :
1401- safe_members = [
1402- m
1403- for m in tf .getmembers ()
1404- if not m .name .startswith (("/" , ".." )) and ".." not in m .name
1405- ]
1406- tf .extractall (extract_dir , members = safe_members )
1407+ safe_members = []
1408+ for m in tf .getmembers ():
1409+ target = os .path .abspath (os .path .join (abs_extract , m .name ))
1410+ if os .path .commonpath ([abs_extract , target ]) != abs_extract :
1411+ continue
1412+ safe_members .append (m )
1413+ # filter="data" (PEP 706) blocks unsafe members (links, abs paths,
1414+ # device files) on Python 3.12+; older versions ignore the kwarg
1415+ # via the try/except.
1416+ try :
1417+ tf .extractall (extract_dir , members = safe_members , filter = "data" )
1418+ except TypeError :
1419+ tf .extractall (extract_dir , members = safe_members )
14071420 os .remove (download_path )
14081421 return extract_dir
14091422
14101423 if zipfile .is_zipfile (download_path ):
14111424 os .makedirs (extract_dir , exist_ok = True )
1425+ abs_extract = os .path .abspath (extract_dir )
14121426 with zipfile .ZipFile (download_path ) as zf :
1413- safe_names = [
1414- n
1415- for n in zf .namelist ()
1416- if not n .startswith (("/" , ".." )) and ".." not in n
1417- ]
1418- for name in safe_names :
1427+ for name in zf .namelist ():
1428+ target = os .path .abspath (os .path .join (abs_extract , name ))
1429+ if os .path .commonpath ([abs_extract , target ]) != abs_extract :
1430+ continue
14191431 zf .extract (name , extract_dir )
14201432 os .remove (download_path )
14211433 return extract_dir
0 commit comments