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

Commit 8058d09

Browse files
committed
Model and test UnmarshalOptions.Unmarshal
Support for UnmarshalOptions.UnmarshalState is dropped for now as too hard to model.
1 parent c2ff2df commit 8058d09

6 files changed

Lines changed: 50 additions & 10 deletions

File tree

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -77,13 +77,13 @@ module Protobuf {
7777
}
7878
}
7979

80-
/** The `Unmarshal` or `UnmarshalState` functions in the protobuf packages. */
80+
/** The `Unmarshal` function in the protobuf packages. */
8181
class UnmarshalFunction extends TaintTracking::FunctionModel, UnmarshalingFunction::Range {
82-
string name;
83-
8482
UnmarshalFunction() {
85-
name = ["Unmarshal", "UnmarshalState"] and
86-
this.hasQualifiedName(protobufPackages(), name)
83+
this.hasQualifiedName(protobufPackages(), "Unmarshal") or
84+
this
85+
.(Method)
86+
.hasQualifiedName("google.golang.org/protobuf/proto", "UnmarshalOptions", "Unmarshal")
8787
}
8888

8989
override predicate hasTaintFlow(DataFlow::FunctionInput inp, DataFlow::FunctionOutput outp) {

ql/test/library-tests/semmle/go/frameworks/Protobuf/FunctionModel.expected

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
| testModernApi.go:112:38:112:42 | alert | testModernApi.go:112:17:112:43 | call to append |
3939
| testModernApi.go:115:33:115:37 | query | testModernApi.go:115:2:115:38 | ... := ...[0] |
4040
| testModernApi.go:123:18:123:36 | untrustedSerialized | testModernApi.go:122:2:122:6 | definition of query |
41-
| testModernApi.go:143:33:143:37 | query | testModernApi.go:143:2:143:38 | ... := ...[0] |
42-
| testModernApi.go:154:33:154:37 | query | testModernApi.go:154:2:154:38 | ... := ...[0] |
43-
| testModernApi.go:168:12:168:16 | query | testModernApi.go:168:12:168:31 | call to ProtoReflect |
41+
| testModernApi.go:133:20:133:38 | untrustedSerialized | testModernApi.go:132:2:132:6 | definition of query |
42+
| testModernApi.go:153:33:153:37 | query | testModernApi.go:153:2:153:38 | ... := ...[0] |
43+
| testModernApi.go:164:33:164:37 | query | testModernApi.go:164:2:164:38 | ... := ...[0] |
44+
| testModernApi.go:178:12:178:16 | query | testModernApi.go:178:12:178:31 | call to ProtoReflect |

ql/test/library-tests/semmle/go/frameworks/Protobuf/TaintFlows.expected

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,6 @@
1818
| testModernApi.go:98:14:98:33 | call to getUntrustedString : string | testModernApi.go:105:12:105:21 | serialized |
1919
| testModernApi.go:113:24:113:43 | call to getUntrustedString : string | testModernApi.go:117:12:117:21 | serialized |
2020
| testModernApi.go:121:25:121:43 | call to getUntrustedBytes : slice type | testModernApi.go:125:13:125:31 | selection of Msg |
21-
| testModernApi.go:132:22:132:41 | call to getUntrustedString : string | testModernApi.go:133:13:133:20 | selection of Id |
22-
| testModernApi.go:140:22:140:41 | call to getUntrustedString : string | testModernApi.go:145:12:145:21 | serialized |
21+
| testModernApi.go:131:25:131:43 | call to getUntrustedBytes : slice type | testModernApi.go:135:13:135:29 | selection of Description |
22+
| testModernApi.go:142:22:142:41 | call to getUntrustedString : string | testModernApi.go:143:13:143:20 | selection of Id |
23+
| testModernApi.go:150:22:150:41 | call to getUntrustedString : string | testModernApi.go:155:12:155:21 | serialized |

ql/test/library-tests/semmle/go/frameworks/Protobuf/testModernApi.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,16 @@ func testUnmarshalTaintedSubmessageModern() {
125125
sinkString(query.Alerts[0].Msg) // BAD
126126
}
127127

128+
func testUnmarshalOptions() {
129+
options := proto.UnmarshalOptions{}
130+
131+
untrustedSerialized := getUntrustedBytes()
132+
query := &query.Query{}
133+
options.Unmarshal(untrustedSerialized, query)
134+
135+
sinkString(query.Description) // BAD
136+
}
137+
128138
// This test should be ok, but is flagged because writing taint to a field of a Message
129139
// taints the entire Message structure in our current implementation.
130140
func testFieldConflationFalsePositiveModern() {

ql/test/library-tests/semmle/go/frameworks/Protobuf/vendor/google.golang.org/protobuf/proto/stub.go

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

ql/test/library-tests/semmle/go/frameworks/Protobuf/vendor/google.golang.org/protobuf/reflect/protoreflect/stub.go

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