You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
<!DOCTYPEqhelp PUBLIC "-//Semmle//qhelp//EN" "qhelp.dtd">
2
+
<qhelp>
3
+
4
+
<overview>
5
+
<p> A JWT consists of three parts: header, payload, and signature.
6
+
The <code>io.jsonwebtoken.jjwt</code> library is one of many libraries used for working with JWTs.
7
+
It offers different methods for parsing tokens like <code>parse</code>, <code>parseClaimsJws</code>, and <code>parsePlaintextJws</code>.
8
+
The last two correctly verify that the JWT is properly signed.
9
+
This is done by computing the signature of the combination of header and payload and
10
+
comparing the locally computed signature with the signature part of the JWT.
11
+
</p>
12
+
<p>
13
+
Therefore it is necessary to provide the <code>JwtParser</code> with a key that is used for signature validation.
14
+
Unfortunately the <code>parse</code> method <b>accepts</b> a JWT whose signature is empty although a signing key has been set for the parser.
15
+
This means that an attacker can create arbitrary JWTs that will be accepted.
16
+
</p>
17
+
</overview>
18
+
<recommendation>
19
+
20
+
<p>Always verify the signature by using either the <code>parseClaimsJws</code> and <code>parsePlaintextJws</code> methods or
21
+
by overriding the <code>onPlaintextJws</code> or <code>onClaimsJws</code> of <code>JwtHandlerAdapter</code>.
22
+
</p>
23
+
24
+
</recommendation>
25
+
<example>
26
+
27
+
<p>The following example shows four cases where a signing key is set for a parser.
28
+
In the first bad case the <code>parse</code> method is used which will not validate the signature.
29
+
The second bad case uses a <code>JwtHandlerAdapter</code> where the <code>onPlaintextJwt</code> method is overriden so it will not validate the signature.
30
+
The third and fourth good cases use <code>parseClaimsJws</code> method or override the <code>onPlaintextJws</code> method.
31
+
</p>
32
+
33
+
<samplesrc="MissingJWTSignatureCheck.java" />
34
+
35
+
</example>
36
+
<references>
37
+
<li>zofrex: <ahref="https://www.zofrex.com/blog/2020/10/20/alg-none-jwt-nhs-contact-tracing-app/">How I Found An alg=none JWT Vulnerability in the NHS Contact Tracing App</a>.</li>
0 commit comments