Skip to content

Commit a49b3f9

Browse files
authored
Fixed incorrect sanitisation of URLs for package installation requests (#457)
1 parent 0f59d2e commit a49b3f9

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

src/murfey/server/api/bootstrap.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -228,15 +228,16 @@ def parse_cygwin_request(request_path: str):
228228
"""
229229

230230
# Validate request path
231-
if bool(re.fullmatch(r"^[\w\s\.\-/]+$", request_path)) is False:
231+
if bool(re.fullmatch(r"^[\w\s\.\-\+/]+$", request_path)) is False:
232232
raise ValueError(f"{request_path!r} is not a valid request path")
233233

234234
try:
235-
url = f'{find_cygwin_mirror()}{quote(request_path, safe="")}'
235+
url = f'{find_cygwin_mirror()}{quote(request_path, safe="/")}'
236236
except Exception:
237237
raise HTTPException(
238238
status_code=503, detail="Could not identify a suitable Cygwin mirror"
239239
)
240+
240241
logger.info(f"Forwarding Cygwin download request to {_sanitise_str(url)}")
241242
cygwin_data = requests.get(url)
242243
return Response(
@@ -434,7 +435,7 @@ def _rewrite_url(match):
434435
raise ValueError(f"{system!r} is not a valid msys2 environment")
435436

436437
# Construct URL to main MSYS repo and get response
437-
arch_url = f'{msys2_url}/{quote(system, safe="")}'
438+
arch_url = f'{msys2_url}/{quote(system, safe="/")}'
438439
response = requests.get(arch_url)
439440

440441
# Parse and rewrite package index content
@@ -497,7 +498,7 @@ def _rewrite_url(match):
497498

498499
# Construct URL to main MSYS repo and get response
499500
package_list_url = (
500-
f'{msys2_url}/{quote(system, safe="")}/{quote(environment, safe="")}'
501+
f'{msys2_url}/{quote(system, safe="/")}/{quote(environment, safe="/")}'
501502
)
502503
response = requests.get(package_list_url)
503504

@@ -551,7 +552,7 @@ def get_msys2_package_file(
551552
raise ValueError(f"{package!r} is not a valid package name")
552553

553554
# Construct URL to main MSYS repo and get response
554-
package_url = f'{msys2_url}/{quote(system, safe="")}/{quote(environment, safe="")}/{quote(package, safe="")}'
555+
package_url = f'{msys2_url}/{quote(system, safe="/")}/{quote(environment, safe="/")}/{quote(package, safe="/")}'
555556
package_file = requests.get(package_url)
556557

557558
if package_file.status_code == 200:
@@ -581,7 +582,7 @@ def _get_full_pypi_path_response(package: str) -> requests.Response:
581582
# alphanumerics (including underscores; \w), dashes (\-), and periods (\.)
582583
if re.match(r"^[\w\-\.]+$", package) is not None:
583584
# Sanitise and normalise package name according to PEP 503
584-
package_clean = quote(re.sub(r"[-_.]+", "-", package.lower()), safe="")
585+
package_clean = quote(re.sub(r"[-_.]+", "-", package.lower()), safe="/")
585586

586587
# Get HTTP response
587588
url = f"https://pypi.org/simple/{package_clean}"

0 commit comments

Comments
 (0)