`sign` crashes with `validator.isValid is not a function` for certain objects
評価
- 難易度
- 3/5
- 見積もり時間
- 1〜2日
- 初心者へのやさしさ
- 45/100
- issue の種類
- バグ
- 明瞭さ
- 明確に書かれている
- 活発さ
- 停滞
- 技術スタック
- javascript, node.js
調査の方向性
まず 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:
- 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
- 主要言語
- JavaScript
- スター
- 18.2k
- フォーク
- 1.3k
- PR マージ指標
- 30日以内にマージされた PR はありません
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートなし
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
auth0/node-jsonwebtoken のほかの issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
auth0/node-jsonwebtoken#1042 · コメント 1 件 ·
-
`jwt.sign()` callback is executed twice for "The payload already has an "..." property" errors対応中かも @cobyfrombrooklyn-bot が 222 日前に担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 84/100
auth0/node-jsonwebtoken#1000 · コメント 2 件 · リアクション 1 件 ·
-
難易度 4/5 3〜5日 初心者へのやさしさ 45/100
auth0/node-jsonwebtoken#1048 ·
-
verify() resolves a string secret by attempting createPublicKey() first, costing 4x-52x on the HS* path対応中かも @Hashim1999164 が 16 日前に担当しました。 オープン
難易度 4/5 3〜5日 初心者へのやさしさ 65/100
auth0/node-jsonwebtoken#1046 ·
-
難易度 5/5 1週間以上 初心者へのやさしさ 10/100
auth0/node-jsonwebtoken#1034 ·
auth0/node-jsonwebtoken の issue をすべて見る
似ている issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
invoiceninja/invoiceninja#13320 ·
メンテナーはふだん 1 日以内に返信
-
NoCode.vue, Task.vue: replace explicit `any` with real types対応中かも @prayas-bit が今日担当しました。 オープンarea/frontend good first issue kind/cooldown
難易度 2/5 1〜3時間 初心者へのやさしさ 67/100
kestra-io/kestra#20347 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 70/100
ubuntu/gnome-shell-extension-appindicator#676 · コメント 1 件 ·