Skip to content

Commit b700b6a

Browse files
author
Alvaro Muñoz
committed
Add Javascript packs
1 parent ecebc67 commit b700b6a

File tree

83 files changed

+1252
-3
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

83 files changed

+1252
-3
lines changed

.github/workflows/build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ jobs:
1212
strategy:
1313
fail-fast: false
1414
matrix:
15-
language: [ 'cpp', 'csharp', 'go', 'java', 'python', 'ruby' ]
15+
language: [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby' ]
1616

1717
steps:
1818
- uses: actions/checkout@v3

.github/workflows/publish.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ jobs:
1717
strategy:
1818
fail-fast: false
1919
matrix:
20-
language: ["cpp", "csharp", "go", "java", "python", "ruby"]
20+
language: ["cpp", "csharp", "go", "java", "javascript", "python", "ruby"]
2121

2222
steps:
2323
- uses: actions/checkout@v3
@@ -54,7 +54,7 @@ jobs:
5454
strategy:
5555
fail-fast: false
5656
matrix:
57-
language: ["cpp", "csharp", "go", "java", "python", "ruby"]
57+
language: ["cpp", "csharp", "go", "java", "javascript", "python", "ruby"]
5858

5959
steps:
6060
- uses: actions/checkout@v3

codeql-workspace.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ provide:
33
- csharp/**/qlpack.yml
44
- go/**/qlpack.yml
55
- java/**/qlpack.yml
6+
- javascript/**/qlpack.yml
67
- python/**/qlpack.yml
78
- ruby/**/qlpack.yml
89

javascript/lib/ResearchMode.qll

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
//import semmle.javascript.heuristics.all
2+
import semmle.javascript.heuristics.AdditionalFrameworks
3+
import semmle.javascript.heuristics.AdditionalPromises
4+
import semmle.javascript.heuristics.AdditionalRouteHandlers
5+
import semmle.javascript.heuristics.AdditionalSources
6+
//import semmle.javascript.heuristics.AdditionalSinks
7+
import semmle.javascript.heuristics.AdditionalTaintSteps

javascript/lib/applications/.gitkeep

Whitespace-only changes.

javascript/lib/codeql-pack.lock.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
---
2+
lockVersion: 1.0.0
3+
dependencies:
4+
codeql/javascript-all:
5+
version: 0.7.4
6+
codeql/mad:
7+
version: 0.1.4
8+
codeql/regex:
9+
version: 0.1.4
10+
codeql/tutorial:
11+
version: 0.1.4
12+
codeql/util:
13+
version: 0.1.4
14+
codeql/yaml:
15+
version: 0.1.4
16+
compiled: false

javascript/lib/frameworks/.gitkeep

Whitespace-only changes.

javascript/lib/github/CommandLine.qll

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import semmle.javascript.dataflow.DataFlow
2+
3+
class CommandLineArgument extends DataFlow::Node {
4+
CommandLineArgument() {
5+
this = DataFlow::globalVarRef("process").getAPropertyRead("argv").getAPropertyReference()
6+
}
7+
}

javascript/lib/github/InsecureIV.qll

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
import semmle.javascript.dataflow.TaintTracking
2+
3+
import github.CommandLine
4+
5+
class RandomTaintsSourceConfiguration extends TaintTracking::Configuration {
6+
RandomTaintsSourceConfiguration() { this = "RandomTaintsSourceConfiguration" }
7+
8+
override predicate isSource(DataFlow::Node source) {
9+
isSecureRandom(source)
10+
}
11+
12+
override predicate isSink(DataFlow::Node sink) {
13+
not isSecureRandom(sink)
14+
}
15+
}
16+
17+
class InsecureIVConfiguration extends TaintTracking::Configuration {
18+
InsecureIVConfiguration() { this = "InsecureIVConfiguration" }
19+
20+
override predicate isSource(DataFlow::Node source) {
21+
exists(Literal literal|literal.flow() = source)
22+
or
23+
source instanceof DataFlow::ArrayLiteralNode
24+
or
25+
source instanceof RemoteFlowSource
26+
or
27+
source instanceof FileSystemReadAccess
28+
or
29+
source instanceof DatabaseAccess
30+
or
31+
source instanceof CommandLineArgument
32+
or
33+
// an external function that is not a known source of randomness
34+
(
35+
source instanceof ExternalCallWithOutput
36+
and not source instanceof CreateIVArgument
37+
and not source instanceof SecureRandomSource
38+
)
39+
}
40+
41+
override predicate isSink(DataFlow::Node sink) {
42+
sink instanceof CreateIVArgument
43+
}
44+
}
45+
46+
class ExternalCallWithOutput extends DataFlow::Node {
47+
CallExpr call;
48+
49+
ExternalCallWithOutput() {
50+
not exists(MethodCallExpr method_call, ThisExpr this_expr| method_call = call and method_call.getReceiver() = this_expr )
51+
and
52+
this = call.flow()
53+
}
54+
}
55+
56+
class SecureRandomSource extends DataFlow::Node {
57+
SecureRandomSource() {
58+
isSecureRandom(this)
59+
}
60+
}
61+
62+
predicate isSecureRandom(DataFlow::Node node) {
63+
exists(string name|
64+
name in ["randomBytes", "getRandomValues"] and
65+
DataFlow::moduleMember("crypto", name).getACall() = node
66+
)
67+
or
68+
exists(string name|
69+
name in ["randomFill", "randomFillSync"] and
70+
DataFlow::moduleMember("crypto", name).getACall().getArgument(0) = node
71+
)
72+
or
73+
exists(string name|
74+
name in ["randomKey", "randomString"] and
75+
DataFlow::moduleMember("crypto-extra", name).getACall() = node
76+
)
77+
or
78+
exists(string name|
79+
name in ["cryptoRandomString", "cryptoRandomStringAsync"] and
80+
DataFlow::moduleMember("crypto-random-string", name).getACall() = node
81+
)
82+
or
83+
exists(string name|
84+
name in ["secureRandom", "randomArray", "randomUint8Array", "randomBuffer"] and
85+
DataFlow::moduleMember("secure-random", name).getACall() = node
86+
)
87+
}
88+
89+
class CreateIVArgument extends DataFlow::Node {
90+
CreateIVArgument() {
91+
isCreateIV(this)
92+
}
93+
}
94+
95+
predicate isCreateIV(DataFlow::Node node) {
96+
exists(string name|
97+
name = "createCipheriv" and
98+
DataFlow::moduleMember("crypto", name).getACall().getArgument(2) = node
99+
)
100+
}
101+
102+
predicate knownCryptTest(DataFlow::Node sink) {
103+
sink.getFile().getRelativePath().matches(
104+
[
105+
"%/des.js/test/%",
106+
"test/common/tls.js",
107+
"test/%/test-crypto-%.js",
108+
"%/browserify-aes/populateFixtures.js",
109+
"%/evp_bytestokey%/test.js",
110+
"%/sshpk/lib/formats/ssh-private.js"
111+
]
112+
)
113+
}

javascript/lib/qlpack.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
library: true
2+
name: githubsecuritylab/codeql-javascript-libs
3+
version: 0.0.1
4+
dependencies:
5+
codeql/javascript-all: '*'

javascript/src/CVEs/CVE-2022-23631.ql

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/**
2+
* @name Use of unsafe superjson parse or deserialize functions
3+
* @description Specific versions of the superjson library are vulnerable to prototype pollution. Avoid calling
4+
* their parse() or deserialize() functions.
5+
* @kind problem
6+
* @problem.severity error
7+
* @security-severity 10.0
8+
* @precision high
9+
* @id githubsecuritylab/cve-2022-23631
10+
* @tags security
11+
* external/cwe/cwe-094
12+
* external/cve/cve-2022-23631
13+
*/
14+
15+
import javascript
16+
import semmle.javascript.dependencies.Dependencies
17+
import semmle.javascript.dependencies.SemVer
18+
19+
class SuperJsonCalls extends DataFlow::CallNode {
20+
SuperJsonCalls() {
21+
// https://github.com/blitz-js/superjson/security/advisories/GHSA-5888-ffcr-r425
22+
// https://github.com/blitz-js/superjson/commit/0d68cd51a430999b848f6da7af528ee02560c883
23+
exists(NpmDependency dep |
24+
dep.getNpmPackageName() = "superjson" and
25+
dep.getVersion().(DependencySemVer).maybeBefore("1.8.1") and
26+
this = DataFlow::dependencyModuleImport(dep).getAMemberCall(["parse", "deserialize"])
27+
)
28+
}
29+
}
30+
31+
from SuperJsonCalls calls
32+
select calls, "Potential prototype pollution via superjson parse or deserialize functions!"
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Audit: Usage of Command Injection sink
2+
3+
This query detects the use of command injection sinks. Command injection sinks are functions that execute commands and if the commands are constructed using user input, it may allow an attacker to execute arbitrary commands.
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/**
2+
* @name Audit: Usage of Command Injection sink
3+
* @description A Command Injection sink is being used in your application, this can lead to remote code execution if user controled input comes into the sink
4+
* @kind problem
5+
* @problem.severity error
6+
* @security-severity 3.0
7+
* @id githubsecuritylab/audit/command-injection
8+
* @tags security
9+
* external/cwe/cwe-078
10+
* audit
11+
*/
12+
13+
import javascript
14+
private import semmle.javascript.security.dataflow.CommandInjectionCustomizations
15+
16+
from DataFlow::Node sink
17+
where sink instanceof CommandInjection::Sink
18+
select sink, "Command Injection sink"
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Audit: Possible Reflected Cross-Site Scripting
2+
3+
This query detects the use of reflected cross-site scripting sinks. Reflected cross-site scripting sinks are functions that output user input without sanitizing it.
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/**
2+
* @name Audit: Possible Reflected Cross-Site Scripting
3+
* @description Insecure dangerouslySetInnerHTML() function can lead to reflected XSS.
4+
* @kind problem
5+
* @problem.severity error
6+
* @security-severity 3.0
7+
* @id githubsecuritylab/audit/reflected-xss
8+
* @tags security
9+
* external/cwe/cwe-079
10+
* external/cwe/cwe-116
11+
* audit
12+
*/
13+
14+
import javascript
15+
private import semmle.javascript.security.dataflow.DomBasedXssCustomizations
16+
17+
from DataFlow::Node sink
18+
where sink instanceof DomBasedXss::DangerouslySetInnerHtmlSink
19+
select sink, "React's dangerouslySetInnerHTML is being used."
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Audit: Usage of Code Injection sink
2+
3+
This query detects the usage of code injection sinks. Code injection sinks are functions that execute arbitrary JavaScript and if the commands are constructed using user input, it may allow an attacker to execute arbitrary JavaScript in the browser (XSS) or server-side code (Remote Code Execution).
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/**
2+
* @name Audit: Usage of Code Injection sink
3+
* @description Usage of Code Injection sink
4+
* @kind problem
5+
* @problem.severity warning
6+
* @security-severity 3.0
7+
* @id githubsecuritylab/audit/code-injection
8+
* @tags security
9+
* external/cwe/cwe-094
10+
* external/cwe/cwe-095
11+
* external/cwe/cwe-079
12+
* external/cwe/cwe-116
13+
* audit
14+
*/
15+
16+
import javascript
17+
import semmle.javascript.security.dataflow.CodeInjectionCustomizations
18+
19+
from CodeInjection::Sink sinks
20+
select sinks, "Code Injection sink"
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Audit: Usage of Unsafe Deserialize sink
2+
3+
This query detects the use of unsafe deserialize sinks. Unsafe deserialize sinks are functions that deserialize data and if the data is constructed using user input, it may allow an attacker to execute arbitrary code.
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/**
2+
* @name Audit: Usage of Unsafe Deserialize sink
3+
* @description A Unsafe Deserialization sink is being used in your application, this can lead to remote code execution if user controled input comes into the sink
4+
* @kind problem
5+
* @problem.severity error
6+
* @security-severity 3.0
7+
* @id githubsecuritylab/audit/unsafe-deserialization
8+
* @tags security
9+
* external/cwe/cwe-503
10+
* audit
11+
*/
12+
13+
import javascript
14+
private import semmle.javascript.security.dataflow.UnsafeDeserializationCustomizations
15+
16+
from DataFlow::Node sink
17+
where sink instanceof UnsafeDeserialization::Sink
18+
select sink, "Unsafe Deserialization sink"
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Audit: XML External Entity sink used
2+
3+
This query detects the use of XML External Entity sinks. XML External Entity sinks are functions that parse XML documents and if the XML documents are constructed using user input, it may allow an attacker to perform XML External Entity attacks.
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/**
2+
* @name Audit: XML External Entity sink used
3+
* @description A XML External Entity (XXE) sink is being used in your application
4+
* @kind problem
5+
* @problem.severity error
6+
* @security-severity 3.0
7+
* @id githubsecuritylab/audit/xxe
8+
* @tags security
9+
* external/cwe/cwe-611
10+
* audit
11+
*/
12+
13+
import javascript
14+
private import semmle.javascript.security.dataflow.XxeCustomizations
15+
16+
from DataFlow::Node sink
17+
where sink instanceof Xxe::Sink
18+
select sink, "XML External Entity sink"
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Audit: Using JS Eval
2+
3+
This query detects the use of `eval` and `Function` in JavaScript code. `eval` and `Function` are functions that execute code and if the code is constructed using user input, it may allow an attacker to execute arbitrary code.
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/**
2+
* @name Audit: Using JS Eval
3+
* @description Usage of eval in JavaScript / TypeScript can be dangerous
4+
* @kind problem
5+
* @problem.severity recommendation
6+
* @security-severity 2.0
7+
* @id githubsecuritylab/audit/using-eval
8+
* @tags maintainability
9+
* external/cwe/cwe-676
10+
* audit
11+
*/
12+
13+
import javascript
14+
import semmle.javascript.security.dataflow.CodeInjectionCustomizations
15+
16+
from CodeInjection::EvalJavaScriptSink eval
17+
select eval, "Using eval"
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/**
2+
* @name External dependencies
3+
* @description Count the number of dependencies that a Java project has on external packages.
4+
* @kind treemap
5+
* @id githubsecuritylab/external-dependencies
6+
* @metricType externalDependency
7+
* @tags audit
8+
*/
9+
10+
import semmle.javascript.dependencies.Dependencies
11+
12+
predicate externalDependencies(Dependency dep, string name, int ndeps) {
13+
exists(string id, string v | dep.info(id, v) | name = id + "-" + v) and
14+
ndeps = count(Locatable use | use = dep.getAUse(_))
15+
}
16+
17+
from Dependency dep, string name, int ndeps
18+
where externalDependencies(dep, name, ndeps)
19+
select name, ndeps order by ndeps desc

javascript/src/audit/explore/Files.ql

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/**
2+
* @name Files
3+
* @description List of all files in the repository
4+
* @kind table
5+
* @id githubsecuritylab/files
6+
* @tags audit
7+
*/
8+
9+
import javascript
10+
11+
from File f
12+
where f.getExtension() = ["js", "ts"] and not f.getRelativePath().matches("%/test/%")
13+
select f.getRelativePath()

0 commit comments

Comments
 (0)