12
12
import csharp
13
13
import semmle.code.csharp.dataflow.DataFlow2
14
14
import semmle.code.csharp.dataflow.TaintTracking2
15
- import DataFlow :: PathGraph
15
+ import HashWithoutSalt :: PathGraph
16
16
17
17
/** The C# class `Windows.Security.Cryptography.Core.HashAlgorithmProvider`. */
18
18
class HashAlgorithmProvider extends RefType {
@@ -120,12 +120,10 @@ predicate hasHashAncestor(MethodCall mc) {
120
120
* Taint configuration tracking flow from an expression whose name suggests it holds
121
121
* password data to a method call that generates a hash without a salt.
122
122
*/
123
- class HashWithoutSaltConfiguration extends TaintTracking :: Configuration {
124
- HashWithoutSaltConfiguration ( ) { this = "HashWithoutSaltConfiguration" }
123
+ module HashWithoutSaltConfig implements DataFlow :: ConfigSig {
124
+ predicate isSource ( DataFlow :: Node source ) { source . asExpr ( ) instanceof PasswordVarExpr }
125
125
126
- override predicate isSource ( DataFlow:: Node source ) { source .asExpr ( ) instanceof PasswordVarExpr }
127
-
128
- override predicate isSink ( DataFlow:: Node sink ) {
126
+ predicate isSink ( DataFlow:: Node sink ) {
129
127
exists ( MethodCall mc |
130
128
sink .asExpr ( ) = mc .getArgument ( 0 ) and
131
129
isHashCall ( mc ) and
@@ -148,7 +146,7 @@ class HashWithoutSaltConfiguration extends TaintTracking::Configuration {
148
146
)
149
147
}
150
148
151
- override predicate isAdditionalTaintStep ( DataFlow:: Node node1 , DataFlow:: Node node2 ) {
149
+ predicate isAdditionalFlowStep ( DataFlow:: Node node1 , DataFlow:: Node node2 ) {
152
150
exists ( MethodCall mc |
153
151
mc .getTarget ( )
154
152
.hasQualifiedName ( "Windows.Security.Cryptography" , "CryptographicBuffer" ,
@@ -166,7 +164,7 @@ class HashWithoutSaltConfiguration extends TaintTracking::Configuration {
166
164
* `byte[] saltedPassword = sha256.ComputeHash(rawSalted);`
167
165
* Or the password is concatenated with a salt as a string.
168
166
*/
169
- override predicate isSanitizer ( DataFlow:: Node node ) {
167
+ predicate isBarrier ( DataFlow:: Node node ) {
170
168
exists ( MethodCall mc |
171
169
hasFurtherProcessing ( mc ) and
172
170
mc .getAnArgument ( ) = node .asExpr ( )
@@ -194,7 +192,9 @@ class HashWithoutSaltConfiguration extends TaintTracking::Configuration {
194
192
}
195
193
}
196
194
197
- from DataFlow:: PathNode source , DataFlow:: PathNode sink , HashWithoutSaltConfiguration c
198
- where c .hasFlowPath ( source , sink )
195
+ module HashWithoutSalt = TaintTracking:: Global< HashWithoutSaltConfig > ;
196
+
197
+ from HashWithoutSalt:: PathNode source , HashWithoutSalt:: PathNode sink
198
+ where HashWithoutSalt:: flowPath ( source , sink )
199
199
select sink .getNode ( ) , source , sink , "$@ is hashed without a salt." , source .getNode ( ) ,
200
200
"The password"
0 commit comments