wolfdn commented on code in PR #64955:
URL: https://github.com/apache/airflow/pull/64955#discussion_r3073405687


##########
airflow-core/src/airflow/api_fastapi/auth/middlewares/refresh_token.py:
##########
@@ -61,16 +61,29 @@ async def dispatch(self, request: Request, call_next):
             response = await call_next(request)
 
             if new_token is not None:
+                cookie_path = get_cookie_path()
                 secure = bool(conf.get("api", "ssl_cert", fallback=""))
                 response.set_cookie(
                     COOKIE_NAME_JWT_TOKEN,
                     new_token,
-                    path=get_cookie_path(),
+                    path=cookie_path,
                     httponly=True,
                     secure=secure,
                     samesite="lax",
                     max_age=0 if new_token == "" else None,
                 )
+                # Clear any stale _token cookie at root path "/".
+                # Older Airflow instances may have set the cookie there;
+                # without this, the root-path cookie keeps being sent on
+                # every request, causing an infinite redirect loop.
+                if new_token == "" and cookie_path != "/":

Review Comment:
   > Why is that conditional of `new_token == ""` don't we want to always 
remove stale cookies on `/` when we set a new one?
   
   That's true, we can actually remove the check for `new_token == ""`. With 
this condition, the stale root-path cookie was only deleted when the middleware 
detected the token as invalid/expired. It would actually be better to always 
clear it whenever we're operating on a subpath.
   
   And yes, in my tests this fixed the redirection loop problem.



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