-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Verification with an asymmetric key of a token signed with a symmetri…
…c key There is a vulnerability in this module when the verification part is expecting a token digitally signed with an asymetric key (RS/ES family) of algorithms but instead the attacker send a token digitally signed with a symmetric algorithm (HS* family). The issue is because this library has the very same signature to verify both type of tokens (parameter: `secretOrPublicKey`). This change adds a new parameter to the verify called `algorithms`. This can be used to specify a list of supported algorithms, but the default value depends on the secret used: if the secretOrPublicKey contains the string `BEGIN CERTIFICATE` the default is `[ 'RS256','RS384','RS512','ES256','ES384','ES512' ]` otherwise is `[ 'HS256','HS384','HS512' ]`.
- Loading branch information
1 parent
f9f3c34
commit 1bb584b
Showing
3 changed files
with
33 additions
and
1 deletion.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,7 @@ | |
"it": true, | ||
"require": true, | ||
"atob": false, | ||
"escape": true | ||
"escape": true, | ||
"before": true | ||
} | ||
} |
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
var fs = require('fs'); | ||
var path = require('path'); | ||
var jwt = require('../index'); | ||
var JsonWebTokenError = require('../lib/JsonWebTokenError'); | ||
var expect = require('chai').expect; | ||
|
||
|
||
var pub = fs.readFileSync(path.join(__dirname, 'pub.pem'), 'utf8'); | ||
// priv is never used | ||
// var priv = fs.readFileSync(path.join(__dirname, 'priv.pem')); | ||
|
||
var TOKEN = 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJmb28iOiJiYXIiLCJpYXQiOjE0MjY1NDY5MTl9.ETgkTn8BaxIX4YqvUWVFPmum3moNZ7oARZtSBXb_vP4'; | ||
|
||
describe('signing with pub key as symmetric', function () { | ||
it('should not verify', function () { | ||
expect(function () { | ||
jwt.verify(TOKEN, pub); | ||
}).to.throw(JsonWebTokenError, /invalid signature/); | ||
}); | ||
}); |