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

Commit 42d6250

Browse files
committed
Add modern-API variants of tests
1 parent 8682eb9 commit 42d6250

3 files changed

Lines changed: 77 additions & 0 deletions

File tree

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,12 @@
3131
| testModernApi.go:75:53:75:57 | query | testModernApi.go:74:2:74:11 | definition of emptyArray |
3232
| testModernApi.go:75:53:75:57 | query | testModernApi.go:75:2:75:58 | ... := ...[0] |
3333
| testModernApi.go:87:12:87:16 | query | testModernApi.go:87:12:87:31 | call to ProtoReflect |
34+
| testModernApi.go:101:24:101:35 | selection of Alerts | testModernApi.go:101:17:101:43 | call to append |
35+
| testModernApi.go:101:38:101:42 | alert | testModernApi.go:101:17:101:43 | call to append |
36+
| testModernApi.go:103:33:103:37 | query | testModernApi.go:103:2:103:38 | ... := ...[0] |
37+
| testModernApi.go:112:24:112:35 | selection of Alerts | testModernApi.go:112:17:112:43 | call to append |
38+
| testModernApi.go:112:38:112:42 | alert | testModernApi.go:112:17:112:43 | call to append |
39+
| testModernApi.go:115:33:115:37 | query | testModernApi.go:115:2:115:38 | ... := ...[0] |
40+
| 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] |

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,8 @@
1515
| testModernApi.go:47:23:47:42 | call to getUntrustedString : string | testModernApi.go:54:12:54:21 | serialized |
1616
| testModernApi.go:59:22:59:41 | call to getUntrustedString : string | testModernApi.go:64:12:64:21 | serialized |
1717
| testModernApi.go:71:22:71:41 | call to getUntrustedString : string | testModernApi.go:77:12:77:21 | serialized |
18+
| testModernApi.go:98:14:98:33 | call to getUntrustedString : string | testModernApi.go:105:12:105:21 | serialized |
19+
| testModernApi.go:113:24:113:43 | call to getUntrustedString : string | testModernApi.go:117:12:117:21 | serialized |
20+
| 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 |

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

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,3 +92,66 @@ func testMarshalState() {
9292

9393
sinkBytes(serialized.Buf)
9494
}
95+
96+
func testTaintedSubmessageModern() {
97+
alert := &query.Query_Alert{}
98+
alert.Msg = getUntrustedString()
99+
100+
query := &query.Query{}
101+
query.Alerts = append(query.Alerts, alert)
102+
103+
serialized, _ := proto.Marshal(query)
104+
105+
sinkBytes(serialized) // BAD
106+
}
107+
108+
func testTaintedSubmessageInPlaceModern() {
109+
alert := &query.Query_Alert{}
110+
111+
query := &query.Query{}
112+
query.Alerts = append(query.Alerts, alert)
113+
query.Alerts[0].Msg = getUntrustedString()
114+
115+
serialized, _ := proto.Marshal(query)
116+
117+
sinkBytes(serialized) // BAD
118+
}
119+
120+
func testUnmarshalTaintedSubmessageModern() {
121+
untrustedSerialized := getUntrustedBytes()
122+
query := &query.Query{}
123+
proto.Unmarshal(untrustedSerialized, query)
124+
125+
sinkString(query.Alerts[0].Msg) // BAD
126+
}
127+
128+
// This test should be ok, but is flagged because writing taint to a field of a Message
129+
// taints the entire Message structure in our current implementation.
130+
func testFieldConflationFalsePositiveModern() {
131+
query := &query.Query{}
132+
query.Description = getUntrustedString()
133+
sinkString(query.Id) // OK (but incorrectly tainted)
134+
}
135+
136+
// This test should be ok, but it flagged because our current implementation doesn't notice
137+
// that the taint applied to `query` is overwritten.
138+
func testMessageReuseFalsePositiveModern() {
139+
query := &query.Query{}
140+
query.Description = getUntrustedString()
141+
query.Description = "clean"
142+
143+
serialized, _ := proto.Marshal(query)
144+
145+
sinkBytes(serialized) // OK (but incorrectly tainted)
146+
}
147+
148+
// This test should be flagged, but we don't notice tainting via an alias of a field.
149+
func testSubmessageAliasFalseNegativeModern() {
150+
query := &query.Query{}
151+
alias := &query.Description
152+
*alias = getUntrustedString()
153+
154+
serialized, _ := proto.Marshal(query)
155+
156+
sinkBytes(serialized) // BAD (but not noticed by our current implementation)
157+
}

0 commit comments

Comments
 (0)