`sign` crashes with `validator.isValid is not a function` for certain objects
Nobody has claimed this yet.
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 45/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Stale
- Tech stack
- javascript, node.js
Research direction
Start by running the minimal index.js reproduction with jsonwebtoken 9.0.2, then trace the sign entry point to see how object properties such as valueOf, toString, and proto are handled. Done means signing these objects no longer throws validator.isValid is not a function; add or run a regression test covering the reported cases.
Written by the indexing model from the issue text.
Description
Description
Provide a clear and concise description of the issue, including what you expected to happen.
I noticed that every once in a blue moon, my tests for something that calls sign would fail with validator.isValid is not a function. After debugging, I managed to narrow it down. I'm using fast-check for tests, and their fc.object function sometimes generates objects that have keys like "__proto__", "valueOf", or "toString". Whenever an object like this is passed into sign, the validator.isValid error appears.
Reproduction
Most minimal reproduction I could create:
- Create a new Node project, installing
jsonwebtoken - In a file
index.js, add:
const { sign } = require("jsonwebtoken");
console.log(sign({ valueOf: 0 }, "anysecret");
- Run
node index.js - See error
To reproduce the fast-check test that shows the different ways this error occurs:
- Create a new Node project, installing
jest,jsonwebtoken, andfast-check. - In a file
jwt.test.js, add:
const fc = require("fast-check");
const { sign } = require("jsonwebtoken");
describe("jwt.sign", () => {
it("should sign any object", () => {
const prop = fc.property(
fc.object(),
fc.base64String({ minLength: 1 }),
(obj, secret) => {
const result = sign(obj, secret);
return !!result;
},
);
fc.assert(prop, { numRuns: 1000, verbose: true });
});
});
- Run
npx jest - See that the test does not pass for certain values, and a
TypeError: validator.isValid is not a functionis thrown
Environment
Please provide the following:
- Version of this library used:
^9.0.2 - Version of the platform or framework used, if applicable: N/A
- Other relevant versions (language, server software, OS, browser): both JS and TS, on Linux, using Node
- Other modules/plugins/libraries that might be involved:
fast-check
- Dominant language
- JavaScript
- Stars
- 18.2k
- Forks
- 1.3k
- PR merge metrics
- No merged PRs in 30d
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from auth0/node-jsonwebtoken
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
auth0/node-jsonwebtoken#1042 · 1 comment ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
auth0/node-jsonwebtoken#1000 · 2 comments · 1 reaction ·
-
Difficulty 4/5 3-5 days Newbie friendliness 65/100
auth0/node-jsonwebtoken#1046 ·
-
Difficulty 5/5 Over a week Newbie friendliness 10/100
auth0/node-jsonwebtoken#1034 ·
-
Difficulty 3/5 1-2 days Newbie friendliness 48/100
auth0/node-jsonwebtoken#1032 ·
All issues in auth0/node-jsonwebtoken
Similar issues
-
Bug
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
Automattic/safe-publish#594 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
dream-num/dsh-univer-office#104 ·
-
comp/dashboard invalid P3
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
NousResearch/hermes-agent#121143 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
avniproject/avni-webapp#1811 ·
-
area/auroraboot area/webui bug
Difficulty 2/5 1-3 hours Newbie friendliness 75/100