Skip to content

Commit 17a6d54

Browse files
committed
JS: Setup basic support for threat-models
Integration with RemoteFlowSource is not straightforward, so postponing that for later Naming in other languages: - `SourceNode` (for QL only modeling) - `ThreatModelFlowSource` (for active sources from QL or data-extensions) However, since we use `LocalSourceNode` in Python, and `SourceNode` in JS (for local source nodes), it seems a bit confusing to follow the same naming convention as other languages, and instead I came up with new names.
1 parent 55d092f commit 17a6d54

File tree

3 files changed

+62
-0
lines changed

3 files changed

+62
-0
lines changed

javascript/ql/lib/qlpack.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ dependencies:
99
codeql/dataflow: ${workspace}
1010
codeql/mad: ${workspace}
1111
codeql/regex: ${workspace}
12+
codeql/threat-models: ${workspace}
1213
codeql/tutorial: ${workspace}
1314
codeql/util: ${workspace}
1415
codeql/xml: ${workspace}

javascript/ql/lib/semmle/javascript/Concepts.qll

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,54 @@
55
*/
66

77
import javascript
8+
private import codeql.threatmodels.ThreatModels
9+
10+
/**
11+
* A data flow source, for a specific threat-model.
12+
*
13+
* Extend this class to refine existing API models. If you want to model new APIs,
14+
* extend `ThreatModelSource::Range` instead.
15+
*/
16+
class ThreatModelSource extends DataFlow::Node instanceof ThreatModelSource::Range {
17+
/**
18+
* Gets a string that represents the source kind with respect to threat modeling.
19+
*/
20+
string getThreatModel() { result = super.getThreatModel() }
21+
22+
/** Gets a string that describes the type of this threat-model source. */
23+
string getSourceType() { result = super.getSourceType() }
24+
}
25+
26+
/** Provides a class for modeling new sources for specific threat-models. */
27+
module ThreatModelSource {
28+
/**
29+
* A data flow source, for a specific threat-model.
30+
*
31+
* Extend this class to model new APIs. If you want to refine existing API models,
32+
* extend `ThreatModelSource` instead.
33+
*/
34+
abstract class Range extends DataFlow::Node {
35+
/**
36+
* Gets a string that represents the source kind with respect to threat modeling.
37+
*/
38+
abstract string getThreatModel();
39+
40+
/** Gets a string that describes the type of this threat-model source. */
41+
abstract string getSourceType();
42+
}
43+
}
44+
45+
/**
46+
* A data flow source that is enabled in the current threat model configuration.
47+
*/
48+
class ActiveThreatModelSource extends DataFlow::Node {
49+
ActiveThreatModelSource() {
50+
exists(string kind |
51+
currentThreatModel(kind) and
52+
this.(ThreatModelSource).getThreatModel() = kind
53+
)
54+
}
55+
}
856

957
/**
1058
* A data flow node that executes an operating system command,

javascript/ql/lib/semmle/javascript/frameworks/data/ModelsAsData.qll

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,19 @@ private class RemoteFlowSourceFromMaD extends RemoteFlowSource {
3232
override string getSourceType() { result = "Remote flow" }
3333
}
3434

35+
/**
36+
* A threat-model flow source originating from a data extension.
37+
*/
38+
private class ThreatModelSourceFromDataExtension extends ThreatModelSource::Range {
39+
ThreatModelSourceFromDataExtension() { this = ModelOutput::getASourceNode(_).asSource() }
40+
41+
override string getThreatModel() { this = ModelOutput::getASourceNode(result).asSource() }
42+
43+
override string getSourceType() {
44+
result = "Source node (" + this.getThreatModel() + ") [from data-extension]"
45+
}
46+
}
47+
3548
/**
3649
* Like `ModelOutput::summaryStep` but with API nodes mapped to data-flow nodes.
3750
*/

0 commit comments

Comments
 (0)