Skip to content

Commit accc09f

Browse files
committed
Lists of strings should be in alphabetical order. In a QLDoc, there should be a full stop at the end of each sentence. shorter model summary. change target from getACall() to getACall().getResult(.). better tests
1 parent b147bac commit accc09f

File tree

5 files changed

+56
-49
lines changed

5 files changed

+56
-49
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
---
22
category: minorAnalysis
33
---
4-
* Support for the [Fasthttp framework](https://github.com/valyala/fasthttp/) has been added.
4+
* Support for the [fasthttp framework](https://github.com/valyala/fasthttp/) has been added.

go/ql/lib/ext/github.com.valyala.fasthttp.model.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,4 @@ extensions:
77
- ["github.com/valyala/fasthttp", "URI", False, "SetHostBytes", "", "", "Argument[0]", "Argument[-1]", "taint", "manual"]
88
- ["github.com/valyala/fasthttp", "URI", False, "Update", "", "", "Argument[0]", "Argument[-1]", "taint", "manual"]
99
- ["github.com/valyala/fasthttp", "URI", False, "UpdateBytes", "", "", "Argument[0]", "Argument[-1]", "taint", "manual"]
10-
- ["github.com/valyala/fasthttp", "URI", False, "Parse", "", "", "Argument[0]", "Argument[-1]", "taint", "manual"]
11-
- ["github.com/valyala/fasthttp", "URI", False, "Parse", "", "", "Argument[1]", "Argument[-1]", "taint", "manual"]
10+
- ["github.com/valyala/fasthttp", "URI", False, "Parse", "", "", "Argument[0..1]", "Argument[-1]", "taint", "manual"]

go/ql/lib/semmle/go/frameworks/Fasthttp.qll

Lines changed: 45 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,19 @@ module Fasthttp {
1717
string packagePath() { result = package(v1modulePath(), "") }
1818

1919
/**
20-
* Provide models for sanitizer/Dangerous Functions of fasthttp
20+
* Provide models for sanitizer/Dangerous Functions of fasthttp.
2121
*/
2222
module Functions {
2323
/**
24-
* A function that doesn't sanitize user-provided file paths
24+
* A function that doesn't sanitize user-provided file paths.
2525
*/
2626
class FileSystemAccess extends FileSystemAccess::Range, DataFlow::CallNode {
2727
FileSystemAccess() {
2828
exists(Function f |
2929
f.hasQualifiedName(packagePath(),
3030
[
31-
"ServeFile", "ServeFileUncompressed", "ServeFileBytes", "ServeFileBytesUncompressed",
32-
"SaveMultipartFile"
31+
"SaveMultipartFile", "ServeFile", "ServeFileBytes", "ServeFileBytesUncompressed",
32+
"ServeFileUncompressed"
3333
]) and
3434
this = f.getACall()
3535
)
@@ -39,7 +39,7 @@ module Fasthttp {
3939
}
4040

4141
/**
42-
* A function that can be used as a sanitizer for XSS
42+
* A function that can be used as a sanitizer for XSS.
4343
*/
4444
class HtmlQuoteSanitizer extends SharedXss::Sanitizer {
4545
HtmlQuoteSanitizer() {
@@ -75,13 +75,13 @@ module Fasthttp {
7575

7676
/**
7777
* A function that create initial connection to a TCP address.
78-
* Following Functions only accept TCP address + Port in their first argument
78+
* Following Functions only accept TCP address + Port in their first argument.
7979
*/
8080
class RequestForgerySinkDial extends RequestForgery::Sink {
8181
RequestForgerySinkDial() {
8282
exists(Function f |
8383
f.hasQualifiedName(packagePath(),
84-
["DialDualStack", "Dial", "DialTimeout", "DialDualStackTimeout"]) and
84+
["Dial", "DialDualStack", "DialDualStackTimeout", "DialTimeout"]) and
8585
this = f.getACall().getArgument(0)
8686
)
8787
}
@@ -93,57 +93,57 @@ module Fasthttp {
9393
}
9494

9595
/**
96-
* Provide modeling for fasthttp.URI Type
96+
* Provide modeling for fasthttp.URI Type.
9797
*/
9898
module URI {
9999
/**
100-
* The methods as Remote user controllable source which are part of the incoming URL
100+
* The methods as Remote user controllable source which are part of the incoming URL.
101101
*/
102102
class UntrustedFlowSource extends UntrustedFlowSource::Range instanceof DataFlow::Node {
103103
UntrustedFlowSource() {
104104
exists(Method m |
105105
m.hasQualifiedName(packagePath(), "URI",
106-
["Path", "PathOriginal", "LastPathSegment", "FullURI", "QueryString", "String"]) and
107-
this = m.getACall()
106+
["FullURI", "LastPathSegment", "Path", "PathOriginal", "QueryString", "String"]) and
107+
this = m.getACall().getResult(0)
108108
)
109109
}
110110
}
111111
}
112112

113113
/**
114-
* Provide modeling for fasthttp.Args Type
114+
* Provide modeling for fasthttp.Args Type.
115115
*/
116116
module Args {
117117
/**
118118
* The methods as Remote user controllable source which are part of the incoming URL Parameters.
119119
*
120-
* When support for lambdas has been implemented we should model "VisitAll"
120+
* When support for lambdas has been implemented we should model "VisitAll".
121121
*/
122122
class UntrustedFlowSource extends UntrustedFlowSource::Range instanceof DataFlow::Node {
123123
UntrustedFlowSource() {
124124
exists(Method m |
125125
m.hasQualifiedName(packagePath(), "Args",
126126
["Peek", "PeekBytes", "PeekMulti", "PeekMultiBytes", "QueryString", "String"]) and
127-
this = m.getACall()
127+
this = m.getACall().getResult(0)
128128
)
129129
}
130130
}
131131
}
132132

133133
/**
134-
* Provide modeling for fasthttp.TCPDialer Type
134+
* Provide modeling for fasthttp.TCPDialer Type.
135135
*/
136136
module TcpDialer {
137137
/**
138138
* A method that create initial connection to a TCP address.
139139
* Provide Methods which can be used as dangerous RequestForgery Sinks.
140-
* Following Methods only accept TCP address + Port in their first argument
140+
* Following Methods only accept TCP address + Port in their first argument.
141141
*/
142142
class RequestForgerySinkDial extends RequestForgery::Sink {
143143
RequestForgerySinkDial() {
144144
exists(Method m |
145145
m.hasQualifiedName(packagePath(), "TCPDialer",
146-
["Dial", "DialTimeout", "DialDualStack", "DialDualStackTimeout"]) and
146+
["Dial", "DialDualStack", "DialDualStackTimeout", "DialTimeout"]) and
147147
this = m.getACall().getArgument(0)
148148
)
149149
}
@@ -155,7 +155,7 @@ module Fasthttp {
155155
}
156156

157157
/**
158-
* Provide modeling for fasthttp.Client Type
158+
* Provide modeling for fasthttp.Client Type.
159159
*/
160160
module Client {
161161
/**
@@ -179,7 +179,7 @@ module Fasthttp {
179179
}
180180

181181
/**
182-
* Provide modeling for fasthttp.HostClient Type
182+
* Provide modeling for fasthttp.HostClient Type.
183183
*/
184184
module HostClient {
185185
/**
@@ -204,11 +204,12 @@ module Fasthttp {
204204
}
205205

206206
/**
207-
* Provide modeling for fasthttp.Response Type
207+
* Provide modeling for fasthttp.Response Type.
208208
*/
209209
module Response {
210210
/**
211-
* A Method That send files from its input and it does not check input path against path traversal attacks, so it is a dangerous method
211+
* A Method That send files from its input.
212+
* It does not check the input path against path traversal attacks, So it is a dangerous method.
212213
*/
213214
class FileSystemAccess extends FileSystemAccess::Range, DataFlow::CallNode {
214215
FileSystemAccess() {
@@ -230,8 +231,8 @@ module Fasthttp {
230231
exists(Method m |
231232
m.hasQualifiedName(packagePath(), "Response",
232233
[
233-
"AppendBody", "AppendBodyString", "SetBody", "SetBodyString", "SetBodyRaw",
234-
"SetBodyStream"
234+
"AppendBody", "AppendBodyString", "SetBody", "SetBodyRaw", "SetBodyStream",
235+
"SetBodyString"
235236
]) and
236237
this = m.getACall().getArgument(0)
237238
)
@@ -240,21 +241,21 @@ module Fasthttp {
240241
}
241242

242243
/**
243-
* Provide modeling for fasthttp.Request Type
244+
* Provide modeling for fasthttp.Request Type.
244245
*/
245246
module Request {
246247
/**
247-
* The methods as Remote user controllable source which can be many part of request
248+
* The methods as Remote user controllable source which can be many part of request.
248249
*/
249250
class UntrustedFlowSource extends UntrustedFlowSource::Range instanceof DataFlow::Node {
250251
UntrustedFlowSource() {
251252
exists(Method m |
252253
m.hasQualifiedName(packagePath(), "Request",
253254
[
254-
"Host", "RequestURI", "Body", "BodyGunzip", "BodyInflate", "BodyUnbrotli",
255-
"BodyStream", "BodyUncompressed"
255+
"Body", "BodyGunzip", "BodyInflate", "BodyStream", "BodyUnbrotli", "BodyUncompressed",
256+
"Host", "RequestURI"
256257
]) and
257-
this = m.getACall()
258+
this = m.getACall().getResult(0)
258259
)
259260
}
260261
}
@@ -269,7 +270,7 @@ module Fasthttp {
269270
RequestForgerySink() {
270271
exists(Method m |
271272
m.hasQualifiedName(packagePath(), "Request",
272-
["SetRequestURI", "SetRequestURIBytes", "SetURI", "SetHost", "SetHostBytes"]) and
273+
["SetHost", "SetHostBytes", "SetRequestURI", "SetRequestURIBytes", "SetURI"]) and
273274
this = m.getACall().getArgument(0)
274275
)
275276
}
@@ -281,16 +282,16 @@ module Fasthttp {
281282
}
282283

283284
/**
284-
* Provide modeling for fasthttp.RequestCtx Type
285+
* Provide modeling for fasthttp.RequestCtx Type.
285286
*/
286287
module RequestCtx {
287288
/**
288-
* The Methods that don't sanitize user provided file paths
289+
* The Methods that don't sanitize user provided file paths.
289290
*/
290291
class FileSystemAccess extends FileSystemAccess::Range, DataFlow::CallNode {
291292
FileSystemAccess() {
292293
exists(Method mcn |
293-
mcn.hasQualifiedName(packagePath(), "RequestCtx", ["SendFileBytes", "SendFile"]) and
294+
mcn.hasQualifiedName(packagePath(), "RequestCtx", ["SendFile", "SendFileBytes"]) and
294295
this = mcn.getACall()
295296
)
296297
}
@@ -299,7 +300,7 @@ module Fasthttp {
299300
}
300301

301302
/**
302-
* The Methods that can be dangerous if they take user controlled URL as their first argument
303+
* The Methods that can be dangerous if they take user controlled URL as their first argument.
303304
*/
304305
class Redirect extends Http::Redirect::Range, DataFlow::CallNode {
305306
Redirect() {
@@ -317,17 +318,17 @@ module Fasthttp {
317318
/**
318319
* The methods as Remote user controllable source which are generally related to HTTP request.
319320
*
320-
* When support for lambdas has been implemented we should model "VisitAll", "VisitAllCookie", "VisitAllInOrder", "VisitAllTrailer"
321+
* When support for lambdas has been implemented we should model "VisitAll", "VisitAllCookie", "VisitAllInOrder", "VisitAllTrailer".
321322
*/
322323
class UntrustedFlowSource extends UntrustedFlowSource::Range instanceof DataFlow::Node {
323324
UntrustedFlowSource() {
324325
exists(Method m |
325326
m.hasQualifiedName(packagePath(), "RequestCtx",
326327
[
327-
"Path", "Referer", "PostBody", "RequestBodyStream", "RequestURI", "UserAgent", "Host",
328-
"String"
328+
"Host", "Path", "PostBody", "Referer", "RequestBodyStream", "RequestURI", "String",
329+
"UserAgent"
329330
]) and
330-
this = m.getACall()
331+
this = m.getACall().getResult(0)
331332
)
332333
}
333334
}
@@ -347,24 +348,25 @@ module Fasthttp {
347348
}
348349

349350
/**
350-
* Provide Methods of fasthttp.RequestHeader which mostly used as remote user controlled sources
351+
* Provide Methods of fasthttp.RequestHeader which mostly used as remote user controlled sources.
351352
*/
352353
module RequestHeader {
353354
/**
354355
* The methods as Remote user controllable source which are mostly related to HTTP Request Headers.
355356
*
356-
* When support for lambdas has been implemented we should model "VisitAll", "VisitAllCookie", "VisitAllInOrder", "VisitAllTrailer"
357+
* When support for lambdas has been implemented we should model "VisitAll", "VisitAllCookie", "VisitAllInOrder", "VisitAllTrailer".
357358
*/
358359
class UntrustedFlowSource extends UntrustedFlowSource::Range instanceof DataFlow::Node {
359360
UntrustedFlowSource() {
360361
exists(Method m |
361362
m.hasQualifiedName(packagePath(), "RequestHeader",
362363
[
363-
"Header", "TrailerHeader", "RequestURI", "Host", "UserAgent", "ContentEncoding",
364-
"ContentType", "Cookie", "CookieBytes", "MultipartFormBoundary", "Peek", "PeekAll",
365-
"PeekBytes", "PeekKeys", "PeekTrailerKeys", "Referer", "RawHeaders", "String"
364+
"ContentEncoding", "ContentType", "Cookie", "CookieBytes", "Header", "Host",
365+
"MultipartFormBoundary", "Peek", "PeekAll", "PeekBytes", "PeekKeys",
366+
"PeekTrailerKeys", "RawHeaders", "Referer", "RequestURI", "String", "TrailerHeader",
367+
"UserAgent"
366368
]) and
367-
this = m.getACall()
369+
this = m.getACall().getResult(0)
368370
)
369371
}
370372
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
11
testFailures
2+
| fasthttp.go:165:41:165:86 | comment | Missing result:UntrustedFlowSource="call to BodyInflate" |
3+
| fasthttp.go:166:41:166:87 | comment | Missing result:UntrustedFlowSource="call to BodyUnbrotli" |
4+
| fasthttp.go:168:41:168:91 | comment | Missing result:UntrustedFlowSource="call to BodyUncompressed" |
25
failures

go/ql/test/library-tests/semmle/go/frameworks/Fasthttp/fasthttp.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,12 @@ func fasthttpClient() {
4040
uri4 := fasthttp.AcquireURI()
4141
uri4.UpdateBytes(source().([]byte))
4242
sink(uri4) // $ hasTaintFlow="uri4"
43-
uri5 := fasthttp.AcquireURI()
44-
uri5.Parse(source().([]byte), source().([]byte))
45-
sink(uri5) // $ hasTaintFlow="uri5"
43+
uri5 := fasthttp.AcquireURI()
44+
uri5.Parse(source().([]byte), nil)
45+
sink(uri5) // $ hasTaintFlow="uri5"
46+
uri6 := fasthttp.AcquireURI()
47+
uri6.Parse(nil, source().([]byte))
48+
sink(uri6) // $ hasTaintFlow="uri6"
4649

4750
resByte := make([]byte, 1000)
4851
userInput = "http://127.0.0.1:8909"

0 commit comments

Comments
 (0)