A JSON web token is issued or accepted unsigned, with the algorithm none
What it finds
A JSON web token with the algorithm none carries no signature. Issuing one lets anyone forge tokens; accepting one in verification lets anyone forge tokens that pass.
Reported are calls of sign with the option algorithm: "none" and calls of verify whose algorithms list contains "none", in any case, as the jsonwebtoken package and others take them.
From the rule's source, jwt_none_algorithm.rs.
import jwt from "jsonwebtoken";export function tokens(payload: object, token: string, key: string) { const a = jwt.sign(payload, key, { algorithm: "none" });tx0 reports: the algorithm none means const b = jwt.verify(token, key, { algorithms: ["HS256", "none"] });tx0 reports: the algorithm none means const c = jwt.sign(payload, key, { algorithm: "RS256" }); return [a, b, c];} Turn it on, off or suppress it
The rule runs from the recommended tier up. To turn it on in a lower tier, give it a level in tx0.toml:
[rules]
"tx0/ts:jwt-none-algorithm" = "warning"To keep one finding, suppress it with a reason. tx0 suppress ID --reason "..." writes the comment on the line before the code:
// tx0: ignore[tx0/ts:jwt-none-algorithm] reason="..."tx0 explain tx0/ts:jwt-none-algorithm shows the same in the terminal. Found a false positive? Report it.