Skip to content

Commit 5fd56ce

Browse files
author
Dave Bartolomeo
committed
Alternate threat model implementation
1 parent 76a9b71 commit 5fd56ce

File tree

3 files changed

+34
-12
lines changed

3 files changed

+34
-12
lines changed

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

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,6 @@ abstract class SourceNode extends DataFlow::Node {
4747
*/
4848
class ThreatModelFlowSource extends DataFlow::Node {
4949
ThreatModelFlowSource() {
50-
// Expansive threat model.
51-
currentThreatModel("all") and
52-
(this instanceof SourceNode or sourceNode(this, _))
53-
or
5450
exists(string kind |
5551
// Specific threat model.
5652
currentThreatModel(kind) and

shared/threat-models/codeql/threatmodels/ThreatModels.qll

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,24 +6,51 @@
66
*/
77

88
/**
9-
* Holds if the specified kind of source model is supported for the current query.
9+
* Holds configuration entries to specify which threat models are enabled.
10+
*
11+
* - `kind` - Specifies the threat model to configure. This can be the name of a specific threat
12+
* model (for example, `environment`), a group (`local`), or `all`.
13+
* - `enable` - `true` to enable the specified threat model (and its children), or `false` to disable it.
14+
* - `priority` - The order in which the configuration should be applied. Lower values are applied first.
15+
*
16+
* The final configuration is the result of processing each row in ascending order of its `priority` column.
17+
* For example:
18+
* - `{ kind: "all", enable: true, priority: 0 }`
19+
* - `{ kind: "remote", enable: false, priority: 1 }`
20+
* - `{ kind: "environment", enable: true, priority: 2 }`
21+
* This configuration first enables all threat models, then disables the `remote` group, and finally re-enables
22+
* the `environment` threat model.
1023
*/
11-
extensible predicate supportedThreatModels(string kind);
24+
extensible predicate threatModelConfiguration(string kind, boolean enable, int priority);
1225

1326
/**
1427
* Holds if the specified kind of source model is containted within the specified group.
1528
*/
1629
extensible private predicate threatModelGrouping(string kind, string group);
1730

1831
/**
19-
* Gets the threat models that are direct descendants of the specified kind/group.
32+
* Gets the threat model group that directly contains the specified threat model.
2033
*/
21-
private string getChildThreatModel(string group) { threatModelGrouping(result, group) }
34+
private string getParentThreatModel(string child) {
35+
threatModelGrouping(child, result)
36+
}
2237

2338
/**
2439
* Holds if the source model kind `kind` is relevant for generic queries
2540
* under the current threat model configuration.
2641
*/
42+
bindingset[kind]
2743
predicate currentThreatModel(string kind) {
28-
exists(string group | supportedThreatModels(group) and kind = getChildThreatModel*(group))
44+
// Find the highest-oriority configuration row whose `kind` column includes the specified threat
45+
// model kind. If such a row exists and its `enabled` column is `true`, then the threat model is
46+
// enabled.
47+
max(boolean enabled, int priority |
48+
exists(string configuredKind |
49+
configuredKind = getParentThreatModel*(kind) or configuredKind = "all"
50+
|
51+
threatModelConfiguration(configuredKind, enabled, priority)
52+
)
53+
|
54+
enabled order by priority
55+
) = true
2956
}
Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
extensions:
2-
32
- addsTo:
43
pack: codeql/threat-models
5-
extensible: supportedThreatModels
4+
extensible: threatModelConfiguration
65
data:
7-
- ["default"] # The "default" threat model is always included.
6+
- ["default", true, -2147483648] # The "default" threat model is included by default

0 commit comments

Comments
 (0)