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

Commit 7a42992

Browse files
committed
Add taint-tracking for encoding/gob
1 parent 57518c7 commit 7a42992

File tree

3 files changed

+170
-0
lines changed

3 files changed

+170
-0
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import semmle.go.frameworks.stdlib.EncodingBase32
2222
import semmle.go.frameworks.stdlib.EncodingBase64
2323
import semmle.go.frameworks.stdlib.EncodingBinary
2424
import semmle.go.frameworks.stdlib.EncodingCsv
25+
import semmle.go.frameworks.stdlib.EncodingGob
2526
import semmle.go.frameworks.stdlib.Path
2627
import semmle.go.frameworks.stdlib.PathFilepath
2728
import semmle.go.frameworks.stdlib.Reflect
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
/**
2+
* Provides classes modeling security-relevant aspects of the `encoding/gob` package.
3+
*/
4+
5+
import go
6+
7+
/** Provides models of commonly used functions in the `encoding/gob` package. */
8+
module EncodingGob {
9+
private class FunctionModels extends TaintTracking::FunctionModel {
10+
FunctionInput inp;
11+
FunctionOutput outp;
12+
13+
FunctionModels() {
14+
// signature: func NewDecoder(r io.Reader) *Decoder
15+
hasQualifiedName("encoding/gob", "NewDecoder") and
16+
(inp.isParameter(0) and outp.isResult())
17+
or
18+
// signature: func NewEncoder(w io.Writer) *Encoder
19+
hasQualifiedName("encoding/gob", "NewEncoder") and
20+
(inp.isResult() and outp.isParameter(0))
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 (*Decoder).Decode(e interface{}) error
34+
this.hasQualifiedName("encoding/gob", "Decoder", "Decode") and
35+
(inp.isReceiver() and outp.isParameter(0))
36+
or
37+
// signature: func (*Decoder).DecodeValue(v reflect.Value) error
38+
this.hasQualifiedName("encoding/gob", "Decoder", "DecodeValue") and
39+
(inp.isReceiver() and outp.isParameter(0))
40+
or
41+
// signature: func (*Encoder).Encode(e interface{}) error
42+
this.hasQualifiedName("encoding/gob", "Encoder", "Encode") and
43+
(inp.isParameter(0) and outp.isReceiver())
44+
or
45+
// signature: func (*Encoder).EncodeValue(value reflect.Value) error
46+
this.hasQualifiedName("encoding/gob", "Encoder", "EncodeValue") and
47+
(inp.isParameter(0) and outp.isReceiver())
48+
or
49+
// signature: func (GobDecoder).GobDecode([]byte) error
50+
this.implements("encoding/gob", "GobDecoder", "GobDecode") and
51+
(inp.isParameter(0) and outp.isReceiver())
52+
or
53+
// signature: func (GobEncoder).GobEncode() ([]byte, error)
54+
this.implements("encoding/gob", "GobEncoder", "GobEncode") and
55+
(inp.isReceiver() and outp.isResult(0))
56+
}
57+
58+
override predicate hasTaintFlow(FunctionInput input, FunctionOutput output) {
59+
input = inp and output = outp
60+
}
61+
}
62+
}

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

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