Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

`jwt.sign()` callback is executed twice for "The payload already has an "..." property" errors

Đang mở Phù hợp với người mới
#1,000 2 bình luận 1 reaction 0 người được giao Xem trên GitHub

@cobyfrombrooklyn-bot đang làm issue này rồi.

Từ ngày 25/2/2026.

  • #1002 của @maishivamhoo123 — đang mở
  • #1011 của @cobyfrombrooklyn-bot — đang mở
  • #1016 của @abhu85 — đang mở
  • #1017 của @abhu85 — đang mở

Đánh giá

Độ khó
2/5
Thời gian dự kiến
1-3 giờ
Mức phù hợp với người mới
84/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Ít trao đổi
Công nghệ
javascript, node.js
Lĩnh vực
authentication, security

Hướng nghiên cứu

Bắt đầu tại các dòng 217-225 trong sign.js, được xác định trong issue, và chạy bản tái hiện a.mjs với jsonwebtoken 9.0.2. Theo dõi hành vi của callback đối với xung đột issuer và xác minh rằng lỗi được báo cáo gây ra một lần gọi callback, không phải hai lần.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

Description

The callback to jwt.sign() is executed twice when there is an error Bad "options.issuer" option. The payload already has an "iss" property. I would expect the callback to only be executed once.

Reproduction
// a.mjs
import jwt from "jsonwebtoken";
jwt.sign(
  {
    iss: "bar",
    iat: 1757476476,
  },
  "secret",
  {
    algorithm: "HS256",
    issuer: "foo",
  },
  (err, asyncSigned) => {
    console.log("callback called:", asyncSigned ?? err?.message);
  },
);
$> npm init -y && npm add jsonwebtoken
$> node a.mjs
callback called: Bad "options.issuer" option. The payload already has an "iss" property.
callback called: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJiYXIiLCJpYXQiOjE3NTc0NzY0NzZ9.TkSecbZDocHnjwnuDhQRXNvRkxsERNGBkRc6P0wHlNY

Notice that "callback called" is printed twice, while I would expect it to be printed only once.

Environment

jsonwebtoken 9.0.2 on Darwin 24.6.0 arm64 arm

Other information

It looks like the error is here:

https://github.com/auth0/node-jsonwebtoken/blob/bc28861f1fa981ed9c009e29c044a19760a0b128/sign.js#L217-L225

Typically, return failure() throws which exits the forEach and the function. But when a callback is provided, it only returns from the forEach. The rest of the keys are checked and the rest of the function still runs.

Ngôn ngữ chính
JavaScript
Star
18.2k
Fork
1.3k
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của auth0/node-jsonwebtoken

Tất cả issue của auth0/node-jsonwebtoken

Issue tương tự

Thêm issue về JavaScript

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.