Skip to content

Commit 7aa59ca

Browse files
authored
Merge pull request github#7633 from erik-krogh/CWE-300
JS: add js/http-dependency query
2 parents 47a57e0 + b5198bd commit 7aa59ca

File tree

9 files changed

+117
-0
lines changed

9 files changed

+117
-0
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
category: newQuery
3+
---
4+
* The `js/insecure-dependency` query has been added. It detects depedencies that are downloaded using an unencrypted connection.
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
<!DOCTYPE qhelp PUBLIC
2+
"-//Semmle//qhelp//EN"
3+
"qhelp.dtd">
4+
<qhelp>
5+
6+
<overview>
7+
<p>
8+
Using an insecure protocol like HTTP or FTP to download build dependencies makes the build process vulnerable to a
9+
man-in-the-middle (MITM) attack.
10+
</p>
11+
<p>
12+
This can allow attackers to inject malicious code into the downloaded dependencies, and thereby
13+
infect the build artifacts and execute arbitrary code on the machine building the artifacts.
14+
</p>
15+
16+
</overview>
17+
<recommendation>
18+
19+
<p>Always use a secure protocol, such as HTTPS or SFTP, when downloading artifacts from an URL.</p>
20+
21+
</recommendation>
22+
23+
<example>
24+
<p>
25+
The below example shows a <code>package.json</code> file that downloads a dependency using the insecure HTTP protocol.
26+
</p>
27+
<sample src="examples/bad-package.json" />
28+
<p>
29+
The fix is to change the protocol to HTTPS.
30+
</p>
31+
<sample src="examples/good-package.json" />
32+
33+
</example>
34+
35+
<references>
36+
<li>
37+
Jonathan Leitschuh:
38+
<a href="https://infosecwriteups.com/want-to-take-over-the-java-ecosystem-all-you-need-is-a-mitm-1fc329d898fb">
39+
Want to take over the Java ecosystem? All you need is a MITM!
40+
</a>
41+
</li>
42+
<li>
43+
Max Veytsman:
44+
<a href="https://max.computer/blog/how-to-take-over-the-computer-of-any-java-or-clojure-or-scala-developer/">
45+
How to take over the computer of any Java (or Closure or Scala) Developer.
46+
</a>
47+
</li>
48+
<li>
49+
Wikipedia: <a href="https://en.wikipedia.org/wiki/Supply_chain_attack">Supply chain attack.</a>
50+
</li>
51+
<li>
52+
Wikipedia: <a href="https://en.wikipedia.org/wiki/Man-in-the-middle_attack">Man-in-the-middle attack.</a>
53+
</li>
54+
</references>
55+
</qhelp>
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/**
2+
* @name Dependency download using unencrypted communication channel
3+
* @description Using unencrypted protocols to fetch dependencies can leave an application
4+
* open to man-in-the-middle attacks.
5+
* @kind problem
6+
* @problem.severity warning
7+
* @security-severity 8.1
8+
* @precision high
9+
* @id js/insecure-dependency
10+
* @tags security
11+
* external/cwe/cwe-300
12+
* external/cwe/cwe-319
13+
* external/cwe/cwe-494
14+
* external/cwe/cwe-829
15+
*/
16+
17+
import javascript
18+
19+
from PackageJSON pack, JSONString val
20+
where
21+
[pack.getDependencies(), pack.getDevDependencies()].getPropValue(_) = val and
22+
val.getValue().regexpMatch("(http|ftp)://.*")
23+
select val, "Dependency downloaded using unencrypted communication channel."
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"name": "example-project",
3+
"dependencies": {
4+
"unencrypted": "http://example.org/foo/tarball/release/0.0.1",
5+
"lodash": "^4.0.0"
6+
}
7+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"name": "example-project",
3+
"dependencies": {
4+
"unencrypted": "https://example.org/foo/tarball/release/0.0.1",
5+
"lodash": "^4.0.0"
6+
}
7+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
| package.json:6:17:6:40 | "http:/ ... rg/foo" | Dependency downloaded using unencrypted communication channel. |
2+
| package.json:7:17:7:39 | "ftp:// ... rg/foo" | Dependency downloaded using unencrypted communication channel. |
3+
| package.json:12:17:12:40 | "http:/ ... rg/foo" | Dependency downloaded using unencrypted communication channel. |
4+
| package.json:13:17:13:39 | "ftp:// ... rg/foo" | Dependency downloaded using unencrypted communication channel. |
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Security/CWE-300/InsecureDependencyResolution.ql
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
console.log("foo");
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"name": "insecure-dep-downloader",
3+
"dependencies": {
4+
"foo": "*",
5+
"good1": "https://example.org/foo",
6+
"bad1": "http://example.org/foo",
7+
"bad2": "ftp://example.org/foo"
8+
},
9+
"devDependencies": {
10+
"bar": "*",
11+
"good2": "https://example.org/foo",
12+
"bad3": "http://example.org/foo",
13+
"bad4": "ftp://example.org/foo"
14+
}
15+
}

0 commit comments

Comments
 (0)