Skip to content

Commit 2809c3a

Browse files
committed
Handle disabled Maven repositories
1 parent a69524f commit 2809c3a

File tree

3 files changed

+23
-1
lines changed

3 files changed

+23
-1
lines changed

java/ql/lib/semmle/code/xml/MavenPom.qll

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,15 @@ class DeclaredRepository extends PomElement {
381381
* be the string contents of that tag.
382382
*/
383383
string getRepositoryUrl() { result = this.getAChild("url").(PomElement).getValue() }
384+
385+
/**
386+
* Holds if this repository is disabled in both the `releases` and `snapshots` policies.
387+
*/
388+
predicate isDisabled() {
389+
forex(PomElement policy | policy = this.getAChild(["releases", "snapshots"]) |
390+
policy.getAChild("enabled").(PomElement).getValue() = "false"
391+
)
392+
}
384393
}
385394

386395
/**

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ import java
1717
import semmle.code.xml.MavenPom
1818

1919
predicate isInsecureRepositoryUsage(DeclaredRepository repository) {
20-
repository.getRepositoryUrl().regexpMatch("(?i)^(http|ftp)://(?!localhost[:/]).*")
20+
repository.getRepositoryUrl().regexpMatch("(?i)^(http|ftp)://(?!localhost[:/]).*") and
21+
not repository.isDisabled()
2122
}
2223

2324
from DeclaredRepository repository

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,5 +61,17 @@
6161
<!-- GOOD! Use HTTPS -->
6262
<url>https://insecure-repository.example</url>
6363
</pluginRepository>
64+
<pluginRepository>
65+
<id>disabled-repo</id>
66+
<name>Disabled Repository</name>
67+
<releases>
68+
<enabled>false</enabled>
69+
</releases>
70+
<snapshots>
71+
<enabled>false</enabled>
72+
</snapshots>
73+
<!-- GOOD! Disabled repo -->
74+
<url>http://insecure-repository.example</url>
75+
</pluginRepository>
6476
</pluginRepositories>
6577
</project>

0 commit comments

Comments
 (0)