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

Revoke session on logout. #607

Merged
merged 10 commits into from
Nov 21, 2023

Conversation

danielballan
Copy link
Member

Closes #602

In main, logging out with the Python client discards the relevant tokens, but it leaves the session open. Anyone holding a copy of the refresh token (somehow) can refresh the session and continue to use it, as long as they do so within the refresh token lifetime (days or weeks).

Now, logging out first revokes the session, such that it can not be refreshed again, and then discards the tokens. A new unit test verifies that the old refresh token cannot be reused after logout.

Copy link
Contributor

@dylanmcreynolds dylanmcreynolds left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just one little picky bit...

@padraic-shafer
Copy link
Contributor

Would it make sense to return 409 for this case also? Session might exist, but it belongs to a different user.

if principal.uuid != session.principal.uuid:
# TODO Add a scope for doing this for other users.
raise HTTPException(
404,
detail="Sessions does not exist or requester has insufficient permissions",
)

@danielballan
Copy link
Member Author

I think 404 is right in this case. The user is providing an ID, and this follows the principle, "If this isn't yours, you're now allowed to know whether or not it exists."

@padraic-shafer
Copy link
Contributor

I think 404 is right in this case. The user is providing an ID, and this follows the principle, "If this isn't yours, you're now allowed to know whether or not it exists."

Oh, right. That make sense.

Copy link
Contributor

@padraic-shafer padraic-shafer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks great. A couple of minor questions in the review.

if session is None:
raise HTTPException(409, detail=f"No session {session_id}")
session.revoked = True
db.add(session)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In SQLAlchemy, is Session.add() an "upsert" operation -- it will perform INSERT or UPDATE as needed?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(As usual with SQLAlchemy, the documentation is sprawling and specific things can be hard to find.)

@@ -1095,12 +1116,13 @@ async def whoami(
)


@base_authentication_router.post("/logout")
@base_authentication_router.post("/logout", include_in_schema=False)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This might be a moot point because it's already removed for the schema, but wanted to point out here the deprecated keyword as a possibility.

Suggested change
@base_authentication_router.post("/logout", include_in_schema=False)
@base_authentication_router.post("/logout", include_in_schema=False, deprecated=True)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moot but good to know about!

@danielballan danielballan merged commit 204676b into bluesky:main Nov 21, 2023
8 checks passed
@danielballan danielballan deleted the revoke-session-on-logout branch November 26, 2023 18:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Logout should revoke user's session?
3 participants