Sample audits · Open-source projects, first eight

auth0/node-jsonwebtoken

JSON Web Token signing and verification for Node.js.

Summary card for this audit: 11 findings after review, 0 High, 0 Medium, 7 Low, 4 Info
Auditedauth0/node-jsonwebtoken at commit b924272f29192e12926b5414546f7c5bfcc9579d
Date11 October 2026 (audited again; first audit 11 October 2026)
How it ranlocal run on our workstation, full audit, Standard review
Verdict after reviewPass with notes (Fail if a High finding remains after review, otherwise Pass with notes)
0
High after review
0
Medium after review
7
Low after review
4
Info after review
0
excluded on review

Compared with the first audit

Same commit as the first audit: the project's default branch has no later commits (checked 11 October 2026), so nothing could have been fixed upstream in between. Each finding of the first audit (11 October 2026) was checked again against the code audited now. 6 findings in the first audit; 6 still open (6 found again, 0 not reported again but still present). This audit has 11 findings after review, 5 of them new.

First auditFindingReviewed rating thenNowIn this audit
#1No size limit on untrusted token parseInfoStill open#1
#2Algorithm lists in three filesLowStill open#3
#3Key conversion duplicatedInfoStill open#4
#4Unsigned token + missing key -> raw TypeErrorLowStill open#7
#5Callback-mode sign calls callback twiceLowStill open#6
noterelease.yml:41 unquoted >= (What-not-covered note)InfoStill open#11
How to read this page

Each finding keeps the number it has in the audit report. The rating shown first is the one after review; the first automated rating is listed with it. 6 findings were first rated Medium or High; 0 of them are Medium or High after review. Text marked "From the report" is quoted from the audit report; fixes are suggestions and were not tested. Code locations link to the file and line at the audited commit.

Low after review (7)

2. Low Releases are published without running the test suite
First rating: Low · Reviewed rating: Low · Review: confirmed · new in this audit
From the report
Evidence
- name: Release
  ...
  run: npx semantic-release
Why it matters

Tests run only on pull requests (test.yml). The release job publishes the merged commit on master without running npm test on that commit or on the packed tarball. A broken merge result, for example two pull requests that are each green but conflict when combined, would be published to npm untested.

Suggested fix, not tested

Run npm test in the release job before semantic-release. Ideally also install the npm pack tarball into a scratch directory and require it as a smoke test.

Review: test.yml triggers only on pull_request, and release.yml runs only npx semantic-release. .releaserc.json has no test step; its exec verifyReleaseCmd only packs and scans. Mitigation the report omits: the release is triggered by a merged chore(release): PR, and prepare-release.yml only bumps package.json and CHANGELOG.md. So the tests-per-PR gap is real but narrow.

