I am currently studying a JWT implementation with PHP and want to use JWT tokens instead of sessions for my RESTful application.
While creating a signature, I do something like this
token = base64Header + '.' + base64Payload + '.' + signature
Here we just use the base64 payload. If I embed sites like https://jwt.io/#debugger , the payload is decrypted (even if the signature is incorrect).
My questions,
- Is JWT only to verify the signature with the server when sending data?
- Is it insecure to store sensitive data in a payload?
- If you are unsure of security, is there any way to protect the payload?
Below is an example of the code I wrote
<?php $headers = base64_encode(json_encode([ "typ" => "JWT", "alg" => "HS256" ])); $claims = base64_encode(json_encode([ "sub" => "1234567890", "name" => "John Doe", "admin" => true, "jti" => "870a3de5-ea7b-4062-abef-11180e530f5a", "iat" => 1492603378, "exp" => 1492606978 ])); $payload = $headers.".".$claims; $signature = base64_encode(hash_hmac("sha256", $payload, 'secret', true)); $encodedJWT = $payload.".".$signature;
source share