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

Commit 3acb7a5

Browse files
committed
Add taint-tracking for crypto/tls package
1 parent 5e0e3cc commit 3acb7a5

File tree

3 files changed

+153
-0
lines changed

3 files changed

+153
-0
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import semmle.go.frameworks.stdlib.Fmt
1616
import semmle.go.frameworks.stdlib.Crypto
1717
import semmle.go.frameworks.stdlib.CryptoCipher
1818
import semmle.go.frameworks.stdlib.CryptoRsa
19+
import semmle.go.frameworks.stdlib.CryptoTls
1920
import semmle.go.frameworks.stdlib.Mime
2021
import semmle.go.frameworks.stdlib.MimeMultipart
2122
import semmle.go.frameworks.stdlib.MimeQuotedprintable
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
/**
2+
* Provides classes modeling security-relevant aspects of the `crypto/tls` package.
3+
*/
4+
5+
import go
6+
7+
/** Provides models of commonly used functions in the `crypto/tls` package. */
8+
module CryptoTls {
9+
private class FunctionModels extends TaintTracking::FunctionModel {
10+
FunctionInput inp;
11+
FunctionOutput outp;
12+
13+
FunctionModels() {
14+
// signature: func Client(conn net.Conn, config *Config) *Conn
15+
hasQualifiedName("crypto/tls", "Client") and
16+
(
17+
inp.isParameter(0) and outp.isResult()
18+
or
19+
inp.isResult() and outp.isParameter(0)
20+
)
21+
or
22+
// signature: func NewListener(inner net.Listener, config *Config) net.Listener
23+
hasQualifiedName("crypto/tls", "NewListener") and
24+
(inp.isParameter(0) and outp.isResult())
25+
or
26+
// signature: func Server(conn net.Conn, config *Config) *Conn
27+
hasQualifiedName("crypto/tls", "Server") and
28+
(
29+
inp.isParameter(0) and outp.isResult()
30+
or
31+
inp.isResult() and outp.isParameter(0)
32+
)
33+
}
34+
35+
override predicate hasTaintFlow(FunctionInput input, FunctionOutput output) {
36+
input = inp and output = outp
37+
}
38+
}
39+
40+
private class MethodModels extends TaintTracking::FunctionModel, Method {
41+
FunctionInput inp;
42+
FunctionOutput outp;
43+
44+
MethodModels() {
45+
// signature: func (*Conn).Read(b []byte) (int, error)
46+
this.hasQualifiedName("crypto/tls", "Conn", "Read") and
47+
(inp.isReceiver() and outp.isParameter(0))
48+
or
49+
// signature: func (*Conn).Write(b []byte) (int, error)
50+
this.hasQualifiedName("crypto/tls", "Conn", "Write") and
51+
(inp.isParameter(0) and outp.isReceiver())
52+
}
53+
54+
override predicate hasTaintFlow(FunctionInput input, FunctionOutput output) {
55+
input = inp and output = outp
56+
}
57+
}
58+
}

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

Lines changed: 94 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)