pierrejeambrun commented on code in PR #47577:
URL: https://github.com/apache/airflow/pull/47577#discussion_r1988929780
##########
airflow/api_fastapi/core_api/security.py:
##########
@@ -197,3 +199,26 @@ def _requires_access(
) -> None:
if not is_authorized_callback():
raise HTTPException(status.HTTP_403_FORBIDDEN, "Forbidden")
+
+
+def is_safe_url(target_url: str) -> bool:
+ """
+ Check that the URL is safe.
+
+ Needs to belong to the same domain as base_url, use HTTP or HTTPS (no
JavaScript/data schemes),
+ is a valid normalized path.
+ """
+ base_url = conf.get("api", "base_url")
+ parsed_base = urlparse(base_url)
Review Comment:
> Let's check that target_url is not an empty string and also urlparse the
target_url the same way we parsed the base_url before we do the join. What if
the target is an absolute url? We could also check for bad protocols on
target_url.
The target is parsed in the line right after `urlparse(urljoin(base_url,
target_url))`
I have reorganized the code a little bit so it appears clearer that we are
only operating on `parsed_base` and `parsed_target` which are both parsed.
--
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]