tldr: Do I need to validate a payload from the received token?
So here's the first step with the creating of the token:
from jose import jwt
to_encode = {
"iss": "https://example.com/",
"aud": "metaserver",
"sub": user.username,
"name": user.display_name,
"metadata": metadata
}
# Here goes the updating of the payload (exp, iat, etc)
...
token = jwt.encode(to_encode, config.JWT_SECRET_KEY, algorithm=algorithm='HS256')
The metadata
field is being saved in the db. It can be anything.
The second step is when I receive a client-request and I have to check the token:
decoded = jwt.decode(token, config.JWT_SECRET_KEY, audience='metaserver', algorithms=[config.ALGORITHM])
In the documentation it is mentioned that:
What is the JSON Web Token structure? In its compact form, JSON Web
Tokens consist of three parts separated by dots (.), which are:Header
Payload
SignatureTherefore, a JWT typically looks like the following. xxxxx.yyyyy.zzzzz
So in my case the Payload
field is my metadata
The question is: is it possible for the user to send a token with the "old" Header
and Signature
parts (xxxxx.____.zzzzz)
but to include his own Payload (____.his-own-payload.____)
?
Is it enough for me just to rely on the result of the jwt.decode
? Do I have to do an additional request to the db
to compare with the received metadata
?