Handle disabled Maven repositories

This commit is contained in:
Tony Torralba
2022-11-21 10:11:57 +01:00
parent a69524f7b4
commit 2809c3a77c
3 changed files with 23 additions and 1 deletions

View File

@@ -381,6 +381,15 @@ class DeclaredRepository extends PomElement {
* be the string contents of that tag.
*/
string getRepositoryUrl() { result = this.getAChild("url").(PomElement).getValue() }
/**
* Holds if this repository is disabled in both the `releases` and `snapshots` policies.
*/
predicate isDisabled() {
forex(PomElement policy | policy = this.getAChild(["releases", "snapshots"]) |
policy.getAChild("enabled").(PomElement).getValue() = "false"
)
}
}
/**

View File

@@ -17,7 +17,8 @@ import java
import semmle.code.xml.MavenPom
predicate isInsecureRepositoryUsage(DeclaredRepository repository) {
repository.getRepositoryUrl().regexpMatch("(?i)^(http|ftp)://(?!localhost[:/]).*")
repository.getRepositoryUrl().regexpMatch("(?i)^(http|ftp)://(?!localhost[:/]).*") and
not repository.isDisabled()
}
from DeclaredRepository repository

View File

@@ -61,5 +61,17 @@
<!-- GOOD! Use HTTPS -->
<url>https://insecure-repository.example</url>
</pluginRepository>
<pluginRepository>
<id>disabled-repo</id>
<name>Disabled Repository</name>
<releases>
<enabled>false</enabled>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
<!-- GOOD! Disabled repo -->
<url>http://insecure-repository.example</url>
</pluginRepository>
</pluginRepositories>
</project>