Skip to content

Commit 958e2fa

Browse files
Apply suggestions from code review
Co-authored-by: Chris Smowton <[email protected]>
1 parent 231b077 commit 958e2fa

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

java/ql/src/experimental/Security/CWE/CWE-347/MissingJWTSignatureCheck.qhelp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<qhelp>
33

44
<overview>
5-
<p> A JWT consists of three parts: header, payload, and signature.
5+
<p> A JSON Web Token (JWT) consists of three parts: header, payload, and signature.
66
The <code>io.jsonwebtoken.jjwt</code> library is one of many libraries used for working with JWTs.
77
It offers different methods for parsing tokens like <code>parse</code>, <code>parseClaimsJws</code>, and <code>parsePlaintextJws</code>.
88
The last two correctly verify that the JWT is properly signed.
@@ -12,7 +12,7 @@ comparing the locally computed signature with the signature part of the JWT.
1212
<p>
1313
Therefore it is necessary to provide the <code>JwtParser</code> with a key that is used for signature validation.
1414
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.
15+
This means that an attacker can create arbitrary JWTs that will be accepted if this method is used.
1616
</p>
1717
</overview>
1818
<recommendation>
@@ -36,4 +36,4 @@ The third and fourth good cases use <code>parseClaimsJws</code> method or overri
3636
<references>
3737
<li>zofrex: <a href="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>
3838
</references>
39-
</qhelp>
39+
</qhelp>

java/ql/src/experimental/Security/CWE/CWE-347/MissingJWTSignatureCheck.ql

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,10 @@ private class JwtHandlerAdapterOnJwtMethod extends Method {
7070

7171
/**
7272
* Holds if `parseHandlerExpr` is an insecure `JwtHandler`.
73-
* That is, it overrides a method from `JwtHandlerOnJwtMethod` and the overridden method is not a method from `JwtHandlerAdapterOnJwtMethod`.
74-
* A overridden method which is a method from `JwtHandlerAdapterOnJwtMethod` is safe, because these always throw an exception.
73+
* That is, it overrides a method from `JwtHandlerOnJwtMethod` and the override is not defined on `JwtHandlerAdapter`.
74+
* `JwtHandlerAdapter`'s overrides are safe since they always throw an exception.
7575
*/
76-
private predicate isInsecureParseHandler(Expr parseHandlerExpr) {
76+
private predicate isInsecureJwtHandler(Expr parseHandlerExpr) {
7777
exists(RefType t |
7878
parseHandlerExpr.getType() = t and
7979
t.getASourceSupertype*() instanceof TypeJwtHandler and
@@ -95,7 +95,7 @@ private class JwtParserInsecureParseMethodAccess extends MethodAccess {
9595
this.getMethod().getASourceOverriddenMethod*() instanceof JwtParserInsecureParseMethod
9696
or
9797
this.getMethod().getASourceOverriddenMethod*() instanceof JwtParserParseHandlerMethod and
98-
isInsecureParseHandler(this.getArgument(1))
98+
isInsecureJwtHandler(this.getArgument(1))
9999
}
100100
}
101101

@@ -113,7 +113,7 @@ private class JwtParserInsecureParseMethodAccess extends MethodAccess {
113113
* ```
114114
* In this case, the signing key is set on a `JwtParserBuilder` indirectly setting the key of `JwtParser` that is created by the call to `build`.
115115
*/
116-
private predicate isSigningKeySet(Expr expr, MethodAccess signingMa) {
116+
private predicate isSigningKeySetter(Expr expr, MethodAccess signingMa) {
117117
any(SigningToExprDataFlow s).hasFlow(DataFlow::exprNode(signingMa), DataFlow::exprNode(expr))
118118
}
119119

@@ -123,7 +123,7 @@ private class JwtParserWithSigningKeyExpr extends Expr {
123123

124124
JwtParserWithSigningKeyExpr() {
125125
this.getType().(RefType).getASourceSupertype*() instanceof TypeJwtParser and
126-
isSigningKeySet(this, signingMa)
126+
isSigningKeySetter(this, signingMa)
127127
}
128128

129129
/** Gets the method access that sets the signing key for this parser. */

0 commit comments

Comments
 (0)