Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

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

Aperta
#945 2 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
45/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Ferma
Stack tecnologico
javascript, node.js
Ambito
api, security

Direzione di ricerca

Inizia eseguendo la riproduzione minima in index.js con jsonwebtoken 9.0.2, quindi segui il punto di ingresso di sign per vedere come vengono gestite proprietà degli oggetti come valueOf, toString e proto. Il lavoro è completato quando la firma di questi oggetti non genera più l'errore validator.isValid is not a function; aggiungi o esegui un test di regressione che copra i casi segnalati.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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
Lingua principale
JavaScript
Stelle
18.2k
Fork
1.3k
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di auth0/node-jsonwebtoken

Tutte le issue di auth0/node-jsonwebtoken

Issue simili

Altre issue su JavaScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.