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

Random Session ID? #515

Open
saiteja-madha opened this issue May 2, 2024 · 5 comments
Open

Random Session ID? #515

saiteja-madha opened this issue May 2, 2024 · 5 comments
Labels
help wanted Extra attention is needed

Comments

@saiteja-madha
Copy link
Owner

Simplify the setup of SESSION_PASSWORD by automating random secret generation. This eliminates user confusion and reduces security risks.

@saiteja-madha saiteja-madha added the help wanted Extra attention is needed label May 2, 2024
@saiteja-madha
Copy link
Owner Author

Since this codebase is being used by beginners, I think we can create a script to help users fill in the .env

@imnaiyar
Copy link

imnaiyar commented May 2, 2024

How about we use uuid for that?

@imnaiyar
Copy link

imnaiyar commented May 2, 2024

Something like this would be sufficient i think

const { v4 } = require('uuid')
app.use(
      session({
        secret: v4(),
        cookie: { maxAge: 336 * 60 * 60 * 1000 },
        ...// other options
    )

@ItzDerock
Copy link

i dont think we need to introduce a whole dependency for this, just use node:crypto,

import { randomBytes } from "node:crypto";

session({ 
  secret: process.env.SESSION_PASSWORD ?? randomBytes(32).toString("hex"),
  ...
});

downside to this and the uuid approach is that upon reboot, the session secret will be different, thus invalidating all existing sessions. Prefilling the .env works fine for all non-docker users.

alternatively, we can just update the readme to include instructions on how to generate a random secret, such as running head /dev/urandom | tr -dc A-Za-z0-9 | head -c32 or link some website.

@saiteja-madha
Copy link
Owner Author

But won’t generating a random one and not the value be a problem?

I believe the session won’t be persisted after restart

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

3 participants