Skip to content

Commit 9a112dd

Browse files
committed
Java: Introduce a class of dataflow nodes for the threat modeling.
1 parent 2684a22 commit 9a112dd

File tree

4 files changed

+32
-3
lines changed

4 files changed

+32
-3
lines changed

java/ql/lib/semmle/code/java/dataflow/ExternalFlowConfiguration.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,6 @@ private string getChildThreatModel(string group) { threatModelGrouping(result, g
2626
* Holds if the source model kind `kind` is relevant for generic queries
2727
* under the current threat model configuration.
2828
*/
29-
predicate sourceModelKindConfig(string kind) {
29+
predicate currentThreatModel(string kind) {
3030
exists(string group | supportedThreatModels(group) and kind = getChildThreatModel*(group))
3131
}

java/ql/lib/semmle/code/java/dataflow/FlowSources.qll

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,35 @@ import semmle.code.java.frameworks.struts.StrutsActions
2929
import semmle.code.java.frameworks.Thrift
3030
import semmle.code.java.frameworks.javaee.jsf.JSFRenderer
3131
private import semmle.code.java.dataflow.ExternalFlow
32+
private import semmle.code.java.dataflow.ExternalFlowConfiguration
33+
34+
/**
35+
* A data flow source.
36+
*/
37+
abstract class SourceNode extends DataFlow::Node {
38+
/**
39+
* Gets a string that represents the source kind with respect to threat modeling.
40+
*/
41+
abstract string getThreatModel();
42+
}
43+
44+
/**
45+
* A class of data flow sources that respects the
46+
* current threat model configuration.
47+
*/
48+
class ThreatModelFlowSource extends DataFlow::Node {
49+
ThreatModelFlowSource() {
50+
// Expansive threat model.
51+
currentThreatModel("all") and
52+
(this instanceof SourceNode or sourceNode(this, _))
53+
or
54+
exists(string kind |
55+
// Specific threat model.
56+
currentThreatModel(kind) and
57+
(this.(SourceNode).getThreatModel() = kind or sourceNode(this, kind))
58+
)
59+
}
60+
}
3261

3362
/** A data flow source of remote user input. */
3463
abstract class RemoteFlowSource extends DataFlow::Node {
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import semmle.code.java.dataflow.ExternalFlowConfiguration as ExternalFlowConfiguration
22

33
query predicate supportedThreatModels(string kind) {
4-
ExternalFlowConfiguration::sourceModelKindConfig(kind)
4+
ExternalFlowConfiguration::currentThreatModel(kind)
55
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import semmle.code.java.dataflow.ExternalFlowConfiguration as ExternalFlowConfiguration
22

33
query predicate supportedThreatModels(string kind) {
4-
ExternalFlowConfiguration::sourceModelKindConfig(kind)
4+
ExternalFlowConfiguration::currentThreatModel(kind)
55
}

0 commit comments

Comments
 (0)