JWT signature verification is disabled

JWT signature verification is disabled

Description

With verify_signature=False, PyJWT reads token claims without verifying who signed them.

Potential impact

Trusting an unverified user ID or role can give someone access to another account. Expiration, issuer and audience checks may also be skipped.

Remediation

In production, pass a trusted key and allowed algorithms to jwt.decode(). Require and validate the claims your service depends on, such as exp, iss and aud. Isolate test code that skips verification.

Examples

Before

python
import jwt

def bad_decode(token):
    return jwt.decode(token, options={"verify_signature": False})

After

python
import jwt

def safe_decode(token, key):
    return jwt.decode(token, key, algorithms=["HS256"], audience="api")

The example checks the HS256 signature and the api audience. Checking a particular issuer or requiring exp to be present needs additional configuration.

References