Description
A JWT with the none algorithm is unsigned. Its claims provide no proof of who issued the token or whether its contents changed.
Potential impact
Accepting it as proof of identity could expose another user’s protected data or session information.
Remediation
Reject unsigned tokens for authentication and authorization. Verify the signature with a trusted key and a server-defined algorithm such as HS256 or RS256. Then check issuer, audience, expiration and the user’s permissions.
Examples
These excerpts use the legacy jose 1.28.2 API. Use a maintained version for new code. Replace token-here with the token and set JWT_SECRET to the Base64 encoding of a random shared secret of at least 256 bits from a trusted source. Configuration and verification error handling are omitted.
Before
const jose = require("jose");
const { JWK, JWT } = jose;
// Accept the unsigned 'none' algorithm
const token = JWT.verify('token-here', JWK.None);
After
const jose = require("jose");
const { JWK, JWT } = jose;
const secretKey = JWK.asKey(Buffer.from(process.env.JWT_SECRET, 'base64'));
// Verify with the allowed HS256 algorithm and shared secret
const token = JWT.verify('token-here', secretKey, { algorithms: ['HS256'] });
The first call accepts an unsigned token with JWK.None. The second verifies only HS256 signatures with the shared secret.