Skip to content

Commit 98d527c

Browse files
authored
Merge pull request #2685 from esbena/java/sharpen-maven-non-ssl
java: sharpen java/maven/non-https-url to allow localhost URLs
2 parents ee0648b + 8deefd6 commit 98d527c

File tree

4 files changed

+27
-4
lines changed

4 files changed

+27
-4
lines changed

java/ql/src/Security/CWE/CWE-829/InsecureDependencyResolution.ql

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@ private class DeclaredRepository extends PomElement {
2525
string getUrl() { result = getAChild("url").(PomElement).getValue() }
2626

2727
predicate isInsecureRepositoryUsage() {
28-
getUrl().matches("http://%") or
29-
getUrl().matches("ftp://%")
28+
getUrl().regexpMatch("(?i)^(http|ftp)://(?!localhost[:/]).*")
3029
}
3130
}
3231

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
| insecure-pom.xml:19:9:24:22 | repository | Downloading or uploading artifacts over insecure protocol (eg. http or ftp) to/from repository http://insecure-repository.example |
22
| insecure-pom.xml:25:9:30:30 | snapshotRepository | Downloading or uploading artifacts over insecure protocol (eg. http or ftp) to/from repository http://insecure-repository.example |
3-
| insecure-pom.xml:33:9:38:22 | repository | Downloading or uploading artifacts over insecure protocol (eg. http or ftp) to/from repository http://insecure-repository.example |
4-
| insecure-pom.xml:41:9:46:28 | pluginRepository | Downloading or uploading artifacts over insecure protocol (eg. http or ftp) to/from repository http://insecure-repository.example |
3+
| insecure-pom.xml:31:9:36:30 | snapshotRepository | Downloading or uploading artifacts over insecure protocol (eg. http or ftp) to/from repository http://localhost.example |
4+
| insecure-pom.xml:39:9:44:22 | repository | Downloading or uploading artifacts over insecure protocol (eg. http or ftp) to/from repository http://insecure-repository.example |
5+
| insecure-pom.xml:47:9:52:28 | pluginRepository | Downloading or uploading artifacts over insecure protocol (eg. http or ftp) to/from repository http://insecure-repository.example |

java/ql/test/query-tests/security/CWE-829/semmle/tests/insecure-pom.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,12 @@
2828
<!-- BAD! Use HTTPS -->
2929
<url>http://insecure-repository.example</url>
3030
</snapshotRepository>
31+
<snapshotRepository>
32+
<id>insecure-snapshots</id>
33+
<name>Insecure Repository Snapshots</name>
34+
<!-- BAD! Use HTTPS -->
35+
<url>http://localhost.example</url>
36+
</snapshotRepository>
3137
</distributionManagement>
3238
<repositories>
3339
<repository>

java/ql/test/query-tests/security/CWE-829/semmle/tests/secure-pom.xml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,18 @@
2828
<!-- GOOD! Use HTTPS -->
2929
<url>https://insecure-repository.example</url>
3030
</snapshotRepository>
31+
<snapshotRepository>
32+
<id>insecure-snapshots</id>
33+
<name>Secure Repository Snapshots</name>
34+
<!-- GOOD! Use HTTP, but for localhost -->
35+
<url>http://localhost/snaphots</url>
36+
</snapshotRepository>
37+
<snapshotRepository>
38+
<id>insecure-snapshots</id>
39+
<name>Secure Repository Snapshots</name>
40+
<!-- GOOD! Use HTTP, but for localhost -->
41+
<url>http://localhost:82</url>
42+
</snapshotRepository>
3143
</distributionManagement>
3244
<repositories>
3345
<repository>
@@ -36,6 +48,11 @@
3648
<!-- GOOD! Use HTTPS -->
3749
<url>https://insecure-repository.example</url>
3850
</repository>
51+
<repository>
52+
<id>test</id>
53+
<!-- GOOD! Use HTTP, but for localhost -->
54+
<url>http://localhost:${deploy.webserver.port}/repo</url>
55+
</repository>
3956
</repositories>
4057
<pluginRepositories>
4158
<pluginRepository>

0 commit comments

Comments
 (0)