11import go
22
33/**
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
55 */
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 {
127 /**
138 * Gets argument number that responsible for JWT
149 *
@@ -25,6 +20,16 @@ abstract class JwtParseWithKeyFunction extends Function {
2520 or
2621 this .getTokenArgNum ( ) = - 1 and result = this .getACall ( ) .getReceiver ( )
2722 }
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 ( ) ;
2833
2934 /**
3035 * Gets Argument as DataFlow node that responsible for a function returning the secret key
@@ -35,29 +40,12 @@ abstract class JwtParseWithKeyFunction extends Function {
3540/**
3641 * A abstract class which responsible for parsing a JWT token which the key parameter can be a string or byte type
3742 */
38- abstract class JwtParse extends Function {
43+ abstract class JwtParse extends JwtParseBase {
3944 /**
4045 * Gets argument number that responsible for secret key
4146 */
4247 abstract int getKeyArgNum ( ) ;
4348
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-
6149 /**
6250 * Gets Argument as DataFlow node that responsible for secret key
6351 */
@@ -67,24 +55,7 @@ abstract class JwtParse extends Function {
6755/**
6856 * A abstract class which responsible for parsing a JWT without verifying it
6957 */
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 { }
8859
8960/**
9061 * 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 {
235206 */
236207predicate golangJwtIsAdditionalFlowStep ( DataFlow:: Node nodeFrom , DataFlow:: Node nodeTo ) {
237208 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
250222 call = f .getACall ( ) and
251223 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 )
257225 or
258- f instanceof GolangJwtParseWithClaims
259- |
226+ (
227+ f instanceof GolangJwtParse
228+ or
229+ f instanceof GolangJwtParseWithClaims
230+ ) and
260231 call = f .getACall ( ) and
261232 nodeFrom = call .getArgument ( 0 ) and
262- nodeTo = call
233+ nodeTo = call . getResult ( 0 )
263234 )
264235}
265236
@@ -268,26 +239,21 @@ predicate golangJwtIsAdditionalFlowStep(DataFlow::Node nodeFrom, DataFlow::Node
268239 */
269240predicate goJoseIsAdditionalFlowStep ( DataFlow:: Node nodeFrom , DataFlow:: Node nodeTo ) {
270241 exists ( Function f , DataFlow:: CallNode call |
271- f .hasQualifiedName ( goJoseJwtPackage ( ) , [ "ParseEncrypted" , "ParseSigned" , ] )
272- |
242+ f .hasQualifiedName ( goJoseJwtPackage ( ) , [ "ParseEncrypted" , "ParseSigned" ] ) and
273243 call = f .getACall ( ) and
274244 nodeFrom = call .getArgument ( 0 ) and
275- nodeTo = call
245+ nodeTo = call . getResult ( 0 )
276246 )
277247 or
278248 exists ( Method m , DataFlow:: CallNode call |
279- m .hasQualifiedName ( goJoseJwtPackage ( ) , "NestedJSONWebToken" , "ParseSignedAndEncrypted" )
280- |
249+ m .hasQualifiedName ( goJoseJwtPackage ( ) , "NestedJSONWebToken" , "ParseSignedAndEncrypted" ) and
281250 call = m .getACall ( ) and
282251 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
290256 nodeFrom = call .getReceiver ( ) and
291- nodeTo = call
257+ nodeTo = call . getResult ( 0 )
292258 )
293259}
0 commit comments