DEV Community

Cover image for What are JWT?

What are JWT?

Thomas Broyer on November 29, 2023

This is a translation of an article I wrote for our internal knowledge base at work, and that we later decided to publish (in French). This art...
Collapse
 
kremsku profile image
kremsku

Very good and valid points! I would summarise this as: "JWT's can be used in a secure way, but can also be implemented in a totally incorrect way".

As in many technologies, the technology itself doesn't guarantee security, it is the implementation that matters.

Collapse
 
arietimmerman profile image
Arie Timmerman

Nice overview with many interesting things to consider.

I do disagree with you on this part however:

Aside: despite ID Tokens in OpenID Connect being JWTs, you won't actually need to verify their signature as you generally get them through HTTPS, that already guarantees authenticity and integrity (and confidentiality), which saves us from a whole class of vulnerabilities.

Here HTTPS only guarantees that the ID Token has been transmitted securely between the end user's user agent and the OpenID Connect client (website). You must still verify the JWT in order to confirm it was issued legitimately from your trusted identity provider. Omitting this introduces many major security risks.

Collapse
 
tbroyer profile image
Thomas Broyer

transmitted securely between the end user's user agent and the OpenID Connect client (website)

Which flow are you talking about? With the authorization code flow (which you should use over anything else), the ID Token comes right from the IdP in the token response, so HTTPS guarantees both authenticity and integrity (and confidentiality).

If you're using an hybrid flow or implicit flow (but you shouldn't) then I agree you must validate the ID Token signature, as it comes from an insecure channel (redirect or possibly form post)

Collapse
 
arietimmerman profile image
Arie Timmerman

You are right with respect to the authorization code flow, and that is indeed the flow that should be used always. I checked the specifications and it even explicitly mentions that there is no need to verify the JWT signature. To be honest, I never really realized this.

If the ID Token is received via direct communication between the Client and the Token Endpoint (which it is in this flow), the TLS server validation MAY be used to validate the issuer in place of checking the token signature. The Client MUST validate the signature of all other ID Tokens according to JWS [JWS] using the algorithm specified in the JWT alg Header Parameter. The Client MUST use the keys provided by the Issuer.