Skip to content

Commit c280e82

Browse files
committed
Fixes #251: "none" alg results in verified signature.
This is a hotfix and should be removed in the future once libraries are updated.
1 parent e390cea commit c280e82

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

js/jwt.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,18 @@ window.verify = function (algorithm, value, key, isSecretBase64Encoded) {
101101

102102
var result = '', error = null;
103103

104+
// HOTFIX: issue #251, 'alg: none' results in valid signature. It should
105+
// always be invalid. This is fixed in KJUR.jws.JWS in later versions.
106+
// When we update libraries to the latest versions, we can remove this.
107+
try {
108+
var header = JSON.parse(window.decode(value.split('.')[0]).result);
109+
if(header.alg === 'none') {
110+
return { result: false, error: null };
111+
}
112+
} catch(e) {
113+
return { result: false, error: e };
114+
}
115+
104116
if (algorithm === 'HS256'){
105117
if (isSecretBase64Encoded) {
106118
try {

0 commit comments

Comments
 (0)