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

Commit 8682eb9

Browse files
committed
Add tests showing imprecision of our current implementation
1 parent a832342 commit 8682eb9

3 files changed

Lines changed: 35 additions & 0 deletions

File tree

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
| testDeprecatedApi.go:84:38:84:42 | alert | testDeprecatedApi.go:84:17:84:43 | call to append |
1818
| testDeprecatedApi.go:87:33:87:37 | query | testDeprecatedApi.go:87:2:87:38 | ... := ...[0] |
1919
| testDeprecatedApi.go:95:18:95:36 | untrustedSerialized | testDeprecatedApi.go:94:2:94:6 | definition of query |
20+
| testDeprecatedApi.go:115:33:115:37 | query | testDeprecatedApi.go:115:2:115:38 | ... := ...[0] |
21+
| testDeprecatedApi.go:126:33:126:37 | query | testDeprecatedApi.go:126:2:126:38 | ... := ...[0] |
2022
| testModernApi.go:13:33:13:37 | query | testModernApi.go:13:2:13:38 | ... := ...[0] |
2123
| testModernApi.go:22:28:22:32 | query | testModernApi.go:22:16:22:33 | call to Clone |
2224
| testModernApi.go:24:33:24:42 | queryClone | testModernApi.go:24:2:24:43 | ... := ...[0] |

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
| testDeprecatedApi.go:70:14:70:33 | call to getUntrustedString : string | testDeprecatedApi.go:77:12:77:21 | serialized |
77
| testDeprecatedApi.go:85:24:85:43 | call to getUntrustedString : string | testDeprecatedApi.go:89:12:89:21 | serialized |
88
| testDeprecatedApi.go:93:25:93:43 | call to getUntrustedBytes : slice type | testDeprecatedApi.go:97:13:97:31 | selection of Msg |
9+
| testDeprecatedApi.go:104:22:104:41 | call to getUntrustedString : string | testDeprecatedApi.go:105:13:105:20 | selection of Id |
10+
| testDeprecatedApi.go:112:22:112:41 | call to getUntrustedString : string | testDeprecatedApi.go:117:12:117:21 | serialized |
911
| testModernApi.go:11:22:11:41 | call to getUntrustedString : string | testModernApi.go:15:12:15:21 | serialized |
1012
| testModernApi.go:20:22:20:41 | call to getUntrustedString : string | testModernApi.go:26:12:26:21 | serialized |
1113
| testModernApi.go:30:25:30:43 | call to getUntrustedBytes : slice type | testModernApi.go:34:13:34:29 | selection of Description |

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

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,3 +96,34 @@ func testUnmarshalTaintedSubmessage() {
9696

9797
sinkString(query.Alerts[0].Msg) // BAD
9898
}
99+
100+
// This test should be ok, but is flagged because writing taint to a field of a Message
101+
// taints the entire Message structure in our current implementation.
102+
func testFieldConflationFalsePositive() {
103+
query := &query.Query{}
104+
query.Description = getUntrustedString()
105+
sinkString(query.Id) // OK (but incorrectly tainted)
106+
}
107+
108+
// This test should be ok, but it flagged because our current implementation doesn't notice
109+
// that the taint applied to `query` is overwritten.
110+
func testMessageReuseFalsePositive() {
111+
query := &query.Query{}
112+
query.Description = getUntrustedString()
113+
query.Description = "clean"
114+
115+
serialized, _ := proto.Marshal(query)
116+
117+
sinkBytes(serialized) // OK (but incorrectly tainted)
118+
}
119+
120+
// This test should be flagged, but we don't notice tainting via an alias of a field.
121+
func testSubmessageAliasFalseNegative() {
122+
query := &query.Query{}
123+
alias := &query.Description
124+
*alias = getUntrustedString()
125+
126+
serialized, _ := proto.Marshal(query)
127+
128+
sinkBytes(serialized) // BAD (but not noticed by our current implementation)
129+
}

0 commit comments

Comments
 (0)