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

figure out sessions #29

Closed
komuw opened this issue Jun 14, 2022 · 8 comments · Fixed by #154
Closed

figure out sessions #29

komuw opened this issue Jun 14, 2022 · 8 comments · Fixed by #154

Comments

@komuw
Copy link
Owner Author

komuw commented Jun 19, 2022

@komuw
Copy link
Owner Author

komuw commented Jun 19, 2022

If we decide to use memory store, we'll run into issue of sticky/non-sticky sessions

@komuw
Copy link
Owner Author

komuw commented Jun 23, 2022

maybe we should just stay out of the session business; it's up to app developers to figure that out with their databases.

@komuw
Copy link
Owner Author

komuw commented Jul 2, 2022

@komuw
Copy link
Owner Author

komuw commented Sep 29, 2022

Assume we're trying to minimize the fraction of requests that have to hit the database. 
Mainstream web application frameworks tend to already have features that help with this.

Give them a bag of attributes and get back a tamper-proof (optionally encrypted) string, 
using HMAC-SHA2 and AES-CBC. Put the string in a cookie. 
The server only remembers a root secret, and can pull user data out of the cookie instead of the database. 
This is how Rails sessions work.

You can’t generally use general-purpose user sessions for API tokens. 
But you can use the same features to build API tokens. 
Share the root secret among multiple services - maybe that's fine - 
and microservices don't have to rely on a central service.

These tokens are relatively simple, and can be stateless. What's the catch? 
You’re effectively using tokens as a database cache, and cache consistency is frustrating.
You’ve lost the simplest form of token revocation. 
You're not validating tokens against the database, 
so now you have to come up with another way to tell if they’ve been revoked. 
A pattern I’ve seen a bunch here, and one that I kind of like, is to “version” the users. 
Stick a token version in the user table, have tokens bear the current version. 
To revoke, bump the version in the database; outstanding tokens are now invalid. 
Of course, you need to keep state to do that, but the state is very cheap; 
a Redis cache of user versions, falling back to the database, does the trick.

@komuw
Copy link
Owner Author

komuw commented Sep 29, 2022

JWT fails miserably at invalidation, or How do you log out the user?
The answer is, you don't. You can't. 
You (the server) can tell the user's client software to forget their JWT and 
hope they'll do it, but you can never be sure.
  • from https://apibakery.com/blog/tech/no-jwt/
    Normal sessions that are not backed by a db and rely solely on cookies also have the same issue.
    You can delete the cookie, but a malicious client can decide not to honour the delition.

To solve this problem, save this in the cookie.

{
 ... stuff
 expires: timestamp   // check it is not expired.
request_ip: some-ip  // check they are using same IP as what was set before??
}

Of course, all this is authenticated and encrypted.
However, what if you set the timestamp to 2weeks, and then you decide you want to logout the user today(maybe to fix a security issue)?

@komuw
Copy link
Owner Author

komuw commented Oct 3, 2022

komuw added a commit that referenced this issue Oct 17, 2022
What:
- add support for http sessions

Why:
- Fixes: #29
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 a pull request may close this issue.

1 participant