12
12
13
13
import java
14
14
import semmle.code.java.dataflow.TaintTracking
15
- import DataFlow :: PathGraph
15
+ import HashWithoutSaltFlow :: PathGraph
16
16
17
17
/**
18
18
* Gets a regular expression for matching common names of variables
@@ -138,12 +138,10 @@ class HashWithoutSaltSink extends DataFlow::ExprNode {
138
138
* Taint configuration tracking flow from an expression whose name suggests it holds password data
139
139
* to a method call that generates a hash without a salt.
140
140
*/
141
- class HashWithoutSaltConfiguration extends TaintTracking :: Configuration {
142
- HashWithoutSaltConfiguration ( ) { this = "HashWithoutSaltConfiguration" }
141
+ module HashWithoutSaltConfig implements DataFlow :: ConfigSig {
142
+ predicate isSource ( DataFlow :: Node source ) { source . asExpr ( ) instanceof PasswordVarExpr }
143
143
144
- override predicate isSource ( DataFlow:: Node source ) { source .asExpr ( ) instanceof PasswordVarExpr }
145
-
146
- override predicate isSink ( DataFlow:: Node sink ) { sink instanceof HashWithoutSaltSink }
144
+ predicate isSink ( DataFlow:: Node sink ) { sink instanceof HashWithoutSaltSink }
147
145
148
146
/**
149
147
* Holds if a password is concatenated with a salt then hashed together through the call `System.arraycopy(password.getBytes(), ...)`, for example,
@@ -152,7 +150,7 @@ class HashWithoutSaltConfiguration extends TaintTracking::Configuration {
152
150
* `byte[] messageDigest = md.digest(allBytes);`
153
151
* Or the password is concatenated with a salt as a string.
154
152
*/
155
- override predicate isSanitizer ( DataFlow:: Node node ) {
153
+ predicate isBarrier ( DataFlow:: Node node ) {
156
154
exists ( MethodAccess ma |
157
155
ma .getMethod ( ) .getDeclaringType ( ) .hasQualifiedName ( "java.lang" , "System" ) and
158
156
ma .getMethod ( ) .hasName ( "arraycopy" ) and
@@ -176,6 +174,8 @@ class HashWithoutSaltConfiguration extends TaintTracking::Configuration {
176
174
}
177
175
}
178
176
179
- from DataFlow:: PathNode source , DataFlow:: PathNode sink , HashWithoutSaltConfiguration cc
180
- where cc .hasFlowPath ( source , sink )
177
+ module HashWithoutSaltFlow = TaintTracking:: Global< HashWithoutSaltConfig > ;
178
+
179
+ from HashWithoutSaltFlow:: PathNode source , HashWithoutSaltFlow:: PathNode sink
180
+ where HashWithoutSaltFlow:: flowPath ( source , sink )
181
181
select sink , source , sink , "$@ is hashed without a salt." , source , "The password"
0 commit comments