# jsonwebtoken — card for AI agents

Create, verify and decode JSON Web Tokens for authentication and secure data transmission.

Category: Auth and security libraries · npm package `jsonwebtoken` · latest version 9.0.3 (checked 2026-11-01)
Install: `npm install jsonwebtoken`
License: MIT (permissive)

In your own product (generator, app, hosted service): **yes**. Permissive license: ship it inside your own product, closed or open source, and keep its license and copyright notice.

## Rules for AI agents (paste into AGENTS.md or CLAUDE.md)

## jsonwebtoken
- Use `jwt.verify` for any token from a client or external request. Never use `jwt.decode`, which does not check the signature.
- Pass `algorithms` explicitly to `verify` (for example `['RS256']`). Do not add `'none'` unless unsigned tokens are really intended.
- Treat the decoded payload as user input. Read only the properties you expect.
- Give `expiresIn`, `notBefore` and `maxAge` a number of seconds or a string with units (`'1h'`, `'7d'`). A unitless string like `'120'` means milliseconds.
- Put a claim either in the payload (`exp`, `nbf`, `aud`, `sub`, `iss`) or in the options, never both. Use an object literal payload so claims get set.
- Use RSA keys of at least 2048 bits, and never sign HS* tokens with an asymmetric key. Do not set `allowInsecureKeySizes` or `allowInvalidAsymmetricKeyTypes` in new code.
- Handle `TokenExpiredError`, `NotBeforeError` and `JsonWebTokenError` separately when mapping failures to responses.

## What it is
- jsonwebtoken is an MIT-licensed implementation of JSON Web Tokens for Node.js. The repository dates from 2013, and it is published on npm as `jsonwebtoken`. It has three calls. `jwt.sign` builds a token, `jwt.verify` checks the signature and the standard claims, and `jwt.decode` reads a token without checking it. Each call runs synchronously, or takes a callback.
- Verification goes beyond the signature. You pass the audience, issuer, subject, JWT ID, nonce, max age and clock tolerance you expect. A mismatch comes back as a named error. Supported algorithms cover HMAC (HS256/384/512), RSA (RS and PS), ECDSA (ES256/384/512) and `none`.
- Version 9 tightened the defaults. The migration notes describe these changes as "security fixes to follow best practices" that may break code which relied on the old behaviour. Read those notes before upgrading an older codebase.

## Caveats
- decode() checks nothing: `jwt.decode` reads the payload without validating the signature. The README warns against using it for untrusted messages and points to `jwt.verify` instead.
- A verified payload is still user input: Even after verification, the README says a payload from an untrusted source must be sanitized, and you should only read the properties you expect.
- String durations without units mean milliseconds: `expiresIn`, `notBefore` and `maxAge` treat numbers as seconds. A unitless string is read as milliseconds, so `"120"` means `"120ms"`.
- No token refresh built in: The maintainers left auto-refresh out on purpose. They link to an example gist instead, and ask you to consider whether refresh adds a vulnerability.
- v9 breaks loose key handling: v9 requires Node 12 or later. Asymmetric keys can no longer sign or verify HS tokens, and key types must match the algorithm unless you set `allowInvalidAsymmetricKeyTypes`.

## Numbers (AgentGid data)
- Gid Score: 78.7 (#122 of all tools, 2 of 141 in its category)
- Used in 149 public projects set up for AI coding agents (2.4%)
- Downloads last week: 84,480,307 (as of 2026-11-24), +40.6% over 4 weeks
- GitHub stars: 18,184 (as of 2026-11-24)
- Last push: 2026-06-25

## Often used with
dotenv 70.5%, Express 60.4%, cors 53.7%, bcryptjs 39.6%, Zod 59.7%, Helmet 35.6%

## Checked alternatives (same job)
- jose: https://agentgid.com/tools/jose/agent.md
- Passport.js: https://agentgid.com/tools/passport/agent.md

## Links
- AgentGid page: https://agentgid.com/tools/jsonwebtoken/
- Homepage: https://github.com/auth0/node-jsonwebtoken#readme
- Repository: https://github.com/auth0/node-jsonwebtoken
- Source: https://github.com/auth0/node-jsonwebtoken#readme
- Source: https://github.com/auth0/node-jsonwebtoken
- Source: https://www.npmjs.com/package/jsonwebtoken
- Source: https://github.com/auth0/node-jsonwebtoken/wiki/Migration-Notes:-v8-to-v9

---
AgentGid's catalog is curated: every entry was checked against the maker's official pages (registry, repository, license and pricing pages) on the date shown; a license value shows the quote it stands on wherever AgentGid has one. Usage numbers come from AgentGid's own scan of public repositories set up for AI coding agents. Claims by makers are reported, not tested by AgentGid.
