Skip to content

Instantly share code, notes, and snippets.

@nsdevaraj
Created August 5, 2024 14:07
Show Gist options
  • Save nsdevaraj/f5655c9626ad1a224466d0480aeb2b20 to your computer and use it in GitHub Desktop.
Save nsdevaraj/f5655c9626ad1a224466d0480aeb2b20 to your computer and use it in GitHub Desktop.
Prevention of the Use of Insecure Session IDs
import express from 'express';
import session from 'express-session';
import crypto from 'crypto';
const app = express();
app.use(session({
secret: 'your-secret-key',
resave: false,
saveUninitialized: true,
cookie: { secure: true, httpOnly: true },
genid: (req) => {
return crypto.randomBytes(16).toString('hex'); // returns a 32-character hexadecimal string
}
}));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment