Skip to content

Commit 4537773

Browse files
committed
feat: enforce secret requirement for session creation
1 parent bbeca94 commit 4537773

File tree

2 files changed

+5
-17
lines changed

2 files changed

+5
-17
lines changed

index.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -143,8 +143,8 @@ function session(options) {
143143
secret = [secret];
144144
}
145145

146-
if (!secret) {
147-
deprecate('req.secret; provide secret option');
146+
if (secret === undefined) {
147+
throw new Error('secret is required for sessions');
148148
}
149149

150150
// notify user that this store is not
@@ -207,7 +207,7 @@ function session(options) {
207207

208208
// backwards compatibility for signed cookies
209209
// req.secret is passed from the cookie parser middleware
210-
var secrets = secret || [req.secret];
210+
var secrets = secret;
211211

212212
var originalHash;
213213
var originalId;

test/session.js

+2-14
Original file line numberDiff line numberDiff line change
@@ -35,20 +35,8 @@ describe('session()', function(){
3535
.expect(200, done)
3636
})
3737

38-
it('should error without secret', function(done){
39-
request(createServer({ secret: undefined }))
40-
.get('/')
41-
.expect(500, /secret.*required/, done)
42-
})
43-
44-
it('should get secret from req.secret', function(done){
45-
function setup (req) {
46-
req.secret = 'keyboard cat'
47-
}
48-
49-
request(createServer(setup, { secret: undefined }))
50-
.get('/')
51-
.expect(200, '', done)
38+
it('should reject without secret', function(){
39+
assert.throws(session.bind(null, { secret: undefined }), /secret.*required/)
5240
})
5341

5442
it('should create a new session', function (done) {

0 commit comments

Comments
 (0)