Merge pull request #11340 from atorralba/atorralba/disabled-poms

Java: Handle disabled Maven repositories
This commit is contained in:
Tony Torralba
2022-11-21 15:31:53 +01:00
committed by GitHub
4 changed files with 27 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

@@ -0,0 +1,4 @@
---
category: minorAnalysis
---
* The query `java/maven/non-https-url` no longer alerts about disabled repositories.

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>