1
+ /** Provides models of commonly used functions and types in the twirp packages. */
2
+
1
3
import go
2
4
import semmle.go.security.RequestForgery
3
5
6
+ /** Provides models of commonly used functions and types in the twirp packages. */
4
7
module Twirp {
5
8
/**
6
9
* A *.pb.go file generated by Twirp.
@@ -47,17 +50,27 @@ module Twirp {
47
50
/**
48
51
* An interface type representing a Twirp service.
49
52
*/
50
- class ServiceInterface extends NamedType {
53
+ class ServiceInterface extends InterfaceType {
54
+ NamedType serviceInterface ;
55
+
51
56
ServiceInterface ( ) {
52
57
exists ( TypeEntity te |
53
- te .getType ( ) = this and
54
- // To match an Interface type we need to use a NamedType whose getUnderlying type is an InterfaceType
55
- this .getUnderlyingType ( ) instanceof InterfaceType and
58
+ te .getType ( ) = serviceInterface and
59
+ this instanceof InterfaceType and
60
+ serviceInterface .getUnderlyingType ( ) = this and
56
61
te .getDeclaration ( ) .getLocation ( ) .getFile ( ) instanceof ServicesGeneratedFile
57
62
)
58
63
}
59
64
60
- InterfaceType getInterfaceType ( ) { result = this .getUnderlyingType ( ) }
65
+ /**
66
+ * Returns the name of the interface
67
+ */
68
+ override string getName ( ) { result = serviceInterface .getName ( ) }
69
+
70
+ /**
71
+ * Returns the named type on top of this interface type
72
+ */
73
+ NamedType getNamedType ( ) { result = serviceInterface }
61
74
}
62
75
63
76
/**
@@ -68,7 +81,7 @@ module Twirp {
68
81
69
82
ServiceClient ( ) {
70
83
exists ( ServiceInterface i |
71
- pointerType .implements ( i . getInterfaceType ( ) ) and
84
+ pointerType .implements ( i ) and
72
85
this = pointerType .getBaseType ( ) and
73
86
this .getName ( ) .toLowerCase ( ) = i .getName ( ) .toLowerCase ( ) + [ "protobuf" , "json" ] + "client"
74
87
)
@@ -81,7 +94,7 @@ module Twirp {
81
94
class ServiceServer extends NamedType {
82
95
ServiceServer ( ) {
83
96
exists ( ServiceInterface i |
84
- this .implements ( i . getInterfaceType ( ) ) and
97
+ this .implements ( i ) and
85
98
this .getName ( ) .toLowerCase ( ) = i .getName ( ) .toLowerCase ( ) + "server"
86
99
)
87
100
}
@@ -106,9 +119,9 @@ module Twirp {
106
119
*/
107
120
class ServerConstructor extends Function {
108
121
ServerConstructor ( ) {
109
- exists ( ServiceServer c |
122
+ exists ( ServiceServer c , ServiceInterface i |
110
123
this .getName ( ) .toLowerCase ( ) = "new" + c .getName ( ) .toLowerCase ( ) and
111
- this .getParameter ( 0 ) .getType ( ) instanceof ServiceInterface
124
+ this .getParameter ( 0 ) .getType ( ) = i . getNamedType ( )
112
125
)
113
126
}
114
127
}
@@ -139,10 +152,10 @@ module Twirp {
139
152
exists ( DataFlow:: CallNode call , Type handlerType , ServiceInterface i |
140
153
call .getTarget ( ) instanceof ServerConstructor and
141
154
call .getArgument ( 0 ) .getType ( ) = handlerType and
142
- handlerType .implements ( i . getInterfaceType ( ) ) and
155
+ handlerType .implements ( i ) and
143
156
this = handlerType .getMethod ( _) and
144
157
this .implements ( m ) and
145
- i .getMethod ( _) = m
158
+ i .getNamedType ( ) . getMethod ( _) = m
146
159
)
147
160
}
148
161
}
0 commit comments