SKY-D232 · Security in code
JWT signature check turned off
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
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
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
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
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
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
- Runs with
--dangeron Python files that mentionjwt. Finds calls that resolve, through the file's imports, tojwt.decode(PyJWT, includingimport jwt as jandfrom jwt import decode) orjose.jwt.decode(python-jose). A local variable or function that happens to be namedjwtdoes not count. - 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), oroptions={...}is a dict literal with"verify_signature": False. - Values held in variables are not followed, so
options=OPTSoralgorithms=ALGSis not checked. Other options, such asverify_exporverify_aud, are not reported. - 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.
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
algorithmstuple instead of a list, decoding through ajwt.PyJWT()object, andjwt.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--baselineaccept 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.