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

Constantly changing Session IDs. #71

Closed
BurntNail opened this issue Jun 6, 2023 · 2 comments
Closed

Constantly changing Session IDs. #71

BurntNail opened this issue Jun 6, 2023 · 2 comments

Comments

@BurntNail
Copy link

I'm pretty sure this is the right place to put this, but if not then feel free to tell me.

Like the examples, I randomly generate a secret every time my server restarts:

let secret = {
        let mut rng = thread_rng();
        let mut v = Vec::with_capacity(64);
        v.append(&mut rng.gen::<[u8; 32]>().to_vec()); //can't get rand to do a [u8; 64] so fun times ensue
        v.append(&mut rng.gen::<[u8; 32]>().to_vec());
        v
    };
    ```
    
    However, because my server restarts often, that key changes often and logs everybody out when I use a `MemoryStore`. 
    I'm now using a persistent postgres-based store, but every time I restart, the secret regenerates and the auth layer picks a new ID for each user and everyone is logged out.
    
    Is there an intended way to fix this - storing the secret in the db doesn't seem intuitive, so I was wondering if I was doing something wrong.
    
    My Postgres solution is almost identical to [aysnc-sqlx-session](https://lib.rs/crates/async-sqlx-session)'s postgres one.

Thanks!
@maxcountryman
Copy link
Owner

Most real applications would be given a secret via an environment variable or similar (how you generate this is up to you, but it’s paramount to your app’s security it be done so with care). Generally, you would not create a new secret each time you run your app. These examples do that only to illustrate the basic principles but are not intended to model a more complex app.

@BurntNail
Copy link
Author

Perfect - thanks for your speedy answer!

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

No branches or pull requests

2 participants