Skip to content

Commit b7a0b87

Browse files
committed
add js/http-dependency query
1 parent b2c7175 commit b7a0b87

File tree

7 files changed

+83
-0
lines changed

7 files changed

+83
-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/http-dependency` query has been added. It detects depedencies that are downloaded using an unencrypted connection.
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<!DOCTYPE qhelp PUBLIC
2+
"-//Semmle//qhelp//EN"
3+
"qhelp.dtd">
4+
<qhelp>
5+
<overview>
6+
<p>Using an insecure protocol like HTTP or FTP to download your dependencies leaves your npm build vulnerable to a
7+
<a href="https://en.wikipedia.org/wiki/Man-in-the-middle_attack">Man in the Middle (MITM)</a>.
8+
This can allow attackers to inject malicious code into the artifacts that you are resolving and infect build artifacts
9+
that are being produced. This can be used by attackers to perform a
10+
<a href="https://en.wikipedia.org/wiki/Supply_chain_attack">Supply chain attack</a>
11+
against your project's users.
12+
</p>
13+
14+
</overview>
15+
<recommendation>
16+
17+
<p>Always use HTTPS or SFTP to download artifacts from artifact servers.</p>
18+
19+
</recommendation>
20+
21+
<references>
22+
<li>
23+
Research:
24+
<a href="https://medium.com/bugbountywriteup/want-to-take-over-the-java-ecosystem-all-you-need-is-a-mitm-1fc329d898fb?source=friends_link&amp;sk=3c99970c55a899ad9ef41f126efcde0e">
25+
Want to take over the Java ecosystem? All you need is a MITM!
26+
</a>
27+
</li>
28+
<li>
29+
Research:
30+
<a href="https://max.computer/blog/how-to-take-over-the-computer-of-any-java-or-clojure-or-scala-developer/">
31+
How to take over the computer of any Java (or Closure or Scala) Developer.
32+
</a>
33+
</li>
34+
</references>
35+
</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 HTTP URLs 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/http-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: 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)