I am working on a server-client web application, and as an authentication scheme, I am issuing base64 encoded json web tokens. Consider the following token...
eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiYWRtaW4iOnRydWV9.TJVA95OrM7E2cBab30RMHrHDcEfxjoYZgeFONFh7HgQ
Decoded as such...
{
"alg": "HS256", // header
"typ": "JWT"
},
{
"sub": "1234567890", // payload
"name": "John Doe",
"admin": true
},
HMACSHA256(base64UrlEncode(header) + "." + base64UrlEncode(payload), 'secret') // signature
My concern is with the payload
portion of this token, where I wish to supply defined claims e.g. "role": "readonly"
. My concern is with these values being visible and tampered with by the end user once issued. Modifying this portion will not invalidate the signature check. I don't wish to persist any data on the server to re-check/compare issued tokens - I wish to keep the server completely stateless.
I thought maybe signing the token, encrypting it via AES 256, and using this as my "token". The flow would be summarized as such...
- generate and sign base64 encoded token
- encrypt token server side via AES 256
Issue encrypted token to client
request recieved, encrypted token supplied
- decrypt token server side
- validate base64 encoded original token signature (now able to ensure claims have not been altered)
My thoughts are, the claims (payload) will not be seen, and any tampering with this encrypted value will obviously not decrypt as expected server side. My question is - is this viable? I couldn't find much on the web for encrypting whole tokens. Is there a better way?