Skip to content

Commit 756ac0c

Browse files
Alvaro MuñozGeekMasher
Alvaro Muñoz
authored andcommitted
Migrate csharp queries to new DF interface
1 parent 899c294 commit 756ac0c

File tree

3 files changed

+17
-21
lines changed

3 files changed

+17
-21
lines changed

csharp/lib/ghsl/HardcodedCredentials.qll

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -61,16 +61,16 @@ class CharArrayLiteral extends Source {
6161
}
6262

6363
// taint from a string literal to the constructor of a SymmetricSecurityKey
64-
class LiteralToSecurityKeyConfig extends TaintTracking::Configuration {
65-
LiteralToSecurityKeyConfig() { this = "LiteralToSecurityKeyConfig" }
64+
module LiteralToSecurityKeyConfig implements DataFlow::ConfigSig {
65+
predicate isSource(DataFlow::Node source) { source instanceof Source }
6666

67-
override predicate isSource(DataFlow::Node source) { source instanceof Source }
67+
predicate isSink(DataFlow::Node sink) { sink instanceof Sink }
6868

69-
override predicate isSink(DataFlow::Node sink) { sink instanceof Sink }
70-
71-
override predicate isSanitizer(DataFlow::Node node) { node instanceof Sanitizer }
69+
predicate isBarrier(DataFlow::Node node) { node instanceof Sanitizer }
7270
}
7371

72+
module LiteralToSecurityKeyFlow = TaintTracking::Global<LiteralToSecurityKeyConfig>;
73+
7474
class SymmetricSecurityKey extends Sink {
7575
SymmetricSecurityKey() {
7676
exists(ObjectCreation securityKey |
@@ -241,4 +241,3 @@ class DebugSanitizer extends Sanitizer {
241241
)
242242
}
243243
}
244-

csharp/src/security/CWE-760/HardcodedSalt.ql

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,9 @@
1212

1313
import csharp
1414
private import semmle.code.csharp.frameworks.Moq
15-
private import semmle.code.csharp.dataflow.DataFlow::DataFlow::PathGraph
16-
// import semmle.code.csharp.frameworks.system.security.Cryptography
1715
private import ghsl.Hardcoded
1816
private import ghsl.Cryptography
17+
import HardcodedSalt::Flow::PathGraph
1918

2019
module HardcodedSalt {
2120
abstract class Source extends DataFlow::ExprNode { }
@@ -30,21 +29,19 @@ module HardcodedSalt {
3029
HashAlgSalts() { exists(Cryptography::HashingAlgorithms hash | this = hash.getSalt()) }
3130
}
3231

33-
class HardcodedSaltConfiguration extends TaintTracking::Configuration {
34-
HardcodedSaltConfiguration() { this = "HardcodedSalt" }
32+
module HardcodedSaltConfiguration implements DataFlow::ConfigSig {
33+
predicate isSource(DataFlow::Node source) { source instanceof HardcodedSalt::Source }
3534

36-
override predicate isSource(DataFlow::Node source) { source instanceof HardcodedSalt::Source }
37-
38-
override predicate isSink(DataFlow::Node sink) {
35+
predicate isSink(DataFlow::Node sink) {
3936
sink instanceof HardcodedSalt::Sink and
4037
not any(ReturnedByMockObject mock).getAMemberInitializationValue() = sink.asExpr() and
4138
not any(ReturnedByMockObject mock).getAnArgument() = sink.asExpr()
4239
}
4340
}
41+
42+
module Flow = TaintTracking::Global<HardcodedSaltConfiguration>;
4443
}
4544

46-
from
47-
HardcodedSalt::HardcodedSaltConfiguration config, DataFlow::PathNode source,
48-
DataFlow::PathNode sink
49-
where config.hasFlowPath(source, sink)
45+
from HardcodedSalt::Flow::PathNode source, HardcodedSalt::Flow::PathNode sink
46+
where HardcodedSalt::Flow::flowPath(source, sink)
5047
select sink.getNode(), source, sink, "Use of $@.", source.getNode(), "hardcoded salt"

csharp/src/security/CWE-798/HardcodedCredentialsSymmetricSecurityKey.ql

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@
1313
*/
1414

1515
import csharp
16-
private import DataFlow::PathGraph
1716
private import ghsl.HardcodedCredentials
17+
import LiteralToSecurityKeyFlow::PathGraph
1818

19-
from DataFlow::PathNode source, DataFlow::PathNode sink, LiteralToSecurityKeyConfig config
20-
where config.hasFlowPath(source, sink)
19+
from LiteralToSecurityKeyFlow::PathNode source, LiteralToSecurityKeyFlow::PathNode sink
20+
where LiteralToSecurityKeyFlow::flowPath(source, sink)
2121
select source, sink, source, "Hard-coded credential $@ used as SymmetricSecurityKey $@",
2222
source.getNode().asExpr(), source.getNode().toString(), sink.getNode().asExpr(), "here"

0 commit comments

Comments
 (0)