Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Harden logout #4359

Merged
merged 1 commit into from
Dec 26, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 19 additions & 10 deletions backend/app/logins.py
Original file line number Diff line number Diff line change
Expand Up @@ -966,18 +966,27 @@ def do_refresh_dev_flatpaks(
@router.post("/logout", tags=["auth"])
def do_logout(request: Request, login: LoginStatusDep):
"""
Clear the login state. This will discard tokens which access socials,
Clear the login state. This will discard tokens which access socials,
and will clear the session cookie so that the user is not logged in.
"""
if login.state == LoginState.LOGGED_OUT:
return {}

# Clear the login ID
del request.session["user-id"]
if login.state.logging_in():
# Also clear any pending login-flow from the session
del request.session["active-login-flow"]
del request.session["active-login-flow-intermediate"]
try:
if login.state == LoginState.LOGGED_OUT:
return {}

# Clear the login ID
if "user-id" in request.session:
del request.session["user-id"]

if login.state.logging_in():
# Also clear any pending login-flow from the session
if "active-login-flow" in request.session:
del request.session["active-login-flow"]
if "active-login-flow-intermediate" in request.session:
del request.session["active-login-flow-intermediate"]

except KeyError as e:
raise HTTPException(status_code=500, detail=f"Session error: {str(e)}")

return {}


Expand Down
Loading