ReDoS in verify() when audience option is a RegExp: attacker-controlled aud claim → catastrophic backtracking
Đánh giá
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức phù hợp với người mới
- 48/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Khá rõ ràng
- Mức độ hoạt động
- Ít trao đổi
- Công nghệ
- javascript, node.js
- Lĩnh vực
- authentication, backend, security
Hướng nghiên cứu
Bắt đầu trong verify.js, quanh vòng lặp kiểm tra audience, rồi chạy bản tái hiện được cung cấp và property của fast-check để quan sát độ trễ. Xem lại tài liệu liên quan đến tùy chọn audience trong README và verify.d.ts. Hoàn tất khi đường dẫn audience RegExp có hành vi bị giới hạn và được ghi chép rõ ràng đối với các claims do kẻ tấn công kiểm soát, đồng thời kịch bản hồi quy được bao phủ.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Description
jwt.verify(token, secret, { audience: regex }) passes the attacker-controlled aud claim of the JWT directly into RegExp.test(). If the application uses a regex with vulnerable patterns (nested quantifiers, ambiguous alternation), the verification call hangs for seconds-to-minutes per request — classic ReDoS via the audience claim.
Reproduction (jsonwebtoken 9.0.2)
const jwt = require('jsonwebtoken');
const SECRET = 'test-secret';
// Application uses RegExp for audience matching (documented feature)
const audRegex = /(a+)+$/;
// Attacker crafts a token with a malicious `aud` claim and signs it
// (in real scenarios the attacker controls some path that signs user-supplied audiences)
const token = jwt.sign({ aud: 'a'.repeat(25) + '!' }, SECRET);
const t0 = Date.now();
try { jwt.verify(token, SECRET, { audience: audRegex }); } catch (_) {}
console.log('verify took', Date.now() - t0, 'ms');
// Output: ~3000ms with 25 a's; ~12s with 27; ~93s with 30.
Property that fails
import fc from "fast-check";
import jwt from "jsonwebtoken";
const SECRET = 's';
const audRegex = /(a+)+$/;
fc.assert(fc.property(
fc.integer({min: 5, max: 30}),
(n) => {
const tok = jwt.sign({ aud: 'a'.repeat(n) + '!' }, SECRET);
const t0 = Date.now();
try { jwt.verify(tok, SECRET, { audience: audRegex }); } catch (_) {}
return Date.now() - t0 < 500; // < 500 ms for any small input
}
));
// Shrinks to n=22 ~ 25
Threat model
Many real applications use RegExp for audience matching (multi-tenant subdomains: /^https:\/\/[^.]+\.example\.com$/, wildcard tenants, microservice families). Where the aud claim originates from anything other than a hard-coded list — for example, a federated token-exchange endpoint where one party signs a token containing the next service's name — an attacker who controls that audience string can supply a payload that exhausts a CPU core per call.
Concrete impact: a single ~80-byte JWT request blocks an event-loop thread for ≥10 seconds. A few requests/second saturate the server.
This is the same class as CVE-2024-21534 (jsonwebtoken older), CVE-2024-21501 (sanitize-html), CVE-2026-35041 (fast-jwt's identical issue with allowedAud).
Root cause
verify.js, audience-check loop (around lines 194-207):
const match = target.some((targetAudience) => {
return audiences.some((audience) => {
return audience instanceof RegExp
? audience.test(targetAudience) // <- no length cap, no timeout
: audience === targetAudience;
});
});
The library:
- Doesn't limit the length of
audbefore RegExp.test. - Doesn't surface the ReDoS risk in
verify's docs for the RegExp-audience path. - Trusts the application to have audited its audience regex — but the attacker, not the application, supplies the input to that regex.
Suggested fix
In verify.js, before calling audience.test(targetAudience), enforce a configurable max-length on targetAudience (e.g. 256 chars by default). Throw JsonWebTokenError('audience claim exceeds length limit') on overflow.
Additionally, document the ReDoS hazard for the regex-audience path in README and verify.d.ts, and recommend re2 or static-regex-safety checking for application-supplied audience regexes.
Environment
- jsonwebtoken: 9.0.2 (latest on npm)
- Node: 20+
- 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
- Không có Dockerfile hay tệp Docker Compose
- Không có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- 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.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của auth0/node-jsonwebtoken
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
auth0/node-jsonwebtoken#1042 · 1 bình luận ·
-
`jwt.sign()` callback is executed twice for "The payload already has an "..." property" errorsCó thể đã có người làm @cobyfrombrooklyn-bot đã nhận 228 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 84/100
auth0/node-jsonwebtoken#1000 · 2 bình luận · 1 reaction ·
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 45/100
auth0/node-jsonwebtoken#1048 ·
-
verify() resolves a string secret by attempting createPublicKey() first, costing 4x-52x on the HS* pathCó thể đã có người làm @Hashim1999164 đã nhận 23 ngày trước. Đang mở
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 65/100
auth0/node-jsonwebtoken#1046 ·
-
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 10/100
auth0/node-jsonwebtoken#1034 ·
Tất cả issue của auth0/node-jsonwebtoken
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
dusk-network/exu#17 ·
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 88/100
jspreadsheet/ce#1809 ·
-
documentation
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 91/100
githubnext/gh-aw-workshop#4458 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Add: CartoonitoĐang mởcheck:failed feeds:add
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 63/100
iptv-org/database#37390 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 9 ngày
-
bug: directory index route root priority is overwritten when wildcard is falseCó thể đã có người làm @TalhaHunter101 đã nhận hôm nay. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 84/100
fastify/fastify-static#617 ·