Skip to content

Commit 23d4d03

Browse files
committed
C++: Different approach to sensitive exprs.
1 parent 65f4ccc commit 23d4d03

File tree

3 files changed

+124
-245
lines changed

3 files changed

+124
-245
lines changed

cpp/ql/src/Security/CWE/CWE-311/CleartextTransmission.ql

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,21 @@ import semmle.code.cpp.valuenumbering.GlobalValueNumbering
1818
import semmle.code.cpp.models.interfaces.FlowSource
1919
import DataFlow::PathGraph
2020

21+
/**
22+
* A DataFlow node corresponding to a variable or function call that
23+
* might contain or return a password or other sensitive information.
24+
*/
25+
class SensitiveNode extends DataFlow::Node {
26+
SensitiveNode() {
27+
this.asExpr() = any(SensitiveVariable sv).getInitializer().getExpr() or
28+
this.asExpr().(VariableAccess).getTarget() =
29+
any(SensitiveVariable sv).(GlobalOrNamespaceVariable) or
30+
this.asUninitialized() instanceof SensitiveVariable or
31+
this.asParameter() instanceof SensitiveVariable or
32+
this.asExpr().(FunctionCall).getTarget() instanceof SensitiveFunction
33+
}
34+
}
35+
2136
/**
2237
* A function call that sends or receives data over a network.
2338
*
@@ -129,25 +144,19 @@ class Encrypted extends Expr {
129144
class FromSensitiveConfiguration extends TaintTracking::Configuration {
130145
FromSensitiveConfiguration() { this = "FromSensitiveConfiguration" }
131146

132-
override predicate isSource(DataFlow::Node source) { source.asExpr() instanceof SensitiveExpr }
147+
override predicate isSource(DataFlow::Node source) { source instanceof SensitiveNode }
133148

134149
override predicate isSink(DataFlow::Node sink) {
135150
sink.asExpr() = any(NetworkSendRecv nsr | nsr.checkSocket()).getDataExpr()
136151
or
137152
sink.asExpr() instanceof Encrypted
138-
or
139-
sink.asExpr() instanceof SensitiveExpr
140153
}
141154

142155
override predicate isAdditionalTaintStep(DataFlow::Node node1, DataFlow::Node node2) {
143156
// flow from pre-update to post-update of the source
144157
isSource(node1) and
145158
node2.(DataFlow::PostUpdateNode).getPreUpdateNode() = node1
146159
or
147-
// flow from pre-update to post-update of the sink (in case we can reach other sinks)
148-
isSink(node1) and
149-
node2.(DataFlow::PostUpdateNode).getPreUpdateNode() = node1
150-
or
151160
// flow through encryption functions to the return value (in case we can reach other sinks)
152161
node2.asExpr().(Encrypted).(FunctionCall).getAnArgument() = node1.asExpr()
153162
}
@@ -166,12 +175,6 @@ where
166175
config.hasFlow(source.getNode(), encrypted) and
167176
encrypted.asExpr() instanceof Encrypted
168177
) and
169-
// only use the 'first' sensitive expression
170-
not exists(DataFlow::Node sensitive |
171-
config.hasFlow(sensitive, source.getNode()) and
172-
sensitive.asExpr() instanceof SensitiveExpr and
173-
not source.getNode() = sensitive
174-
) and
175178
// construct result
176179
if networkSendRecv instanceof NetworkSend
177180
then

0 commit comments

Comments
 (0)