1
1
import go
2
2
3
3
/**
4
- * A abstract class which responsible for parsing a JWT token which the key parameter is a function type
4
+ * A abstract class which responsible for parsing a JWT token
5
5
*/
6
- abstract class JwtParseWithKeyFunction extends Function {
7
- /**
8
- * Gets argument number that responsible for a function returning the secret key
9
- */
10
- abstract int getKeyFuncArgNum ( ) ;
11
-
6
+ abstract class JwtParseBase extends Function {
12
7
/**
13
8
* Gets argument number that responsible for JWT
14
9
*
@@ -25,6 +20,16 @@ abstract class JwtParseWithKeyFunction extends Function {
25
20
or
26
21
this .getTokenArgNum ( ) = - 1 and result = this .getACall ( ) .getReceiver ( )
27
22
}
23
+ }
24
+
25
+ /**
26
+ * A abstract class which responsible for parsing a JWT token which the key parameter is a function type
27
+ */
28
+ abstract class JwtParseWithKeyFunction extends JwtParseBase {
29
+ /**
30
+ * Gets argument number that responsible for a function returning the secret key
31
+ */
32
+ abstract int getKeyFuncArgNum ( ) ;
28
33
29
34
/**
30
35
* Gets Argument as DataFlow node that responsible for a function returning the secret key
@@ -35,29 +40,12 @@ abstract class JwtParseWithKeyFunction extends Function {
35
40
/**
36
41
* A abstract class which responsible for parsing a JWT token which the key parameter can be a string or byte type
37
42
*/
38
- abstract class JwtParse extends Function {
43
+ abstract class JwtParse extends JwtParseBase {
39
44
/**
40
45
* Gets argument number that responsible for secret key
41
46
*/
42
47
abstract int getKeyArgNum ( ) ;
43
48
44
- /**
45
- * Gets argument number that responsible for JWT
46
- *
47
- * `-1` means the receiver is a argument node that responsible for JWT.
48
- * In this case, we must declare some additional taint steps.
49
- */
50
- abstract int getTokenArgNum ( ) ;
51
-
52
- /**
53
- * Gets Argument as DataFlow node that responsible for JWT
54
- */
55
- DataFlow:: Node getTokenArg ( ) {
56
- this .getTokenArgNum ( ) != - 1 and result = this .getACall ( ) .getArgument ( this .getTokenArgNum ( ) )
57
- or
58
- this .getTokenArgNum ( ) = - 1 and result = this .getACall ( ) .getReceiver ( )
59
- }
60
-
61
49
/**
62
50
* Gets Argument as DataFlow node that responsible for secret key
63
51
*/
@@ -67,24 +55,7 @@ abstract class JwtParse extends Function {
67
55
/**
68
56
* A abstract class which responsible for parsing a JWT without verifying it
69
57
*/
70
- abstract class JwtUnverifiedParse extends Function {
71
- /**
72
- * Gets argument number that responsible for JWT
73
- *
74
- * `-1` means the receiver is a argument node that responsible for JWT.
75
- * In this case, we must declare some additional taint steps.
76
- */
77
- abstract int getTokenArgNum ( ) ;
78
-
79
- /**
80
- * Gets Argument as DataFlow node that responsible for JWT
81
- */
82
- DataFlow:: Node getTokenNode ( ) {
83
- this .getTokenArgNum ( ) != - 1 and result = this .getACall ( ) .getArgument ( this .getTokenArgNum ( ) )
84
- or
85
- this .getTokenArgNum ( ) = - 1 and result = this .getACall ( ) .getReceiver ( )
86
- }
87
- }
58
+ abstract class JwtUnverifiedParse extends JwtParseBase { }
88
59
89
60
/**
90
61
* Gets `github.com/golang-jwt/jwt` and `github.com/dgrijalva/jwt-go`(previous name of `golang-jwt`) JWT packages
@@ -235,31 +206,31 @@ class GoJoseUnsafeClaims extends JwtUnverifiedParse {
235
206
*/
236
207
predicate golangJwtIsAdditionalFlowStep ( DataFlow:: Node nodeFrom , DataFlow:: Node nodeTo ) {
237
208
exists ( Function f , DataFlow:: CallNode call |
238
- f .hasQualifiedName ( package ( "github.com/golang-jwt/jwt" , "" ) ,
239
- [
240
- "ParseECPrivateKeyFromPEM" , "ParseECPublicKeyFromPEM" , "ParseEdPrivateKeyFromPEM" ,
241
- "ParseEdPublicKeyFromPEM" , "ParseRSAPrivateKeyFromPEM" , "ParseRSAPublicKeyFromPEM" ,
242
- "RegisterSigningMethod"
243
- ] ) or
244
- f .hasQualifiedName ( package ( "github.com/dgrijalva/jwt-go" , "" ) ,
245
- [
246
- "ParseECPrivateKeyFromPEM" , "ParseECPublicKeyFromPEM" , "ParseRSAPrivateKeyFromPEM" ,
247
- "ParseRSAPrivateKeyFromPEMWithPassword" , "ParseRSAPublicKeyFromPEM"
248
- ] )
249
- |
209
+ (
210
+ f .hasQualifiedName ( package ( "github.com/golang-jwt/jwt" , "" ) ,
211
+ [
212
+ "ParseECPrivateKeyFromPEM" , "ParseECPublicKeyFromPEM" , "ParseEdPrivateKeyFromPEM" ,
213
+ "ParseEdPublicKeyFromPEM" , "ParseRSAPrivateKeyFromPEM" , "ParseRSAPublicKeyFromPEM" ,
214
+ "RegisterSigningMethod"
215
+ ] ) or
216
+ f .hasQualifiedName ( package ( "github.com/dgrijalva/jwt-go" , "" ) ,
217
+ [
218
+ "ParseECPrivateKeyFromPEM" , "ParseECPublicKeyFromPEM" , "ParseRSAPrivateKeyFromPEM" ,
219
+ "ParseRSAPrivateKeyFromPEMWithPassword" , "ParseRSAPublicKeyFromPEM"
220
+ ] )
221
+ ) and
250
222
call = f .getACall ( ) and
251
223
nodeFrom = call .getArgument ( 0 ) and
252
- nodeTo = call
253
- )
254
- or
255
- exists ( Function f , DataFlow:: CallNode call |
256
- f instanceof GolangJwtParse
224
+ nodeTo = call .getResult ( 0 )
257
225
or
258
- f instanceof GolangJwtParseWithClaims
259
- |
226
+ (
227
+ f instanceof GolangJwtParse
228
+ or
229
+ f instanceof GolangJwtParseWithClaims
230
+ ) and
260
231
call = f .getACall ( ) and
261
232
nodeFrom = call .getArgument ( 0 ) and
262
- nodeTo = call
233
+ nodeTo = call . getResult ( 0 )
263
234
)
264
235
}
265
236
@@ -268,26 +239,21 @@ predicate golangJwtIsAdditionalFlowStep(DataFlow::Node nodeFrom, DataFlow::Node
268
239
*/
269
240
predicate goJoseIsAdditionalFlowStep ( DataFlow:: Node nodeFrom , DataFlow:: Node nodeTo ) {
270
241
exists ( Function f , DataFlow:: CallNode call |
271
- f .hasQualifiedName ( goJoseJwtPackage ( ) , [ "ParseEncrypted" , "ParseSigned" , ] )
272
- |
242
+ f .hasQualifiedName ( goJoseJwtPackage ( ) , [ "ParseEncrypted" , "ParseSigned" ] ) and
273
243
call = f .getACall ( ) and
274
244
nodeFrom = call .getArgument ( 0 ) and
275
- nodeTo = call
245
+ nodeTo = call . getResult ( 0 )
276
246
)
277
247
or
278
248
exists ( Method m , DataFlow:: CallNode call |
279
- m .hasQualifiedName ( goJoseJwtPackage ( ) , "NestedJSONWebToken" , "ParseSignedAndEncrypted" )
280
- |
249
+ m .hasQualifiedName ( goJoseJwtPackage ( ) , "NestedJSONWebToken" , "ParseSignedAndEncrypted" ) and
281
250
call = m .getACall ( ) and
282
251
nodeFrom = call .getArgument ( 0 ) and
283
- nodeTo = call
284
- )
285
- or
286
- exists ( Method f , DataFlow:: CallNode call |
287
- f .hasQualifiedName ( goJoseJwtPackage ( ) , "NestedJSONWebToken" , "Decrypt" )
288
- |
289
- call = f .getACall ( ) and
252
+ nodeTo = call .getResult ( 0 )
253
+ or
254
+ m .hasQualifiedName ( goJoseJwtPackage ( ) , "NestedJSONWebToken" , "Decrypt" ) and
255
+ call = m .getACall ( ) and
290
256
nodeFrom = call .getReceiver ( ) and
291
- nodeTo = call
257
+ nodeTo = call . getResult ( 0 )
292
258
)
293
259
}
0 commit comments