@@ -38,7 +38,12 @@ string getPasswordRegex() { result = "(?i).*pass(wd|word|code|phrase).*" }
3838/** Finds variables that hold password information judging by their names. */
3939class PasswordVarExpr extends Expr {
4040 PasswordVarExpr ( ) {
41- exists ( Variable v | this = v .getAnAccess ( ) | v .getName ( ) .regexpMatch ( getPasswordRegex ( ) ) )
41+ exists ( Variable v | this = v .getAnAccess ( ) |
42+ (
43+ v .getName ( ) .toLowerCase ( ) .regexpMatch ( getPasswordRegex ( ) ) and
44+ not v .getName ( ) .toLowerCase ( ) .matches ( "%hash%" ) // Exclude variable names such as `passwordHash` since their values were already hashed
45+ )
46+ )
4247 }
4348}
4449
@@ -77,17 +82,20 @@ class HashWithoutSaltConfiguration extends TaintTracking::Configuration {
7782 }
7883
7984 /**
80- * Holds if a password is concatenated with a salt then hashed together through the call `System.arraycopy(password.getBytes(), ...)`. For example,
85+ * Holds if a password is concatenated with a salt then hashed together through the call `System.arraycopy(password.getBytes(), ...)`, for example,
8186 * `System.arraycopy(password.getBytes(), 0, allBytes, 0, password.getBytes().length);`
8287 * `System.arraycopy(salt, 0, allBytes, password.getBytes().length, salt.length);`
8388 * `byte[] messageDigest = md.digest(allBytes);`
89+ * Or the password is concatenated with a salt as a string.
8490 */
8591 override predicate isSanitizer ( DataFlow:: Node node ) {
8692 exists ( MethodAccess ma |
8793 ma .getMethod ( ) .getDeclaringType ( ) .hasQualifiedName ( "java.lang" , "System" ) and
8894 ma .getMethod ( ) .hasName ( "arraycopy" ) and
8995 ma .getArgument ( 0 ) = node .asExpr ( )
90- )
96+ ) // System.arraycopy(password.getBytes(), ...)
97+ or
98+ exists ( AddExpr e | node .asExpr ( ) = e .getAnOperand ( ) ) // password+salt
9199 }
92100}
93101
0 commit comments