|
6 | 6 | */
|
7 | 7 |
|
8 | 8 | /**
|
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. |
10 | 23 | */
|
11 |
| -extensible predicate supportedThreatModels(string kind); |
| 24 | +extensible predicate threatModelConfiguration(string kind, boolean enable, int priority); |
12 | 25 |
|
13 | 26 | /**
|
14 | 27 | * Holds if the specified kind of source model is containted within the specified group.
|
15 | 28 | */
|
16 | 29 | extensible private predicate threatModelGrouping(string kind, string group);
|
17 | 30 |
|
18 | 31 | /**
|
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. |
20 | 33 | */
|
21 |
| -private string getChildThreatModel(string group) { threatModelGrouping(result, group) } |
| 34 | +private string getParentThreatModel(string child) { |
| 35 | + threatModelGrouping(child, result) |
| 36 | +} |
22 | 37 |
|
23 | 38 | /**
|
24 | 39 | * Holds if the source model kind `kind` is relevant for generic queries
|
25 | 40 | * under the current threat model configuration.
|
26 | 41 | */
|
| 42 | +bindingset[kind] |
27 | 43 | 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 |
29 | 56 | }
|
0 commit comments