diff --git a/java/ql/src/Security/CWE/CWE-829/InsecureDependencyResolution.qhelp b/java/ql/src/Security/CWE/CWE-829/InsecureDependencyResolution.qhelp new file mode 100644 index 00000000000..c68f73ba2e1 --- /dev/null +++ b/java/ql/src/Security/CWE/CWE-829/InsecureDependencyResolution.qhelp @@ -0,0 +1,73 @@ + + + +

Using an insecure protocol like HTTP or FTP to download your dependencies leaves your Maven build vulnerable to a +Man in the Middle (MITM). +This can allow attackers to inject malicious code into the artifacts that you are resolving and infect build artifacts +that are being produced. This can be used by attackers to perform a +Supply chain attack +against your project's users. +

+ +

This vulnerability has a + + CVSS v3.1 base score of 8.1/10 +.

+ +
+ + +

Always use HTTPS or SFTP to download artifacts from artifact servers.

+ +
+ + + +

These examples show examples of locations in Maven POM files where artifact repository upload/download is configured. +The first shows the use of HTTP, the second shows the use of HTTPS. +

+ + + + + +
+ +
  • + Research: + + Want to take over the Java ecosystem? All you need is a MITM! + +
  • +
  • + Research: + + How to take over the computer of any Java (or Closure or Scala) Developer. + +
  • +
  • + Proof of Concept: + + mveytsman/dilettante + +
  • +
  • + Additional Gradle & Maven plugin: + + Announcing nohttp + +
  • +
  • + Java Ecosystem Announcement: + + HTTP Decommission Artifact Server Announcements + +
  • + + + +
    +
    diff --git a/java/ql/src/Security/CWE/CWE-829/InsecureDependencyResolution.ql b/java/ql/src/Security/CWE/CWE-829/InsecureDependencyResolution.ql new file mode 100644 index 00000000000..a8b21dc4f39 --- /dev/null +++ b/java/ql/src/Security/CWE/CWE-829/InsecureDependencyResolution.ql @@ -0,0 +1,38 @@ +/** + * @name Failure to use HTTPS or SFTP URL in Maven artifact upload/download + * @description Non-HTTPS connections can be intercepted by third parties. + * @kind path-problem + * @problem.severity error + * @precision very high + * @id java/maven/non-https-url + * @tags security + * external/cwe/cwe-319 + * external/cwe/cwe-494 + * external/cwe/cwe-829 + */ + +import java +import semmle.code.xml.MavenPom + +private class DeclaredRepository extends PomElement { + DeclaredRepository() { + this.getName() = "repository" or + this.getName() = "snapshotRepository" or + this.getName() = "pluginRepository" + } + + string getUrl() { + result = getAChild("url").(PomElement).getValue() + } + + predicate isInsecureRepositoryUsage() { + getUrl().matches("http://%") or + getUrl().matches("ftp://%") + } +} + +from DeclaredRepository repository +where repository.isInsecureRepositoryUsage() +select + repository, + "Downloading or uploading artifacts over insecure protocol (eg. http or ftp) to repository " + repository.getUrl() diff --git a/java/ql/src/Security/CWE/CWE-829/insecure-pom.xml b/java/ql/src/Security/CWE/CWE-829/insecure-pom.xml new file mode 100644 index 00000000000..fad05139c7e --- /dev/null +++ b/java/ql/src/Security/CWE/CWE-829/insecure-pom.xml @@ -0,0 +1,46 @@ + + + + 4.0.0 + + com.semmle + parent + 1.0 + pom + + Security Testing + An example of insecure download and upload of dependencies + + + + insecure-releases + Insecure Repository Releases + + http://insecure-repository.example + + + insecure-snapshots + Insecure Repository Snapshots + + http://insecure-repository.example + + + + + insecure + Insecure Repository + + http://insecure-repository.example + + + + + insecure-plugins + Insecure Repository Releases + + http://insecure-repository.example + + + diff --git a/java/ql/src/Security/CWE/CWE-829/secure-pom.xml b/java/ql/src/Security/CWE/CWE-829/secure-pom.xml new file mode 100644 index 00000000000..83ffdba79e8 --- /dev/null +++ b/java/ql/src/Security/CWE/CWE-829/secure-pom.xml @@ -0,0 +1,46 @@ + + + + 4.0.0 + + com.semmle + parent + 1.0 + pom + + Security Testing + An example of secure download and upload of dependencies + + + + insecure-releases + Secure Repository Releases + + https://insecure-repository.example + + + insecure-snapshots + Secure Repository Snapshots + + https://insecure-repository.example + + + + + insecure + Secure Repository + + https://insecure-repository.example + + + + + insecure-plugins + Secure Repository Releases + + https://insecure-repository.example + + +