Skip to content
This repository was archived by the owner on Jan 5, 2023. It is now read-only.

Commit e6cb8fe

Browse files
committed
Add taint-tracking for package net/http/httputil
1 parent 85f9760 commit e6cb8fe

File tree

3 files changed

+325
-0
lines changed

3 files changed

+325
-0
lines changed

ql/src/semmle/go/frameworks/Stdlib.qll

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import semmle.go.frameworks.stdlib.Html
3131
import semmle.go.frameworks.stdlib.HtmlTemplate
3232
import semmle.go.frameworks.stdlib.Net
3333
import semmle.go.frameworks.stdlib.NetHttp
34+
import semmle.go.frameworks.stdlib.NetHttpHttputil
3435
import semmle.go.frameworks.stdlib.Path
3536
import semmle.go.frameworks.stdlib.PathFilepath
3637
import semmle.go.frameworks.stdlib.Reflect
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
/**
2+
* Provides classes modeling security-relevant aspects of the `net/http/httputil` package.
3+
*/
4+
5+
import go
6+
7+
/** Provides models of commonly used functions in the `net/http/httputil` package. */
8+
module NetHttpHttputil {
9+
private class FunctionModels extends TaintTracking::FunctionModel {
10+
FunctionInput inp;
11+
FunctionOutput outp;
12+
13+
FunctionModels() {
14+
// signature: func DumpRequest(req *net/http.Request, body bool) ([]byte, error)
15+
hasQualifiedName("net/http/httputil", "DumpRequest") and
16+
(inp.isParameter(0) and outp.isResult(0))
17+
or
18+
// signature: func DumpRequestOut(req *net/http.Request, body bool) ([]byte, error)
19+
hasQualifiedName("net/http/httputil", "DumpRequestOut") and
20+
(inp.isParameter(0) and outp.isResult(0))
21+
or
22+
// signature: func DumpResponse(resp *net/http.Response, body bool) ([]byte, error)
23+
hasQualifiedName("net/http/httputil", "DumpResponse") and
24+
(inp.isParameter(0) and outp.isResult(0))
25+
or
26+
// signature: func NewChunkedReader(r io.Reader) io.Reader
27+
hasQualifiedName("net/http/httputil", "NewChunkedReader") and
28+
(inp.isParameter(0) and outp.isResult())
29+
or
30+
// signature: func NewChunkedWriter(w io.Writer) io.WriteCloser
31+
hasQualifiedName("net/http/httputil", "NewChunkedWriter") and
32+
(inp.isResult() and outp.isParameter(0))
33+
or
34+
// signature: func NewClientConn(c net.Conn, r *bufio.Reader) *ClientConn
35+
hasQualifiedName("net/http/httputil", "NewClientConn") and
36+
(
37+
inp.isParameter(_) and outp.isResult()
38+
or
39+
inp.isResult() and outp.isParameter(0)
40+
)
41+
or
42+
// signature: func NewProxyClientConn(c net.Conn, r *bufio.Reader) *ClientConn
43+
hasQualifiedName("net/http/httputil", "NewProxyClientConn") and
44+
(
45+
inp.isParameter(_) and outp.isResult()
46+
or
47+
inp.isResult() and outp.isParameter(0)
48+
)
49+
}
50+
51+
override predicate hasTaintFlow(FunctionInput input, FunctionOutput output) {
52+
input = inp and output = outp
53+
}
54+
}
55+
56+
private class MethodModels extends TaintTracking::FunctionModel, Method {
57+
FunctionInput inp;
58+
FunctionOutput outp;
59+
60+
MethodModels() {
61+
// signature: func (*ClientConn).Hijack() (c net.Conn, r *bufio.Reader)
62+
this.hasQualifiedName("net/http/httputil", "ClientConn", "Hijack") and
63+
(
64+
inp.isReceiver() and outp.isResult(_)
65+
or
66+
inp.isResult(0) and outp.isReceiver()
67+
)
68+
or
69+
// signature: func (*ServerConn).Hijack() (net.Conn, *bufio.Reader)
70+
this.hasQualifiedName("net/http/httputil", "ServerConn", "Hijack") and
71+
(
72+
inp.isReceiver() and outp.isResult(_)
73+
or
74+
inp.isResult(0) and outp.isReceiver()
75+
)
76+
or
77+
// signature: func (BufferPool).Get() []byte
78+
this.implements("net/http/httputil", "BufferPool", "Get") and
79+
(inp.isReceiver() and outp.isResult())
80+
or
81+
// signature: func (BufferPool).Put([]byte)
82+
this.implements("net/http/httputil", "BufferPool", "Put") and
83+
(inp.isParameter(0) and outp.isReceiver())
84+
}
85+
86+
override predicate hasTaintFlow(FunctionInput input, FunctionOutput output) {
87+
input = inp and output = outp
88+
}
89+
}
90+
}

ql/test/library-tests/semmle/go/frameworks/StdlibTaintFlow/NetHttpHttputil.go

Lines changed: 234 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)