@@ -18,6 +18,21 @@ import semmle.code.cpp.valuenumbering.GlobalValueNumbering
18
18
import semmle.code.cpp.models.interfaces.FlowSource
19
19
import DataFlow:: PathGraph
20
20
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
+
21
36
/**
22
37
* A function call that sends or receives data over a network.
23
38
*
@@ -129,25 +144,19 @@ class Encrypted extends Expr {
129
144
class FromSensitiveConfiguration extends TaintTracking:: Configuration {
130
145
FromSensitiveConfiguration ( ) { this = "FromSensitiveConfiguration" }
131
146
132
- override predicate isSource ( DataFlow:: Node source ) { source . asExpr ( ) instanceof SensitiveExpr }
147
+ override predicate isSource ( DataFlow:: Node source ) { source instanceof SensitiveNode }
133
148
134
149
override predicate isSink ( DataFlow:: Node sink ) {
135
150
sink .asExpr ( ) = any ( NetworkSendRecv nsr | nsr .checkSocket ( ) ) .getDataExpr ( )
136
151
or
137
152
sink .asExpr ( ) instanceof Encrypted
138
- or
139
- sink .asExpr ( ) instanceof SensitiveExpr
140
153
}
141
154
142
155
override predicate isAdditionalTaintStep ( DataFlow:: Node node1 , DataFlow:: Node node2 ) {
143
156
// flow from pre-update to post-update of the source
144
157
isSource ( node1 ) and
145
158
node2 .( DataFlow:: PostUpdateNode ) .getPreUpdateNode ( ) = node1
146
159
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
151
160
// flow through encryption functions to the return value (in case we can reach other sinks)
152
161
node2 .asExpr ( ) .( Encrypted ) .( FunctionCall ) .getAnArgument ( ) = node1 .asExpr ( )
153
162
}
@@ -166,12 +175,6 @@ where
166
175
config .hasFlow ( source .getNode ( ) , encrypted ) and
167
176
encrypted .asExpr ( ) instanceof Encrypted
168
177
) 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
175
178
// construct result
176
179
if networkSendRecv instanceof NetworkSend
177
180
then
0 commit comments