Created
August 5, 2024 14:07
-
-
Save nsdevaraj/f5655c9626ad1a224466d0480aeb2b20 to your computer and use it in GitHub Desktop.
Prevention of the Use of Insecure Session IDs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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