Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

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

オープン
#945 コメント 2 件 リアクション 0 件 担当者 0 名 GitHub で見る

@ej-shafran がすでに取り組んでいます。

2023年11月3日 から。

  • #946 @ej-shafran による — オープン

評価

難易度
3/5
見積もり時間
1〜2日
初心者へのやさしさ
45/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
停滞
技術スタック
javascript, node.js
領域
api, security

調査の方向性

まず jsonwebtoken 9.0.2 を使って最小限の index.js の再現を実行し、次に sign のエントリーポイントを追跡して、valueOf、toString、proto などのオブジェクトプロパティがどのように処理されるかを確認します。これらのオブジェクトに署名しても validator.isValid is not a function がスローされなくなり、報告されたケースをカバーする回帰テストを追加または実行できれば完了です。

索引モデルが issue の本文から書いたものです。

説明

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
主要言語
JavaScript
スター
18.2k
フォーク
1.3k
PR マージ指標
30日以内にマージされた PR はありません

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

auth0/node-jsonwebtoken のほかの issue

auth0/node-jsonwebtoken の issue をすべて見る

似ている issue

JavaScript の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。