Skip to content

Commit 63263a2

Browse files
committed
do not mutate options in jwt.verify, closes #227
1 parent e11d505 commit 63263a2

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

test/verify.tests.js

+21
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,27 @@ describe('verify', function() {
4646
});
4747
});
4848

49+
it('should not mutate options', function (done) {
50+
var header = { alg: 'none' };
51+
52+
var payload = { iat: Math.floor(Date.now() / 1000 ) };
53+
54+
var options = {typ: 'JWT'};
55+
56+
var signed = jws.sign({
57+
header: header,
58+
payload: payload,
59+
secret: priv,
60+
encoding: 'utf8'
61+
});
62+
63+
jwt.verify(signed, null, options, function(err) {
64+
assert.isNull(err);
65+
assert.deepEqual(Object.keys(options).length, 1);
66+
done();
67+
});
68+
});
69+
4970
describe('expiration', function () {
5071
// { foo: 'bar', iat: 1437018582, exp: 1437018583 }
5172
var token = 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJmb28iOiJiYXIiLCJpYXQiOjE0MzcwMTg1ODIsImV4cCI6MTQzNzAxODU4M30.NmMv7sXjM1dW0eALNXud8LoXknZ0mH14GtnFclwJv0s';

verify.js

+3
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ var TokenExpiredError = require('./lib/TokenExpiredError');
44
var decode = require('./decode');
55
var jws = require('jws');
66
var ms = require('ms');
7+
var xtend = require('xtend');
78

89
module.exports = function (jwtString, secretOrPublicKey, options, callback) {
910
if ((typeof options === 'function') && !callback) {
@@ -15,6 +16,8 @@ module.exports = function (jwtString, secretOrPublicKey, options, callback) {
1516
options = {};
1617
}
1718

19+
//clone this object since we are going to mutate it.
20+
options = xtend(options);
1821
var done;
1922

2023
if (callback) {

0 commit comments

Comments
 (0)