A JSON Web Token is signed or checked with a key written in the source

tx0/python:hardcoded-jwt-secretrecommendedwarningsecurity/secretsdepth fastsecurity, cwe-798

What it finds

With a symmetric algorithm the same key signs and verifies tokens, so a key in the source lets anyone who reads it mint valid tokens. Checked are jwt.encode and jwt.decode of PyJWT given a non-empty string literal as the key.

From the rule's source, hardcoded_jwt_secret.rs.

Example from the rule's tests
import jwt def issue(payload, key):    a = jwt.encode(payload, "secret", algorithm="HS256")tx0 reports: the token key is written in the source    b = jwt.decode(a, key="secret", algorithms=["HS256"])tx0 reports: the token key is written    c = jwt.encode(payload, key, algorithm="HS256")    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/python:hardcoded-jwt-secret" = "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/python:hardcoded-jwt-secret] reason="..."

tx0 explain tx0/python:hardcoded-jwt-secret shows the same in the terminal. Found a false positive? Report it.