sublinks / sublinks-api

MIT License
74 stars 18 forks source link

Create logout API route and delete tokens #406

Open kgilles opened 5 months ago

kgilles commented 5 months ago

Today there's no way to invalidate an auth token via the API. Which means when a user logs out via the UI, the frontend can't tell the backend to remove the active token connected to the user. This token can still be used to make API requests.

This isn't necessarily a big security threat as long as the frontend promptly removes all references to this token, and the token itself is given a very short lifetime. However, I want to share some reasons in favor of deleting these tokens in the backend on logout.

  1. I did say this isn't a big security threat. However, it could still give malicious actors access to more users' active tokens in case database access is gained. Compared to if we would remove these tokens on user logout.
  2. Keeping the tokens alive even after the user has logged out means we can't trust thevalidate_auth* API route response(according to my personal expectations that the it return falsy after the user has logged out).
  3. I believe it's an expectation from the user that there be no way to take actions as the user after they've logged out.

* I'm developing restricted frontend routes which requires the user to be logged in, such as the "create a post"-page. I'd like to use the validate_auth route to know whether the user is logged in or not. And direct the user to the login page if I receive a non-OK response.

Open to discuss.

Pdzly commented 4 months ago

Yeah the Sublinks Native API will support that.

Pdzly commented 2 months ago

@kgilles Added 2 ( 3 ) possibilities.

  1. /api/v1/person/logout ( is a straight up alias for /api/v1/session/invalidate )
  2. /api/1v/session/invalidate
  3. Get all sessions with /api/v1/session/person => get the "key" ( or in this case the id ) related to the logged in token and then you can invalidate ( or delete it ) with DELETE /api/v1/person/invalidate/{sessionkey} or DELETE /api/v1/data/{sessionkey}
Pdzly commented 2 months ago

( currently in the #359 branch )