Skip to content

PyJWKSet reports the wrong exception for an empty key set #754

@lbam

Description

@lbam

Empty key sets give the wrong exception. The error is here:

pyjwt/jwt/api_jwk.py

Lines 80 to 84 in 24b29ad

if not keys or not isinstance(keys, list):
raise PyJWKSetError("Invalid JWK Set value")
if len(keys) == 0:
raise PyJWKSetError("The JWK Set did not contain any keys")

When keys is the empty list, not keys is true so the second check is never reached (unless some list subclass overrides __bool__).

Expected Result

Should raise PyJWKSetError("The JWK Set did not contain any keys").

Actual Result

Raises PyJWKSetError("Invalid JWK Set value").

Reproduction Steps

import jwt
jwt.PyJWKSet.from_dict({"keys": []})

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions