Skip to content

Commit e62ec88

Browse files
authored
Merge pull request github#13506 from michaelnebel/java/threatmodels
Java: Threat Models
2 parents e14e0cd + 9c4d77a commit e62ec88

File tree

10 files changed

+95
-0
lines changed

10 files changed

+95
-0
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
extensions:
2+
3+
- addsTo:
4+
pack: codeql/java-all
5+
extensible: supportedThreatModels
6+
data:
7+
- ["default"] # The "default" threat model is always included.
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
extensions:
2+
3+
- addsTo:
4+
pack: codeql/java-all
5+
extensible: threatModelGrouping
6+
data:
7+
# Default threat model
8+
- ["remote", "default"]
9+
- ["uri-path", "default"]
10+
11+
# Android threat models
12+
- ["android-external-storage-dir", "android"]
13+
- ["contentprovider", "android"]
14+
15+
# Remote threat models
16+
- ["request", "remote"]
17+
- ["response", "remote"]
18+
19+
# Local threat models
20+
- ["database", "local"]
21+
- ["cli", "local"]
22+
- ["environment", "local"]
23+
- ["file", "local"]

java/ql/lib/qlpack.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,5 @@ dataExtensions:
1616
- ext/*.model.yml
1717
- ext/generated/*.model.yml
1818
- ext/experimental/*.model.yml
19+
- ext/threatmodels/*.model.yml
1920
warnOnImplicitThis: true
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/**
2+
* INTERNAL use only. This is an experimental API subject to change without notice.
3+
*
4+
* This module provides extensible predicates for configuring which kinds of MaD models
5+
* are applicable to generic queries.
6+
*/
7+
8+
private import ExternalFlowExtensions
9+
10+
/**
11+
* Holds if the specified kind of source model is supported for the current query.
12+
*/
13+
extensible private predicate supportedThreatModels(string kind);
14+
15+
/**
16+
* Holds if the specified kind of source model is containted within the specified group.
17+
*/
18+
extensible private predicate threatModelGrouping(string kind, string group);
19+
20+
/**
21+
* Gets the threat models that are direct descendants of the specified kind/group.
22+
*/
23+
private string getChildThreatModel(string group) { threatModelGrouping(result, group) }
24+
25+
/**
26+
* Holds if the source model kind `kind` is relevant for generic queries
27+
* under the current threat model configuration.
28+
*/
29+
predicate sourceModelKindConfig(string kind) {
30+
exists(string group | supportedThreatModels(group) and kind = getChildThreatModel*(group))
31+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
class Empty { }
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
| default |
2+
| remote |
3+
| request |
4+
| response |
5+
| uri-path |
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import semmle.code.java.dataflow.ExternalFlowConfiguration as ExternalFlowConfiguration
2+
3+
query predicate supportedThreatModels(string kind) {
4+
ExternalFlowConfiguration::sourceModelKindConfig(kind)
5+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
| cli |
2+
| database |
3+
| default |
4+
| environment |
5+
| file |
6+
| local |
7+
| remote |
8+
| request |
9+
| response |
10+
| uri-path |
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
extensions:
2+
3+
- addsTo:
4+
pack: codeql/java-all
5+
extensible: supportedThreatModels
6+
data:
7+
- ["local"] # Add the "local" group threat model.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import semmle.code.java.dataflow.ExternalFlowConfiguration as ExternalFlowConfiguration
2+
3+
query predicate supportedThreatModels(string kind) {
4+
ExternalFlowConfiguration::sourceModelKindConfig(kind)
5+
}

0 commit comments

Comments
 (0)