@@ -28,29 +28,51 @@ extensible predicate threatModelConfiguration(string kind, boolean enable, int p
28
28
*/
29
29
extensible private predicate threatModelGrouping ( string kind , string group ) ;
30
30
31
+ /** Holds if the specified threat model kind is mentioned in either the configuration or grouping table. */
32
+ private predicate knownThreatModel ( string kind ) {
33
+ threatModelConfiguration ( kind , _, _) or
34
+ threatModelGrouping ( kind , _) or
35
+ threatModelGrouping ( _, kind ) or
36
+ kind = "all"
37
+ }
38
+
31
39
/**
32
40
* Gets the threat model group that directly contains the specified threat model.
33
41
*/
34
42
private string getParentThreatModel ( string child ) {
35
43
threatModelGrouping ( child , result )
44
+ or
45
+ knownThreatModel ( child ) and child != "all" and result = "all"
36
46
}
37
47
38
48
/**
39
- * Holds if the source model kind `kind` is relevant for generic queries
40
- * under the current threat model configuration .
49
+ * Gets the `enabled` column of the highest-priority configuration row whose `kind` column includes
50
+ * the specified threat model kind .
41
51
*/
42
- bindingset [ kind]
43
- predicate currentThreatModel ( string kind ) {
52
+ private boolean threatModelExplicitState ( string kind ) {
44
53
// Find the highest-oriority configuration row whose `kind` column includes the specified threat
45
54
// model kind. If such a row exists and its `enabled` column is `true`, then the threat model is
46
55
// enabled.
47
- max ( boolean enabled , int priority |
48
- exists ( string configuredKind |
49
- configuredKind = getParentThreatModel * ( kind ) or configuredKind = "all"
56
+ ( knownThreatModel ( kind ) or kind = "<other>" ) and
57
+ result =
58
+ max ( boolean enabled , int priority |
59
+ exists ( string configuredKind | configuredKind = getParentThreatModel * ( kind ) |
60
+ threatModelConfiguration ( configuredKind , enabled , priority )
61
+ )
50
62
|
51
- threatModelConfiguration ( configuredKind , enabled , priority )
63
+ enabled order by priority
52
64
)
53
- |
54
- enabled order by priority
55
- ) = true
65
+ }
66
+
67
+ /**
68
+ * Holds if the source model kind `kind` is relevant for generic queries
69
+ * under the current threat model configuration.
70
+ */
71
+ bindingset [ kind]
72
+ predicate currentThreatModel ( string kind ) {
73
+ knownThreatModel ( kind ) and threatModelExplicitState ( kind ) = true
74
+ or
75
+ // For any threat model kind not mentioned in the configuration or grouping tables, its state of
76
+ // enablement is controlled only by the entries that specifiy the "all" kind.
77
+ not knownThreatModel ( kind ) and threatModelExplicitState ( "all" ) = true
56
78
}
0 commit comments