@@ -168,22 +168,9 @@ module CleartextLogging {
168168 }
169169
170170 /**
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.
174172 */
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 {
187174 private string name ;
188175 private DataFlow:: ExprNode recv ;
189176
@@ -202,18 +189,27 @@ module CleartextLogging {
202189 }
203190
204191 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 ( ) {
207201 result = recv .getExprNode ( ) .getExpr ( ) .( VariableReadAccess ) .getVariable ( )
208202 }
209203 }
210204
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 {
212209 private string name ;
213- private HashLiteral lit ;
214210
215211 HashLiteralPasswordSource ( ) {
216- exists ( DataFlow:: Node val |
212+ exists ( DataFlow:: Node val , HashLiteral lit |
217213 name .regexpMatch ( maybePassword ( ) ) and
218214 not name .regexpMatch ( notSensitiveRegexp ( ) ) and
219215 // avoid safe values assigned to presumably unsafe names
@@ -228,13 +224,6 @@ module CleartextLogging {
228224 }
229225
230226 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- }
238227 }
239228
240229 /** An assignment that may assign a password to a variable */
@@ -295,7 +284,7 @@ module CleartextLogging {
295284 nodeFrom .( HashKeyWritePasswordSource ) .getName ( ) = name and
296285 nodeTo .asExpr ( ) .getExpr ( ) = ref and
297286 ref .getArgument ( 0 ) .getConstantValue ( ) .getStringOrSymbol ( ) = name and
298- nodeFrom .( HashPasswordSource ) .getVariable ( ) = hashVar and
287+ nodeFrom .( HashKeyWritePasswordSource ) .getVariable ( ) = hashVar and
299288 ref .getReceiver ( ) .( VariableReadAccess ) .getVariable ( ) = hashVar and
300289 nodeFrom .asExpr ( ) .getASuccessor * ( ) = nodeTo .asExpr ( )
301290 )
0 commit comments