Hacktoberfest 2026: the issues maintainers tagged for October, open and beginner-friendly. Browse Hacktoberfest issues

`sign` crashes with `validator.isValid is not a function` for certain objects

Open
#945 2 comments 0 reactions 0 assignees View on GitHub

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
Domain
api, security

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:

  1. Create a new Node project, installing jsonwebtoken
  2. In a file index.js, add:
const { sign } = require("jsonwebtoken");

console.log(sign({ valueOf: 0 }, "anysecret");
  1. Run node index.js
  2. See error

To reproduce the fast-check test that shows the different ways this error occurs:

  1. Create a new Node project, installing jest, jsonwebtoken, and fast-check.
  2. 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 });
  });
});
  1. Run npx jest
  2. See that the test does not pass for certain values, and a TypeError: validator.isValid is not a function is 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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from auth0/node-jsonwebtoken

All issues in auth0/node-jsonwebtoken

Similar issues

More JavaScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.