Skip to main content

SKY-D232 · Security in code

JWT signature check turned off

CriticalCWE-347

A JWT (JSON Web Token) is a signed piece of text that says who a user is. The signature is the only thing that proves the server issued it. SKY-D232 reports a PyJWT or python-jose jwt.decode() call that turns the signature check off or accepts the "none" algorithm, which means "no signature".

Languages
Python
Quality gate
counted toward the gate limits; a CRITICAL finding fails the gate on its own (full and diff scans)
Finding type
review
Catalog name
Unsafe JWT handling
Wrong result? Report itA false positive, a missed case or a confusing message: it goes privately to the founder.

Why it matters

Anyone can write a token with "sub": "admin" in it. When the signature is not checked, the server believes that token, so an attacker can log in as any user, including administrators, without a password.

What Skylos flags

app/auth.py · PythonReported on line 12
import jwtfrom flask import Flask, abort, request app = Flask(__name__)  def current_user_id():    header = request.headers.get("Authorization", "")    if not header.startswith("Bearer "):        abort(401)    token = header.removeprefix("Bearer ")    claims = jwt.decode(token, options={"verify_signature": False})    return claims["sub"]

What Skylos leaves alone

app/auth.py · Python
import jwtfrom flask import Flask, abort, request from app.keys import PUBLIC_KEYS app = Flask(__name__)  def current_user_id():    header = request.headers.get("Authorization", "")    if not header.startswith("Bearer "):        abort(401)    token = header.removeprefix("Bearer ")    key_id = jwt.get_unverified_header(token).get("kid")    if key_id not in PUBLIC_KEYS:        abort(401)    claims = jwt.decode(        token,        PUBLIC_KEYS[key_id],        algorithms=["RS256"],        audience="api.example.com",        options={"verify_signature": True, "require": ["exp", "sub"]},    )    return claims["sub"]

Why Skylos leaves it alone

The unverified header is read only to pick which public key to use. The jwt.decode() call then checks the signature with that key and allows only RS256. The rule reports only a literal False for the signature switch or a literal "none" algorithm, and neither is present.

More languages

Python

Flagged

app/tokens.py · PythonReported on line 7
from jose import jwt from app.settings import JWT_SECRET  def read_claims(token: str) -> dict:    return jwt.decode(token, JWT_SECRET, algorithms=["HS256", "none"])

Not flagged

app/tokens.py · Python
from jose import jwt from app.settings import JWT_SECRET  def user_id_from_expired(token: str) -> str:    claims = jwt.decode(        token,        JWT_SECRET,        algorithms=["HS256"],        options={"verify_exp": False},    )    return claims["sub"]

Why Skylos leaves it alone

This refresh helper reads the user ID from an expired access token. verify_exp turns off only the expiry check; the signature is still checked against JWT_SECRET with HS256. SKY-D232 is about the signature, so only verify_signature, verify and the "none" algorithm count.

How Skylos decides

  1. Runs with --danger on Python files that mention jwt. Finds calls that resolve, through the file's imports, to jwt.decode (PyJWT, including import jwt as j and from jwt import decode) or jose.jwt.decode (python-jose). A local variable or function that happens to be named jwt does not count.
  2. Reports CRITICAL when a keyword argument written in the call turns the signature check off: algorithms=[...] is a list literal holding the string "none" (any case), verify=False (the old PyJWT form), or options={...} is a dict literal with "verify_signature": False.
  3. Values held in variables are not followed, so options=OPTS or algorithms=ALGS is not checked. Other options, such as verify_exp or verify_aud, are not reported.
  4. TypeScript and JavaScript jwt.decode() without verification is a separate rule, SKY-D246.

How to fix it

Pass the signing key and a fixed list of the algorithms you issue, and leave signature checking on (it is on by default). Reject the request when jwt.decode() raises jwt.InvalidTokenError.

app/auth.py · Python · the fix, against the flagged file
import jwtfrom flask import Flask, abort, request app = Flask(__name__)Added: app.config.from_prefixed_env()  def current_user_id():    header = request.headers.get("Authorization", "")    if not header.startswith("Bearer "):        abort(401)    token = header.removeprefix("Bearer ")Removed:     claims = jwt.decode(token, options={"verify_signature": False})Added:     try:Added:         claims = jwt.decode(Added:             token, app.config["JWT_SECRET"], algorithms=["HS256"]Added:         )Added:     except jwt.InvalidTokenError:Added:         abort(401)    return claims["sub"]

When it can be wrong

  • Code that only reads a token's claims for display or debugging, never for an access decision, is still reported. So is a test helper that inspects tokens it made itself.
  • Missed: options or algorithm lists held in a variable or built elsewhere, an algorithms tuple instead of a list, decoding through a jwt.PyJWT() object, and jwt.get_unverified_claims() results used for access decisions.

Seeing a case that isn't listed here? Report the wrong result so the rule can be fixed. Don't paste company code: describe the shape of it.

How to silence it

  • Put the marker on the first line of the jwt.decode() call (the reported line) and say why the claims are not trusted for access.

    Python
    claims = jwt.decode(  # skylos: ignore[SKY-D232] only logged, never trusted    token, options={"verify_signature": False})
  • skylos baseline . and then --baseline accept the existing calls and report only new ones.

  • [tool.skylos] ignore = ["SKY-D232"] turns the rule off for the whole project, which also hides real authentication bypasses.

From the Skylos rule handbook, Skylos 5.8.0 (commit 5b880b0). All rules.