1
1
import go
2
2
import semmle.go.frameworks.Twirp
3
+ import semmle.go.security.RequestForgery //.dataflow.ReflectedXssQuery as XssConfig
3
4
4
5
class InlineTest extends LineComment {
5
6
string tests ;
@@ -49,22 +50,27 @@ query predicate passingPositiveTests(string res, string expectation, InlineTest
49
50
exists ( RequestForgery:: Sink n | t .inNode ( n ) )
50
51
or
51
52
expectation = "message" and
52
- exists ( Twirp:: ProtobufMessage n | t .inType ( n ) )
53
+ exists ( Twirp:: ProtobufMessageType n | t .inType ( n ) )
53
54
or
54
55
expectation = "serviceInterface" and
55
- exists ( Twirp:: ServiceInterface n | t .inType ( n .getNamedType ( ) ) )
56
+ exists ( Twirp:: ServiceInterfaceType n | t .inType ( n .getNamedType ( ) ) )
56
57
or
57
58
expectation = "serviceClient" and
58
- exists ( Twirp:: ServiceClient n | t .inType ( n ) )
59
+ exists ( Twirp:: ServiceClientType n | t .inType ( n ) )
59
60
or
60
61
expectation = "serviceServer" and
61
- exists ( Twirp:: ServiceServer n | t .inType ( n ) )
62
+ exists ( Twirp:: ServiceServerType n | t .inType ( n ) )
62
63
or
63
64
expectation = "clientConstructor" and
64
65
exists ( Twirp:: ClientConstructor n | t .inEntity ( n ) )
65
66
or
66
67
expectation = "serverConstructor" and
67
68
exists ( Twirp:: ServerConstructor n | t .inEntity ( n ) )
69
+ or
70
+ expectation = "ssrf" and
71
+ exists ( RequestForgery:: Configuration cfg , DataFlow:: Node sink |
72
+ cfg .hasFlow ( _, sink ) and t .inNode ( sink )
73
+ )
68
74
)
69
75
}
70
76
@@ -82,22 +88,27 @@ query predicate failingPositiveTests(string res, string expectation, InlineTest
82
88
not exists ( RequestForgery:: Sink n | t .inNode ( n ) )
83
89
or
84
90
expectation = "message" and
85
- not exists ( Twirp:: ProtobufMessage n | t .inType ( n ) )
91
+ not exists ( Twirp:: ProtobufMessageType n | t .inType ( n ) )
86
92
or
87
93
expectation = "serviceInterface" and
88
- not exists ( Twirp:: ServiceInterface n | t .inType ( n .getNamedType ( ) ) )
94
+ not exists ( Twirp:: ServiceInterfaceType n | t .inType ( n .getNamedType ( ) ) )
89
95
or
90
96
expectation = "serviceClient" and
91
- not exists ( Twirp:: ServiceClient n | t .inType ( n ) )
97
+ not exists ( Twirp:: ServiceClientType n | t .inType ( n ) )
92
98
or
93
99
expectation = "serviceServer" and
94
- not exists ( Twirp:: ServiceServer n | t .inType ( n ) )
100
+ not exists ( Twirp:: ServiceServerType n | t .inType ( n ) )
95
101
or
96
102
expectation = "clientConstructor" and
97
103
not exists ( Twirp:: ClientConstructor n | t .inEntity ( n ) )
98
104
or
99
105
expectation = "serverConstructor" and
100
106
not exists ( Twirp:: ServerConstructor n | t .inEntity ( n ) )
107
+ or
108
+ expectation = "ssrf" and
109
+ not exists ( RequestForgery:: Configuration cfg , DataFlow:: Node sink |
110
+ cfg .hasFlow ( _, sink ) and t .inNode ( sink )
111
+ )
101
112
)
102
113
}
103
114
@@ -115,22 +126,27 @@ query predicate passingNegativeTests(string res, string expectation, InlineTest
115
126
not exists ( RequestForgery:: Sink n | t .inNode ( n ) )
116
127
or
117
128
expectation = "!message" and
118
- not exists ( Twirp:: ProtobufMessage n | t .inType ( n ) )
129
+ not exists ( Twirp:: ProtobufMessageType n | t .inType ( n ) )
119
130
or
120
131
expectation = "!serviceInterface" and
121
- not exists ( Twirp:: ServiceInterface n | t .inType ( n ) )
132
+ not exists ( Twirp:: ServiceInterfaceType n | t .inType ( n ) )
122
133
or
123
134
expectation = "!serviceClient" and
124
- not exists ( Twirp:: ServiceClient n | t .inType ( n ) )
135
+ not exists ( Twirp:: ServiceClientType n | t .inType ( n ) )
125
136
or
126
137
expectation = "!serviceServer" and
127
- not exists ( Twirp:: ServiceServer n | t .inType ( n ) )
138
+ not exists ( Twirp:: ServiceServerType n | t .inType ( n ) )
128
139
or
129
140
expectation = "!clientConstructor" and
130
141
not exists ( Twirp:: ClientConstructor n | t .inEntity ( n ) )
131
142
or
132
143
expectation = "!serverConstructor" and
133
144
not exists ( Twirp:: ServerConstructor n | t .inEntity ( n ) )
145
+ or
146
+ expectation = "!ssrf" and
147
+ not exists ( RequestForgery:: Configuration cfg , DataFlow:: Node sink |
148
+ cfg .hasFlow ( _, sink ) and t .inNode ( sink )
149
+ )
134
150
)
135
151
}
136
152
@@ -148,21 +164,26 @@ query predicate failingNegativeTests(string res, string expectation, InlineTest
148
164
exists ( RequestForgery:: Sink n | t .inNode ( n ) )
149
165
or
150
166
expectation = "!message" and
151
- exists ( Twirp:: ProtobufMessage n | t .inType ( n ) )
167
+ exists ( Twirp:: ProtobufMessageType n | t .inType ( n ) )
152
168
or
153
169
expectation = "!serviceInterface" and
154
- exists ( Twirp:: ServiceInterface n | t .inType ( n ) )
170
+ exists ( Twirp:: ServiceInterfaceType n | t .inType ( n ) )
155
171
or
156
172
expectation = "!serviceClient" and
157
- exists ( Twirp:: ServiceClient n | t .inType ( n ) )
173
+ exists ( Twirp:: ServiceClientType n | t .inType ( n ) )
158
174
or
159
175
expectation = "!serviceServer" and
160
- exists ( Twirp:: ServiceServer n | t .inType ( n ) )
176
+ exists ( Twirp:: ServiceServerType n | t .inType ( n ) )
161
177
or
162
178
expectation = "!clientConstructor" and
163
179
exists ( Twirp:: ClientConstructor n | t .inEntity ( n ) )
164
180
or
165
181
expectation = "!serverConstructor" and
166
182
exists ( Twirp:: ServerConstructor n | t .inEntity ( n ) )
183
+ or
184
+ expectation = "!ssrf" and
185
+ exists ( RequestForgery:: Configuration cfg , DataFlow:: Node sink |
186
+ cfg .hasFlow ( _, sink ) and t .inNode ( sink )
187
+ )
167
188
)
168
189
}
0 commit comments