Skip to content

Commit ff0e599

Browse files
committed
feat(js): Add Initial lib support
1 parent de4db29 commit ff0e599

File tree

3 files changed

+94
-1
lines changed

3 files changed

+94
-1
lines changed

javascript/lib/ghsl.qll

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
import ghsl.Utils

javascript/lib/ghsl/Utils.qll

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
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+
}

javascript/lib/qlpack.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
library: true
1+
library: true
22
name: githubsecuritylab/codeql-javascript-libs
33
version: 0.2.1
44
dependencies:

0 commit comments

Comments
 (0)