1
+ /**
2
+ * A collection of utility predicates and classes for JavaScript
3
+ */
4
+ private import javascript
5
+ private import semmle.javascript.security.dataflow.CommandInjectionCustomizations
6
+ private import semmle.javascript.security.dataflow.CodeInjectionCustomizations
7
+ private import semmle.javascript.security.dataflow.LogInjectionQuery as LogInjection
8
+ private import semmle.javascript.security.dataflow.NosqlInjectionCustomizations
9
+ private import semmle.javascript.security.dataflow.Xss as Xss
10
+ private import semmle.javascript.security.dataflow.XxeCustomizations
11
+
12
+
13
+ /**
14
+ * Filter results to a specific file and line number
15
+ *
16
+ * **Examples:**
17
+ *
18
+ * ```
19
+ * filterByLocation(sources, "db.js", 1)
20
+ * // or we don't care about the line numbers
21
+ * filterByLocation(sources, "db.js", _)
22
+ * ```
23
+ */
24
+ predicate filterByLocation ( DataFlow:: Node node , string relative_path , int linenumber ) {
25
+ node .getLocation ( ) .getFile ( ) .getRelativePath ( ) = relative_path and
26
+ node .getLocation ( ) .getStartLine ( ) = linenumber
27
+ }
28
+
29
+
30
+ /**
31
+ * All Sources (Remote and Local)
32
+ */
33
+ class AllSources extends DataFlow:: Node {
34
+ private string threadmodel ;
35
+
36
+ AllSources ( ) {
37
+ this instanceof RemoteSources and
38
+ threadmodel = "remote" or
39
+ this instanceof LocalSources and
40
+ threadmodel = "local"
41
+ }
42
+
43
+ /**
44
+ * Gets the source threat model.
45
+ */
46
+ string getThreatModel ( ) {
47
+ result = threadmodel
48
+ }
49
+ }
50
+
51
+ /**
52
+ * Remote Sources (HTTP frameworks, etc)
53
+ */
54
+ class RemoteSources extends ThreatModelSource {
55
+ RemoteSources ( ) { this .getThreatModel ( ) = "remote" }
56
+ }
57
+
58
+ /**
59
+ * Local Sources (CLI arguments, Filesystem, etc)
60
+ */
61
+ class LocalSources extends ThreatModelSource {
62
+ LocalSources ( ) { this .getThreatModel ( ) = "local" }
63
+ }
64
+
65
+ /**
66
+ * List of all sinks
67
+ */
68
+ class AllSinks extends DataFlow:: Node {
69
+ private string sink ;
70
+
71
+ AllSinks ( ) {
72
+ this instanceof CodeInjection:: Sink and
73
+ sink = "code-injection" or
74
+ this instanceof CommandInjection:: Sink and
75
+ sink = "command-injection" or
76
+ this instanceof LogInjection:: Sink and
77
+ sink = "log-injection" or
78
+ this instanceof NosqlInjection:: Sink and
79
+ sink = "nosql-injection" or
80
+ this instanceof Xss:: Shared:: Sink and
81
+ sink = "xss" or
82
+ this instanceof Xxe:: Sink and
83
+ sink = "xxe"
84
+ }
85
+
86
+ /**
87
+ * Gets the sink threat model.
88
+ */
89
+ string sinkType ( ) {
90
+ result = sink
91
+ }
92
+ }
0 commit comments