sjyangkevin commented on code in PR #77619:
URL: https://github.com/apache/airflow/pull/77619#discussion_r4713542856
##########
providers/fab/src/airflow/providers/fab/auth_manager/api_fastapi/routes/login.py:
##########
@@ -129,22 +131,20 @@ def create_token_cli(request: Request, body: dict[str,
Any] = Body(...)) -> Logi
status_code=status.HTTP_307_TEMPORARY_REDIRECT,
)
def logout(request: Request) -> RedirectResponse:
- """Clear session cookies and redirect to the login page."""
- with _get_flask_app().app_context(), _release_scoped_session():
- login_url = get_auth_manager().get_url_login()
- secure = request.base_url.scheme == "https" or bool(conf.get("api",
"ssl_cert", fallback=""))
- cookie_path = get_cookie_path()
- response = RedirectResponse(login_url)
- response.delete_cookie(
- key="session",
- path=cookie_path,
- secure=secure,
- httponly=True,
- )
- response.delete_cookie(
- key=COOKIE_NAME_JWT_TOKEN,
- path=cookie_path,
- secure=secure,
- httponly=True,
- )
- return response
+ """Clear the API token cookie and redirect to the Flask logout view, which
ends the session."""
+ # The trailing slash routes to the Flask app's own logout view. The
``session`` cookie is
Review Comment:
Yeah, the `session` cookie is kept. I ran some manual tests to reproduce the
scenario, but couldn't. Below are the steps for my testing, feel free to
correct me if that seems wrong.
Start Airflow with breeze
```bash
breeze start-airflow --backend postgres --auth-manager FabAuthManager
--create-all-roles
```
In a regular browser window, I signed in at `http://localhost:28080` as
`viewer` (let's say it's the user A), recorded the `session` cookie, and logged
out.
<img width="1536" height="633" alt="Screenshot from 2026-11-26 15-31-51"
src="https://github.com/user-attachments/assets/84b61e07-aca7-43db-8e00-2162b3e05a2c"
/>
In the same window, I signed in as `admin` (user B). The `session` in the
cookie changed.
<img width="1535" height="655" alt="Screenshot from 2026-11-26 15-32-22"
src="https://github.com/user-attachments/assets/d80e8191-e127-41d0-a1e3-cfbb7117a8de"
/>
In an Incognito window, I opened `http://localhost:28080/auth/login/`,
replaced the `session` cookie with A's recorded value and reloaded. It stayed
on the login page, so it seems A's copy doesn't sign in as B.
<img width="1533" height="546" alt="Screenshot from 2026-11-26 15-32-59"
src="https://github.com/user-attachments/assets/e9287946-bbd7-434b-a189-d490faa07562"
/>
If I understand correctly, B gets a new id because the security manager
rotates the session id on every successful sign-in with the database backend.
I think that's right that keeping the session after logout isn't ideal. The
latest commit overrides logout in our custom auth views to call
`session.clear()` after FAB's logout. The session row is now deleted and the
browser is told to delete the cookie.
I tested this live with database login only. LDAP, OAuth and remote-user
logins use the same override and are covered by unit tests. Remote user needed
a new `CustomAuthRemoteUserView`, since it used FAB's view directly before.
--
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]