Recently I bumped atlassian-connect-express
to 7.0.1
and atlassian-jwt
to 2.0.0
.
Now I see this message “Algorithm from the header “HS256” does not match” for each post install hook.
I copied samples from https://bitbucket.org/atlassian/atlassian-jwt-js/ and created a minimal project to test it:
{
"dependencies": {
"atlassian-jwt": "^2.0.0",
"esm": "^3.2.25",
"moment": "^2.29.1"
}
}
import * as jwt from 'atlassian-jwt';
import moment from 'moment';
const now = moment().utc();
const req = jwt.fromMethodAndUrl('GET', '/rest/resource/you/want');
const tokenData = {
"iss": 'issuer-val',
"iat": now.unix(), // The time the token is generated
"exp": now.add(3, 'minutes').unix(), // Token expiry time (recommend 3 minutes after issuing)
"qsh": jwt.createQueryStringHash(req) // [Query String Hash](https://developer.atlassian.com/cloud/jira/platform/understanding-jwt/#a-name-qsh-a-creating-a-query-string-hash)
};
const secret = 'xxx';
const token = jwt.encodeSymmetric(tokenData, secret);
console.log(token);
const decoded = jwt.decodeSymmetric(token, secret);
console.log(decoded); //=> { foo: 'bar' }
const decodedUnverifing = jwt.decodeSymmetric(token, null, true);
console.log(decodedUnverifing); //=> { foo: 'bar' }
now:
$ node -r esm index.js
eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.[CUT]
/private/tmp/node_modules/atlassian-jwt/dist/lib/jwt.js:1
Error: Algorithm from the header "HS256" does not match
at validateSymmetricAlgorithm (/private/tmp/node_modules/atlassian-jwt/dist/lib/jwt.js:279:15)
at Proxy.jwt_decode_symmetric (/private/tmp/node_modules/atlassian-jwt/dist/lib/jwt.js:177:5)
at Object.<anonymous> (/private/tmp/index.js:20:21)
at Generator.next (<anonymous>)
This is an exact the same error message I have in logs while trying to use jwt.decodeSymmetric
.
Additionally, the documentation suggest, that decodeSymmetric
does not require signedAlgorithm string as a parameter. Whereas ./dist/lib/jwt.d.ts:73
shows this definition:
export declare const decodeSymmetric: (token: string, key: string, signedAlgorithm: Algorithm, noVerify?: boolean | undefined) => any;
This seems to be a bug in the newly upgraded library. But I can’t create an issue there.
Anyone experienced else that?