-
Notifications
You must be signed in to change notification settings - Fork 35
Open
Description
I use python-jws for JWT.
The jws.utils.encode function uses json.dumps without the sort_keys=True parameter.
In my testing, this can cause JWT header, for example, to be encoded differently randomly.
{
"alg": "HS256",
"typ": "JWT"
}
vs
{
"typ": "JWT"
"alg": "HS256",
}
Here is my JWT verification code:
def from_jwt(jwt, algo, key):
(header, claim, sig) = jwt.split('.')
header = jws.utils.decode(header)
assert header['alg'] == algo, header
claim = jws.utils.decode(claim)
r = jws.verify(header, claim, sig, key)
assert r
return claim
jws.verify signature verification fails when header is ordered differently.
Does it make sense to set sort_keys=True?
Metadata
Metadata
Assignees
Labels
No labels