fix security bug. JWT with alg none should fail if secretOrPulblicKey is passed

This commit is contained in:
Matias Woloski
2014-07-14 16:18:05 -03:00
parent 708c4d824a
commit dfddaa4bf5
2 changed files with 17 additions and 0 deletions
+7
View File
@@ -34,6 +34,13 @@ module.exports.verify = function(jwtString, secretOrPublicKey, options, callback
if ((typeof options === 'function') && !callback) callback = options;
if (!options) options = {};
var parts = jwtString.split('.');
if (parts.length < 3)
return callback(new Error('jwt malformed'));
if (parts[2].trim() === '' && secretOrPublicKey)
return callback(new Error('jwt signature is required'));
var valid;
try {
valid = jws.verify(jwtString, secretOrPublicKey);
+10
View File
@@ -31,5 +31,15 @@ describe('HS256', function() {
});
});
it('should throw with secret and token not signed', function(done) {
var signed = jwt.sign({ foo: 'bar' }, secret, { algorithm: 'none' });
var unsigned = signed.split('.')[0] + '.' + signed.split('.')[1] + '.';
jwt.verify(unsigned, 'secret', function(err, decoded) {
assert.isUndefined(decoded);
assert.isNotNull(err);
done();
});
});
});
});