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

Commit 75751d7

Browse files
committed
Add taint-tracking for package net/mail
1 parent e6cb8fe commit 75751d7

File tree

3 files changed

+134
-0
lines changed

3 files changed

+134
-0
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import semmle.go.frameworks.stdlib.HtmlTemplate
3232
import semmle.go.frameworks.stdlib.Net
3333
import semmle.go.frameworks.stdlib.NetHttp
3434
import semmle.go.frameworks.stdlib.NetHttpHttputil
35+
import semmle.go.frameworks.stdlib.NetMail
3536
import semmle.go.frameworks.stdlib.Path
3637
import semmle.go.frameworks.stdlib.PathFilepath
3738
import semmle.go.frameworks.stdlib.Reflect
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/**
2+
* Provides classes modeling security-relevant aspects of the `net/mail` package.
3+
*/
4+
5+
import go
6+
7+
/** Provides models of commonly used functions in the `net/mail` package. */
8+
module NetMail {
9+
private class FunctionModels extends TaintTracking::FunctionModel {
10+
FunctionInput inp;
11+
FunctionOutput outp;
12+
13+
FunctionModels() {
14+
// signature: func ParseAddress(address string) (*Address, error)
15+
hasQualifiedName("net/mail", "ParseAddress") and
16+
(inp.isParameter(0) and outp.isResult(0))
17+
or
18+
// signature: func ParseAddressList(list string) ([]*Address, error)
19+
hasQualifiedName("net/mail", "ParseAddressList") and
20+
(inp.isParameter(0) and outp.isResult(0))
21+
or
22+
// signature: func ReadMessage(r io.Reader) (msg *Message, err error)
23+
hasQualifiedName("net/mail", "ReadMessage") and
24+
(inp.isParameter(0) and outp.isResult(0))
25+
}
26+
27+
override predicate hasTaintFlow(FunctionInput input, FunctionOutput output) {
28+
input = inp and output = outp
29+
}
30+
}
31+
32+
private class MethodModels extends TaintTracking::FunctionModel, Method {
33+
FunctionInput inp;
34+
FunctionOutput outp;
35+
36+
MethodModels() {
37+
// signature: func (*AddressParser).Parse(address string) (*Address, error)
38+
this.hasQualifiedName("net/mail", "AddressParser", "Parse") and
39+
(inp.isParameter(0) and outp.isResult(0))
40+
or
41+
// signature: func (*AddressParser).ParseList(list string) ([]*Address, error)
42+
this.hasQualifiedName("net/mail", "AddressParser", "ParseList") and
43+
(inp.isParameter(0) and outp.isResult(0))
44+
or
45+
// signature: func (Header).Get(key string) string
46+
this.hasQualifiedName("net/mail", "Header", "Get") and
47+
(inp.isReceiver() and outp.isResult())
48+
}
49+
50+
override predicate hasTaintFlow(FunctionInput input, FunctionOutput output) {
51+
input = inp and output = outp
52+
}
53+
}
54+
}

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

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