-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
"decode" function is not used for v9 in strict mode #866
Comments
We are also hitting this |
We are hitting the following issue when we test and mock our code with jest.
Results into the following error:
Which has the same root problem, meaning that the decode function now is read only due to it being defined in the You can find the source code here: https://github.com/auth0/node-jsonwebtoken/blob/v9.0.0/index.js Proposed solution:Add |
It looks like |
It's still there -> https://github.com/auth0/node-jsonwebtoken/blob/v9.0.0/decode.js #741 was never merged. We've encountered this too when upgrading to mitigate GHSA-8cf7-32gw-wr33 as we use |
Also running into this issue when using jest. Trying to remediate the same vuln as well @psyvision |
It seems this is the root cause: 15a1bc4. We are also struggling with const jwt = require('jsonwebtoken');
sinon.stub(jwt, 'decode')
TypeError: Cannot redefine property: decode |
I am running into the same issue when trying to stub decode using sinon after upgrading from 8.5.1 to v9.0.0 to resolve the same vulnerability.
But I now receive: |
As a workaround until it gets fixed, instead of
you can use
|
Using Error: |
We have legitimate use-cases for This is particularly pertinent since the 8->9 version bump mitigates a number of vulnerabilities in the package (meaning some consumers are somewhat forced to upgrade ASAP). |
Workaround: To continue using import jwt from 'jsonwebtoken';
//...
jest.mock('jsonwebtoken');
//...
jest.spyOn(jwt, 'decode')
//... |
I think it should once revert back to defineProperty (delete settings) due to run Lines 9 to 12 in e1fa9dc
|
A better way of making this work in jest without mocking the whole lib is as follows: import * as jwt from 'jsonwebtoken';
jest.mock('jsonwebtoken', () => {
return {
__esModule: true,
...jest.requireActual('jsonwebtoken'),
decode: require('jsonwebtoken/decode')
};
}); that way you're not mocking every function as suggested in #866 (comment), and still allows you stub decode |
This issue already done to fix. |
Description
We upgraded from v8.5.1 to v9.0.0, but happend TypeError that "decode" is not a function in strict mode.
I think this issue cause is below change, define non-enum in this function.
#741
This change point is not included in Migration note, so we did not notice.
I'm sure that many other users also have used this function.
How about mentioning this matter in the Migration note and Readme?
Reproductiona
In strict mode, use "decode" function.
Environment
jsonwebtoken : ^9.0.0
node : v16.16.0 (use strict mode)
Typescript : ^4.7.4
OS : windows10
The text was updated successfully, but these errors were encountered: