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

Commit c44d426

Browse files
committed
Add taint-tracking for mime package.
1 parent 25e4245 commit c44d426

File tree

3 files changed

+139
-0
lines changed

3 files changed

+139
-0
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import semmle.go.frameworks.stdlib.CompressFlate
1212
import semmle.go.frameworks.stdlib.CompressGzip
1313
import semmle.go.frameworks.stdlib.CompressLzw
1414
import semmle.go.frameworks.stdlib.CompressZlib
15+
import semmle.go.frameworks.stdlib.Mime
1516
import semmle.go.frameworks.stdlib.Path
1617
import semmle.go.frameworks.stdlib.PathFilepath
1718

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/**
2+
* Provides classes modeling security-relevant aspects of the `mime` package.
3+
*/
4+
5+
import go
6+
7+
/** Provides models of commonly used functions in the `mime` package. */
8+
module Mime {
9+
private class FunctionModels extends TaintTracking::FunctionModel {
10+
FunctionInput inp;
11+
FunctionOutput outp;
12+
13+
FunctionModels() {
14+
// signature: func FormatMediaType(t string, param map[string]string) string
15+
hasQualifiedName("mime", "FormatMediaType") and
16+
(inp.isParameter(_) and outp.isResult())
17+
or
18+
// signature: func ParseMediaType(v string) (mediatype string, params map[string]string, err error)
19+
hasQualifiedName("mime", "ParseMediaType") and
20+
(inp.isParameter(0) and outp.isResult([0, 1]))
21+
}
22+
23+
override predicate hasTaintFlow(FunctionInput input, FunctionOutput output) {
24+
input = inp and output = outp
25+
}
26+
}
27+
28+
private class MethodModels extends TaintTracking::FunctionModel, Method {
29+
FunctionInput inp;
30+
FunctionOutput outp;
31+
32+
MethodModels() {
33+
// signature: func (*WordDecoder).Decode(word string) (string, error)
34+
this.hasQualifiedName("mime", "WordDecoder", "Decode") and
35+
(inp.isParameter(0) and outp.isResult(0))
36+
or
37+
// signature: func (*WordDecoder).DecodeHeader(header string) (string, error)
38+
this.hasQualifiedName("mime", "WordDecoder", "DecodeHeader") and
39+
(inp.isParameter(0) and outp.isResult(0))
40+
or
41+
// signature: func (WordEncoder).Encode(charset string, s string) string
42+
this.hasQualifiedName("mime", "WordEncoder", "Encode") and
43+
(inp.isParameter(1) and outp.isResult())
44+
}
45+
46+
override predicate hasTaintFlow(FunctionInput input, FunctionOutput output) {
47+
input = inp and output = outp
48+
}
49+
}
50+
}

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

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