kaxil commented on code in PR #77796:
URL: https://github.com/apache/airflow/pull/77796#discussion_r4746733299


##########
airflow-core/src/airflow/api_fastapi/core_api/security.py:
##########
@@ -187,7 +188,13 @@ def collect_request_tokens(
     candidates: list[str | None] = []
     if bearer_credentials and bearer_credentials.scheme.lower() == "bearer":
         candidates.append(bearer_credentials.credentials)
-    candidates.append(request.cookies.get(COOKIE_NAME_JWT_TOKEN))
+    # A browser holding ``_token`` cookies for several paths sends them all. 
We can't use
+    # ``request.cookies`` because Starlette only keeps the last one.
+    for header in request.headers.getlist("cookie"):
+        for chunk in header.split(";"):
+            candidates.extend(

Review Comment:
   `/auth/logout` requires no authentication, and this now collects every 
distinct `_token` value, so a request with `_token=0; _token=1; ...` reaches 
`revoke_token` several hundred times from 8 KB of cookies, where it used to be 
twice at most. Each one that fails validation logs a warning with a traceback. 
Should this stop after the first few `_token` values (dropping the rest, not 
raising, so logout still clears the cookie)? A browser only sends a handful.



##########
airflow-core/tests/unit/api_fastapi/core_api/routes/public/test_auth.py:
##########
@@ -330,6 +330,25 @@ def test_logout_revokes_every_credential_presented(self, 
logout_client):
         assert RevokedToken.is_revoked("test-jti-both-bearer") is True
         assert RevokedToken.is_revoked("test-jti-both-cookie") is True
 
+    def test_logout_revokes_every_token_cookie(self, logout_client):
+        """A browser holding ``_token`` cookies for several paths sends them 
all; each is revoked."""
+        auth_manager = logout_client.app.state.auth_manager
+        root_token = self._mint(auth_manager, "test-jti-root-path")
+        subpath_token = self._mint(auth_manager, "test-jti-subpath")
+
+        with patch.object(auth_manager, "get_url_logout", return_value=None):
+            response = logout_client.get(
+                "/auth/logout",
+                headers={
+                    "Cookie": f"{COOKIE_NAME_JWT_TOKEN}={subpath_token}; 
{COOKIE_NAME_JWT_TOKEN}={root_token}"

Review Comment:
   Both cookies go in one `Cookie` header here, so the `getlist("cookie")` loop 
has no coverage: reading only the first header still passes every logout test. 
Could this get a second case that sends them as two separate headers? Not 
blocking.



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