3. Low Algorithm lists are defined separately in three files
First rating: Low · Reviewed rating: Low · Review: confirmed · also in the first audit (#2)
From the report
Evidence
const PUB_KEY_ALGS = ['RS256', 'RS384', 'RS512'];
const EC_KEY_ALGS = ['ES256', 'ES384', 'ES512'];
const RSA_KEY_ALGS = ['RS256', 'RS384', 'RS512'];
Why it matters

The supported algorithms and the algorithms allowed for each key type are written out three times: in sign.js (SUPPORTED_ALGS plus the PS insertion), in verify.js (four lists plus the PS insertion) and in lib/validateAsymmetricKey.js. The copies agree today. A future algorithm, or a change to how PS algorithms are enabled, has to be made in all three places, and missing one makes signing, verification and key validation disagree.

Suggested fix, not tested

Keep one algorithm table in lib/, keyed by algorithm with its key type and curve, and derive the sign, verify and validation lists from it.

Review: verify.js:11-14 has four lists plus a PS splice at :16-19. sign.js:14 has SUPPORTED_ALGS plus a splice at :15-17. validateAsymmetricKey.js:4-8 has its own table. The "copies agree today" claim holds, with one nuance: validateAsymmetricKey.js lists PS algorithms unconditionally while sign and verify gate them on PS_SUPPORTED.

6. Low Asynchronous sign calls the callback twice when an option duplicates a payload claim
First rating: Medium · Reviewed rating: Low · Review: rated too high · also in the first audit (#5)
Location: sign.js:221
From the report
Evidence
if (typeof payload[claim] !== 'undefined') {
  return failure(new Error('Bad "options.' + key + '" option. The payload already has an "' + claim + '" property.'));
}
Why it matters

This return sits inside a forEach callback, so it only ends that callback, not sign. With a callback, failure delivers the error and signing continues. The callback is only wrapped in once later (line 230), after this first call, so it fires a second time with a signed token. Callers that react to both calls may answer an HTTP request twice ("headers already sent") or issue a token after logging a failure. The synchronous form is not affected, because there failure throws.

Suggested fix, not tested

Replace the forEach with a for...of loop and return failure(...) from sign itself. Alternatively, record the conflicting key and return after the loop. Wrap the callback in once at the top of the function.

Review: return failure(...) at sign.js:221 returns only from the forEach callback. In callback mode failure calls callback(err) (:103-105). Signing then continues, once wraps the callback at :230 (after the first call), and :243 calls it again with a token. Sync mode throws at :107 and is not affected, as the report says. The trigger is a developer error (same claim in payload and options), not attacker input. The blast radius is contained.

7. Low An unsigned token with no resolved key makes verify throw a TypeError
First rating: Medium · Reviewed rating: Low · Review: rated too high · also in the first audit (#4)
Location: verify.js:148
From the report
Evidence
if (header.alg.startsWith('HS') && secretOrPublicKey.type !== 'secret') {
Why it matters

Consider a token with an empty signature and a header algorithm such as HS256. The application passes an algorithms list containing that algorithm, and its key callback resolves to null or undefined (a common answer for an unknown kid). Every earlier guard lets this through: the token is unsigned, there is no key, and algorithms is set. Line 148 or 150 then reads .type of null. Instead of the documented JsonWebTokenError, a TypeError is thrown. When the key callback answers asynchronously, the throw happens inside the application's own key-lookup code and can surface as an uncaught exception or an unhandled rejection. Any client can trigger it with a crafted token.

Suggested fix, not tested

Before lines 148-152, return done(new JsonWebTokenError('secret or public key must be provided')) whenever the key is null or undefined and the token's algorithm is not none.

Review: Trace: empty signature, key null/undefined, algorithms set to include the alg. :108 and :112 do not fire, :116 passes, :120 and :132 are skipped, :144 passes, and :148 (or :150) reads .type of null. The report says this is thrown outside the documented error type. It needs a falsy key returned without an error, plus an alg in algorithms that is not none. In the sync path the TypeError leaves verify() through the same channel as every other invalid token. Process-level damage needs an async resolver or a promise wrapper without a catch.

8. Low The issuer check is silently skipped for unsupported option types
First rating: Medium · Reviewed rating: Low · Review: rated too high · new in this audit
Location: verify.js:210
From the report
Evidence
const invalid_issuer =
        (typeof options.issuer === 'string' && payload.iss !== options.issuer) ||
        (Array.isArray(options.issuer) && options.issuer.indexOf(payload.iss) === -1);
Why it matters

If options.issuer is anything other than a string or an array, invalid_issuer is false and every issuer is accepted without warning. A RegExp is the likely case, because the neighbouring audience option accepts regular expressions. The application believes the issuer is enforced when it is not.

Suggested fix, not tested

Validate options.issuer up front, the way nonce and clockTimestamp already are. Accept only a string or an array of strings, and return a JsonWebTokenError for any other type.

Review: if (options.issuer) at :209 is true for a RegExp or object. :210-212 evaluate to false for non-string/non-array, so no issuer is enforced. The README (line 153) documents the option as string or array of strings, so this is fail-open on a type the docs exclude. The report is correct that audience accepts regex and issuer does not, which invites the mistake. There is no up-front type validation as for nonce/clockTimestamp (:45-55).

9. Low A regular-expression audience accepts tokens that carry no audience
First rating: Medium · Reviewed rating: Low · Review: rated too high · new in this audit
Location: verify.js:196
From the report
Evidence
const target = Array.isArray(payload.aud) ? payload.aud : [payload.aud];
...
return audience instanceof RegExp ? audience.test(targetAudience) : audience === targetAudience;
Why it matters

When the token has no aud claim, the target list is [undefined]. RegExp.test(undefined) tests the text "undefined". Permissive patterns such as /.*/, /^[a-z]+$/ or /def/ therefore match, and a token issued with no audience at all passes the audience check.

Suggested fix, not tested

When options.audience is set, reject the token if payload.aud is missing or is not a string or an array of strings. Call .test only on string values.

Review: Mechanism confirmed: :196 gives [undefined] and :200 calls audience.test(undefined), which tests the string "undefined". So /def/, /.*/ or /^[a-z]+$/ match a token with no aud. Realistic anchored patterns (for example /^api\.example\.com$/) do not match. The token must also carry a valid signature from a trusted signer. The report's "a token issued with no audience at all passes" is true only for permissive patterns. Real but narrow, so LOW.

10. Low The minimum RSA key size is not enforced on older supported Node versions
First rating: Medium · Reviewed rating: Low · Review: rated too high · new in this audit
Location: sign.js:248, and the same check at sign.js:240 for the asynchronous path
From the report
Evidence
let signature = jws.sign({header: header, payload: payload, secret: secretOrPrivateKey, encoding: encoding});
// TODO: Remove in favor of the modulus length check before signing once node 15+ is the minimum supported version
if(!options.allowInsecureKeySizes && /^(?:RS|PS)/.test(header.alg) && signature.length < 256) {
Why it matters

On Node versions below 15.7, key details are not available, so the 2048-bit check at line 132 is skipped and this fallback is the only guard. However, signature here is the whole compact token (header.payload.signature), not the signature segment. Its length is above 256 characters for almost any payload, so tokens signed with 1024-bit RSA keys are accepted. package.json declares support for Node >=12, while the CI matrix (test.yml:18) starts at Node 16, so this path is never run in tests.

Suggested fix, not tested

Measure only the signature segment: the decoded length of split('.')[2] must be at least 256 bytes. Alternatively, raise engines.node to >=15.7, or add the older versions to the CI matrix.

Review: defect CONFIRMED. The fallback at sign.js:248 tests signature.length < 256, but signature is the whole header.payload.signature string returned by jws.sign. For a 1024-bit key the signature segment alone is about 171 characters, so a token with a payload JSON of about 35 bytes or more passes the check. A very small payload such as {foo:'bar'} stays under 256 and is caught, which is why the repo tests pass; the report's "almost any payload" is slightly strong. The primary check at :132-137 relies on asymmetricKeyDetails, which only exists from Node 15.7, so on Node 12-14 the broken fallback is the only guard. package.json:68-70 declares node >=12 and test.yml:18 starts at Node 16, so the path is untested. Applies only to EOL Node, and only to the developer's own chosen key.

Info after review (4)

1. Info Token verification has no size or work limit
First rating: Low · Reviewed rating: Info · Review: rated too high · also in the first audit (#1)
Location: verify.js:67
From the report
Evidence
const parts = jwtString.split('.');
...
decodedToken = decode(jwtString, { complete: true });
Why it matters

verify accepts a token string of any length. It splits it, base64-decodes it and JSON-parses the header and payload before checking any size. It then walks an aud array of any length chosen by the token's author. A service that passes request headers straight into verify therefore does work in proportion to whatever an unauthenticated client sends. Most deployments are protected by an upstream header-size limit, so this is a hardening point, not a demonstrated outage.

Suggested fix, not tested

Add an option such as maxTokenLength with a sensible default, for example 8 KB, and reject longer tokens before splitting or decoding. Also cap the number of audience entries that are examined. Reject anything over the cap instead of truncating it.

Review: The absence of a limit is factual (only parts.length !== 3 at verify.js:69, no length checks in verify.js or decode.js). The report itself says upstream header limits usually cover it, "a hardening point, not a demonstrated outage".

4. Info Key conversion and key-type checks are duplicated in sign and verify
First rating: Low · Reviewed rating: Info · Review: rated too high · also in the first audit (#3)
Location: sign.js:114, with verify.js:120
From the report
Evidence
if (secretOrPrivateKey != null && !(secretOrPrivateKey instanceof KeyObject)) {
  try {
    secretOrPrivateKey = createPrivateKey(secretOrPrivateKey)
Why it matters

Two parts of the code are written twice with the same structure:

  • the "try an asymmetric key, then fall back to a secret key" conversion (sign.js:114-124, verify.js:120-130)
  • the check that the key type matches the algorithm family (sign.js:126-130, verify.js:148-152)

Security fixes to key handling have to be applied to both copies.

Suggested fix, not tested

Move the conversion into a shared helper that takes createPrivateKey or createPublicKey as a parameter, and put the type-versus-algorithm check in that helper too.

Review: sign.js:114-124 and verify.js:120-130 are the same cascade (private/public key, then secret key). sign.js:126-130 and verify.js:148-152 are the same type-versus-algorithm check.

5. Info The current time in seconds is computed in three places
First rating: Info · Reviewed rating: Info · Review: confirmed · new in this audit
From the report
Evidence
const clockTimestamp = options.clockTimestamp || Math.floor(Date.now() / 1000);
Why it matters

This is not a defect. It is a small inconsistency risk: a future change to how "now" is taken (a clock option, a different rounding) would have to be repeated in three files.

Suggested fix, not tested

Optionally, add one nowSeconds() helper in lib/ and use it in all three places.

Review: verify.js:57, sign.js:185 and lib/timespan.js:4 each compute Math.floor(Date.now() / 1000). The report states it is not a defect.

11. Info Version minimums in the release job's pip install are lost to shell redirection
First rating: Medium · Reviewed rating: Info · Review: rated too high · also in the first audit (a note)
From the report
Evidence
run: pip install boto3>=1.34.159 requests>=2.32.3 rl-deploy>=2.2.3.0 pip-system-certs>=4.0
Why it matters

The specifiers are unquoted, so bash reads each >=… as an output redirection. pip installs whatever versions are current, without the intended minimums. Its output goes into stray files named =1.34.159 and so on, which hides install errors from the log. This happens in the job that holds the AWS role, the npm publishing path and id-token: write.

Suggested fix, not tested

Quote every specifier, for example pip install "boto3>=1.34.159" "requests>=2.32.3" "rl-deploy>=2.2.3.0" "pip-system-certs>=4.0". Better still, use a pinned requirements file with hashes. The same job also runs npm install with package-lock.json ignored (.gitignore:5). Committing the lockfile and using npm ci would make release-time dependencies reproducible as well.

Review: defect CONFIRMED. With shell: bash, boto3>=1.34.159 parses as boto3 plus stdout redirected to a file named =1.34.159. The floors are dropped and stray files are created. But pip then installs the latest versions, which satisfy any "at least" floor, so there is no practical downgrade risk. The stdout loss hides pip progress, while errors on stderr still show. The report's remark that the lockfile is gitignored is correct (.gitignore:5), and the job does hold id-token: write and the AWS role.

Want this for your code?

Upload a ZIP or link a public GitHub repo, pick the areas and the depth, and get findings by severity with fixes.