Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Should JWT access tokens contain PII?

JWT access tokens shouldn't contain personally identifiable information (PII) as I understand it. This is to keep them small but also if intercepted, reduce the exposure of the information contained.

The OIDC protocol asks for a user info endpoint to be implemented. It can be called using the access token and it will return a bunch of claims about the user. Effectively what the id token contains, but potentially even more information.

So even though the access token doesn't carry this PII itself, if intercepted it can certainly be used to expose all this information anyway. So the argument about PII in the access token doesn't really stand up.

Does this mean I should be fine including email in the access token, because the API might want it in addition to the sub claim?

like image 719
Daniel Revell Avatar asked Oct 18 '25 11:10

Daniel Revell


1 Answers

There are several points to be addressed here:

  1. Not all access tokens must allow access to the userinfo endpoint. First, your system must expose a userinfo endpoint. Secondly, the user must have consented to release information in the userinfo endpoint to the given client. So in case of some access tokens there will be no threat that a malicious party could access the userinfo endpoint. And sometimes the user can consent to only expose their username, so even if you gain access to userinfo, you'll still not be able to read the email. (of course it depends on the implementation of the OIDC Provider)

  2. In the majority of cases, oauth access tokens are used as bearer tokens. That means that anyone who has the token can access any data which can be accessed with that token. If someone manages to steal that token, they can do whatever the original client could. If it is a concern for you, you can use sender constrained tokens instead of bearer tokens (e.g. mTLS constrained tokens or implement DPoP). These tokens are tied to the client which originally requested them. An attacker would have to steal not only the access token, but also a certificate used to verify proof-of-possession. The implementation is a bit more tricky than with bearer tokens, but security is greatly improved.

  3. I would avoid putting any PII in a JWT. JWT can be decoded just like that, and any information kept within can be read by anyone. Let's say that someone manages to get hold of a JWT issued from your system, but it's expired. They will not be able to access the API, or userinfo, but they can still extract data from the JWT. It's much better to use opaque tokens as access tokens and exchange them in your gateway (something which is called a Phantom Token approach).

Interestingly enough, I only recently gave a talk on that concrete subject - using JWTs as access tokens and the Phantom Token flow :) (you can view here if you're interested :) link)

like image 71
Michal Trojanowski Avatar answered Oct 21 '25 17:10

Michal Trojanowski