vincbeck commented on code in PR #77797:
URL: https://github.com/apache/airflow/pull/77797#discussion_r4743491891
##########
airflow-core/src/airflow/api_fastapi/core_api/security.py:
##########
@@ -1490,9 +1490,16 @@ def is_safe_url(target_url: str, request: Request | None
= None) -> bool:
# this leads to an inconsistency where python returns a target url with
/// as a valid url
# The same thing also happens with \ where under WHATWG \ are translated
to /, including
# after a scheme, so "https:\\host" is an authority for a browser but a
path for urllib.
+ # Callers redirect to the URL as given, which is sent with "\\" quoted and
which a browser does
+ # not unquote: in "https://host%5C@other" the authority is "other", so it
is checked too.
+ given_url = target_url.strip()
target_url = unquote(target_url).strip().replace("\\", "/")
- if target_url.startswith("//"):
- return False
+ for url in (given_url, target_url):
+ # A browser skips every slash after "http:" or "https:", so
"http:///other" names "other",
+ # while urllib reads no authority and urljoin resolves it onto the
base.
+ if url.startswith("//") or (urlparse(url).scheme and not
urlparse(url).netloc):
Review Comment:
nit: `urlparse(url)` is called twice here
```suggestion
parsed_url = urlparse(url)
if url.startswith("//") or (parsed_url.scheme and not
parsed_url.netloc):
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]