vincbeck commented on code in PR #77209:
URL: https://github.com/apache/airflow/pull/77209#discussion_r4616943739


##########
providers/amazon/src/airflow/providers/amazon/aws/auth_manager/routes/login.py:
##########
@@ -273,14 +286,17 @@ def login_callback(request: Request):
         username=saml_auth.get_nameid(),
         email=attributes["email"][0] if "email" in attributes else None,
     )
-    url = conf.get("api", "base_url", fallback="/")
+    fallback_url = conf.get("api", "base_url", fallback="/")
+    next_url = matched.get("next") if matched else None
+    redirect_url = next_url if next_url and is_safe_url(next_url, 
request=request) else fallback_url
     token = get_auth_manager().generate_jwt(user)
 
+    cookie_path = get_cookie_path()
+    secure = _is_secure_request(request)

Review Comment:
   nit: these are still only used in the `LOGIN_MODE_REDIRECT` branch, can you 
move them back inside it?



##########
providers/amazon/tests/unit/amazon/aws/auth_manager/routes/test_login.py:
##########
@@ -149,7 +160,7 @@ def get_login_callback_response(
     relay_state: str,
     *,
     base_url: str = "http://testserver";,
-    pending: list[tuple[str, str, str]] | None = None,
+    pending: list[tuple] | None = None,

Review Comment:
   nit: the docstring below still says `(nonce, request_id, mode)` tuples. Also 
`tuple[str, str, str] | tuple[str, str, str, str | None]` would be more precise 
than a bare `tuple` (same in `make_login_state`).



##########
providers/amazon/src/airflow/providers/amazon/aws/auth_manager/routes/login.py:
##########
@@ -273,14 +286,17 @@ def login_callback(request: Request):
         username=saml_auth.get_nameid(),
         email=attributes["email"][0] if "email" in attributes else None,
     )
-    url = conf.get("api", "base_url", fallback="/")
+    fallback_url = conf.get("api", "base_url", fallback="/")
+    next_url = matched.get("next") if matched else None
+    redirect_url = next_url if next_url and is_safe_url(next_url, 
request=request) else fallback_url

Review Comment:
   Is `is_safe_url` needed here? `next` is already checked in `_start_login` 
before being stored, and the entry is signed so it can't be changed.



##########
providers/amazon/src/airflow/providers/amazon/aws/auth_manager/routes/login.py:
##########
@@ -196,14 +202,21 @@ def _start_login(request: Request, mode: str) -> 
RedirectResponse:
     callback_url = saml_auth.login(f"{mode}:{nonce}")
     response = RedirectResponse(url=callback_url)
     pending = _read_pending_logins(request)[-(MAX_PENDING_LOGINS - 1) :]
-    pending.append(
-        {
-            "nonce": nonce,
-            "request_id": saml_auth.get_last_request_id(),
-            "mode": mode,
-            "exp": time.time() + LOGIN_STATE_MAX_AGE,
-        }
-    )
+    entry: dict[str, Any] = {
+        "nonce": nonce,
+        "request_id": saml_auth.get_last_request_id(),
+        "mode": mode,
+        "exp": time.time() + LOGIN_STATE_MAX_AGE,
+    }
+    if mode == LOGIN_MODE_REDIRECT:
+        next_url = request.query_params.get("next")
+        if (

Review Comment:
   nit: maybe log something (debug level) when `next` is set but dropped? 
Otherwise it is hard to know why a user landed on the home page.



-- 
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]

Reply via email to