`sign` crashes with `validator.isValid is not a function` for certain objects
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
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:
- 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
- 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
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di auth0/node-jsonwebtoken
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
auth0/node-jsonwebtoken#1042 · 1 commento ·
-
`jwt.sign()` callback is executed twice for "The payload already has an "..." property" errors Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 84/100
auth0/node-jsonwebtoken#1000 · 2 commenti · 1 reazione ·
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 65/100
auth0/node-jsonwebtoken#1046 ·
-
Difficoltà 5/5 Più di una settimana Idoneità per principianti 10/100
auth0/node-jsonwebtoken#1034 ·
-
Difficoltà 3/5 1-2 giorni Idoneità per principianti 48/100
auth0/node-jsonwebtoken#1032 ·
Tutte le issue di auth0/node-jsonwebtoken
Issue simili
-
bug confirmed issue
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
open-webui/open-webui#30750 · 1 commento ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
-
Mend: dependency security vulnerability untriaged
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100