@@ -168,22 +168,9 @@ module CleartextLogging {
168
168
}
169
169
170
170
/**
171
- * An hash with a value that may contain password information
172
- *
173
- * This is a source since logging a hash will show the pairs present.
171
+ * A write to a hash entry with a value that may contain password information.
174
172
*/
175
- private abstract class HashPasswordSource extends Source {
176
- /** Gets the name of the key */
177
- abstract string getName ( ) ;
178
-
179
- /**
180
- * Gets the name of the hash variable that this password source is assigned
181
- * to, if applicable.
182
- */
183
- abstract LocalVariable getVariable ( ) ;
184
- }
185
-
186
- private class HashKeyWritePasswordSource extends HashPasswordSource {
173
+ private class HashKeyWritePasswordSource extends Source {
187
174
private string name ;
188
175
private DataFlow:: ExprNode recv ;
189
176
@@ -202,18 +189,27 @@ module CleartextLogging {
202
189
}
203
190
204
191
override string describe ( ) { result = "an write to " + name }
205
- override string getName ( ) { result = name }
206
- override LocalVariable getVariable ( ) {
192
+
193
+ /** Gets the name of the key */
194
+ string getName ( ) { result = name }
195
+
196
+ /**
197
+ * Gets the name of the hash variable that this password source is assigned
198
+ * to, if applicable.
199
+ */
200
+ LocalVariable getVariable ( ) {
207
201
result = recv .getExprNode ( ) .getExpr ( ) .( VariableReadAccess ) .getVariable ( )
208
202
}
209
203
}
210
204
211
- private class HashLiteralPasswordSource extends HashPasswordSource {
205
+ /**
206
+ * A hash literal with an entry that may contain a password
207
+ */
208
+ private class HashLiteralPasswordSource extends Source {
212
209
private string name ;
213
- private HashLiteral lit ;
214
210
215
211
HashLiteralPasswordSource ( ) {
216
- exists ( DataFlow:: Node val |
212
+ exists ( DataFlow:: Node val , HashLiteral lit |
217
213
name .regexpMatch ( maybePassword ( ) ) and
218
214
not name .regexpMatch ( notSensitiveRegexp ( ) ) and
219
215
// avoid safe values assigned to presumably unsafe names
@@ -228,13 +224,6 @@ module CleartextLogging {
228
224
}
229
225
230
226
override string describe ( ) { result = "an write to " + name }
231
- override string getName ( ) { result = name }
232
- override LocalVariable getVariable ( ) {
233
- exists ( Assignment a |
234
- a .getRightOperand ( ) = lit |
235
- result = a .getLeftOperand ( ) .getAVariable ( )
236
- )
237
- }
238
227
}
239
228
240
229
/** An assignment that may assign a password to a variable */
@@ -295,7 +284,7 @@ module CleartextLogging {
295
284
nodeFrom .( HashKeyWritePasswordSource ) .getName ( ) = name and
296
285
nodeTo .asExpr ( ) .getExpr ( ) = ref and
297
286
ref .getArgument ( 0 ) .getConstantValue ( ) .getStringOrSymbol ( ) = name and
298
- nodeFrom .( HashPasswordSource ) .getVariable ( ) = hashVar and
287
+ nodeFrom .( HashKeyWritePasswordSource ) .getVariable ( ) = hashVar and
299
288
ref .getReceiver ( ) .( VariableReadAccess ) .getVariable ( ) = hashVar and
300
289
nodeFrom .asExpr ( ) .getASuccessor * ( ) = nodeTo .asExpr ( )
301
290
)
0 commit comments