A JSON web token is issued or accepted unsigned, with the algorithm none

tx0/ts:jwt-none-algorithmrecommendedwarningsecurity, cwe-347

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.

Example from the rule's tests
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];}
Highlighted lines are the ones tx0 reports, with its message under each; the other lines are left alone.

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:

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.