@@ -35,83 +35,59 @@ module Twirp {
35
35
}
36
36
}
37
37
38
- /**
39
- * A type representing a protobuf message.
40
- */
38
+ /** A type representing a protobuf message. */
41
39
class ProtobufMessageType extends Type {
42
40
ProtobufMessageType ( ) {
43
- exists ( TypeEntity te |
44
- te .getType ( ) = this and
45
- te .getDeclaration ( ) .getLocation ( ) .getFile ( ) instanceof ProtobufGeneratedFile
46
- )
41
+ this .hasLocationInfo ( any ( ProtobufGeneratedFile f ) .getAbsolutePath ( ) , _, _, _, _)
47
42
}
48
43
}
49
44
50
- /**
51
- * An interface type representing a Twirp service.
52
- */
45
+ /** An interface type representing a Twirp service. */
53
46
class ServiceInterfaceType extends InterfaceType {
54
47
NamedType namedType ;
55
48
56
49
ServiceInterfaceType ( ) {
57
- exists ( TypeEntity te |
58
- te .getType ( ) = namedType and
59
- namedType .getUnderlyingType ( ) = this and
60
- te .getDeclaration ( ) .getLocation ( ) .getFile ( ) instanceof ServicesGeneratedFile
61
- )
50
+ namedType .getUnderlyingType ( ) = this and
51
+ namedType .hasLocationInfo ( any ( ServicesGeneratedFile f ) .getAbsolutePath ( ) , _, _, _, _)
62
52
}
63
53
64
- /**
65
- * Gets the name of the interface.
66
- */
54
+ /** Gets the name of the interface. */
67
55
override string getName ( ) { result = namedType .getName ( ) }
68
56
69
- /**
70
- * Gets the named type on top of this interface type.
71
- */
57
+ /** Gets the named type on top of this interface type. */
72
58
NamedType getNamedType ( ) { result = namedType }
73
59
}
74
60
75
- /**
76
- * A Twirp client.
77
- */
61
+ /** A Twirp client. */
78
62
class ServiceClientType extends NamedType {
79
63
ServiceClientType ( ) {
80
- exists ( ServiceInterfaceType i , PointerType p , TypeEntity te |
64
+ exists ( ServiceInterfaceType i , PointerType p |
81
65
p .implements ( i ) and
82
66
this = p .getBaseType ( ) and
83
67
this .getName ( ) .regexpMatch ( "(?i)" + i .getName ( ) + "(protobuf|json)client" ) and
84
- te .getType ( ) = this and
85
- te .getDeclaration ( ) .getLocation ( ) .getFile ( ) instanceof ServicesGeneratedFile
68
+ this .hasLocationInfo ( any ( ServicesGeneratedFile f ) .getAbsolutePath ( ) , _, _, _, _)
86
69
)
87
70
}
88
71
}
89
72
90
- /**
91
- * A Twirp server.
92
- */
73
+ /** A Twirp server. */
93
74
class ServiceServerType extends NamedType {
94
75
ServiceServerType ( ) {
95
- exists ( ServiceInterfaceType i , TypeEntity te |
76
+ exists ( ServiceInterfaceType i |
96
77
this .implements ( i ) and
97
78
this .getName ( ) .regexpMatch ( "(?i)" + i .getName ( ) + "server" ) and
98
- te .getType ( ) = this and
99
- te .getDeclaration ( ) .getLocation ( ) .getFile ( ) instanceof ServicesGeneratedFile
79
+ this .hasLocationInfo ( any ( ServicesGeneratedFile f ) .getAbsolutePath ( ) , _, _, _, _)
100
80
)
101
81
}
102
82
}
103
83
104
- /**
105
- * A Twirp function to construct a Client.
106
- */
84
+ /** A Twirp function to construct a Client. */
107
85
class ClientConstructor extends Function {
108
86
ClientConstructor ( ) {
109
- exists ( ServiceClientType c |
110
- this .getName ( ) .regexpMatch ( "(?i)new" + c .getName ( ) ) and
111
- this .getParameterType ( 0 ) instanceof StringType and
112
- this .getParameterType ( 1 ) .getName ( ) = "HTTPClient" and
113
- this .getDeclaration ( ) .getLocation ( ) .getFile ( ) instanceof ServicesGeneratedFile
114
- )
87
+ this .getName ( ) .regexpMatch ( "(?i)new" + any ( ServiceClientType c ) .getName ( ) ) and
88
+ this .getParameterType ( 0 ) instanceof StringType and
89
+ this .getParameterType ( 1 ) .getName ( ) = "HTTPClient" and
90
+ this .hasLocationInfo ( any ( ServicesGeneratedFile f ) .getAbsolutePath ( ) , _, _, _, _)
115
91
}
116
92
}
117
93
@@ -122,17 +98,13 @@ module Twirp {
122
98
*/
123
99
class ServerConstructor extends Function {
124
100
ServerConstructor ( ) {
125
- exists ( ServiceServerType c , ServiceInterfaceType i |
126
- this .getName ( ) .regexpMatch ( "(?i)new" + c .getName ( ) ) and
127
- this .getParameterType ( 0 ) = i .getNamedType ( ) and
128
- this .getDeclaration ( ) .getLocation ( ) .getFile ( ) instanceof ServicesGeneratedFile
129
- )
101
+ this .getName ( ) .regexpMatch ( "(?i)new" + any ( ServiceServerType c ) .getName ( ) ) and
102
+ this .getParameterType ( 0 ) = any ( ServiceInterfaceType i ) .getNamedType ( ) and
103
+ this .hasLocationInfo ( any ( ServicesGeneratedFile f ) .getAbsolutePath ( ) , _, _, _, _)
130
104
}
131
105
}
132
106
133
- /**
134
- * An SSRF sink for the Client constructor.
135
- */
107
+ /** An SSRF sink for the Client constructor. */
136
108
class ClientRequestUrlAsSink extends RequestForgery:: Sink {
137
109
ClientRequestUrlAsSink ( ) {
138
110
exists ( DataFlow:: CallNode call |
@@ -146,27 +118,22 @@ module Twirp {
146
118
override string getKind ( ) { result = "URL" }
147
119
}
148
120
149
- /**
150
- * A service handler.
151
- */
121
+ /** A service handler. */
152
122
class ServiceHandler extends Method {
153
123
ServiceHandler ( ) {
154
- exists ( DataFlow:: CallNode call , Type handlerType , ServiceInterfaceType i |
124
+ exists ( DataFlow:: CallNode call |
155
125
call .getTarget ( ) instanceof ServerConstructor and
156
- call .getArgument ( 0 ) .getType ( ) = handlerType and
157
- this = handlerType .getMethod ( _) and
158
- this .implements ( i .getNamedType ( ) .getMethod ( _) )
126
+ this = call .getArgument ( 0 ) .getType ( ) .getMethod ( _) and
127
+ this .implements ( any ( ServiceInterfaceType i ) .getNamedType ( ) .getMethod ( _) )
159
128
)
160
129
}
161
130
}
162
131
163
- /**
164
- * A request coming to the service handler.
165
- */
132
+ /** A request coming to the service handler. */
166
133
class Request extends UntrustedFlowSource:: Range instanceof DataFlow:: ParameterNode {
167
134
Request ( ) {
168
- exists ( FuncDef c , ServiceHandler handler | handler . getFuncDecl ( ) = c |
169
- this .asParameter ( ) .isParameterOf ( c , 1 ) and
135
+ exists ( ServiceHandler handler |
136
+ this .asParameter ( ) .isParameterOf ( handler . getFuncDecl ( ) , 1 ) and
170
137
handler .getParameterType ( 0 ) .hasQualifiedName ( "context" , "Context" ) and
171
138
this .getType ( ) .( PointerType ) .getBaseType ( ) instanceof ProtobufMessageType
172
139
)
0 commit comments