Skip to content

Commit e1cf1e4

Browse files
committed
Better OAuth2 random state string
1 parent a302a12 commit e1cf1e4

2 files changed

Lines changed: 3 additions & 2 deletions

File tree

lib/config.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
'use strict'
22

3+
var crypto = require('crypto')
34
var dcopy = require('deep-copy')
45

56
// oauth configuration
@@ -48,7 +49,7 @@ exports.state = function (provider) {
4849
state = provider.state.toString()
4950
}
5051
else if (typeof provider.state == 'boolean' && provider.state) {
51-
state = (Math.floor(Math.random() * 999999) + 1).toString()
52+
state = crypto.randomBytes(10).toString('hex')
5253
}
5354
return state
5455
}

test/config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ describe('config', function () {
7878
it('boolean true', function () {
7979
var provider = {state:true}
8080
, state = config.state(provider)
81-
state.should.match(/\d+/)
81+
state.should.match(/^\w+$/)
8282
state.should.be.type('string')
8383
})
8484
it('boolean false', function () {

0 commit comments

Comments
 (0)