diff --git a/core/src/main/java/org/elasticsearch/plugins/InstallPluginCommand.java b/core/src/main/java/org/elasticsearch/plugins/InstallPluginCommand.java index 697f99014dc..f9300d87dc0 100644 --- a/core/src/main/java/org/elasticsearch/plugins/InstallPluginCommand.java +++ b/core/src/main/java/org/elasticsearch/plugins/InstallPluginCommand.java @@ -160,9 +160,9 @@ class InstallPluginCommand extends CliTool.Command { return downloadZipAndChecksum(url, tmpDir); } - // now try as maven coordinates, a valid URL would only have a single colon + // now try as maven coordinates, a valid URL would only have a colon and slash String[] coordinates = pluginId.split(":"); - if (coordinates.length == 3) { + if (coordinates.length == 3 && pluginId.contains("/") == false) { String mavenUrl = String.format(Locale.ROOT, "https://repo1.maven.org/maven2/%1$s/%2$s/%3$s/%2$s-%3$s.zip", coordinates[0].replace(".", "/") /* groupId */, coordinates[1] /* artifactId */, coordinates[2] /* version */); terminal.println("-> Downloading " + pluginId + " from maven central"); diff --git a/qa/evil-tests/src/test/java/org/elasticsearch/plugins/InstallPluginCommandTests.java b/qa/evil-tests/src/test/java/org/elasticsearch/plugins/InstallPluginCommandTests.java index b61ba3c13ef..727728f84ab 100644 --- a/qa/evil-tests/src/test/java/org/elasticsearch/plugins/InstallPluginCommandTests.java +++ b/qa/evil-tests/src/test/java/org/elasticsearch/plugins/InstallPluginCommandTests.java @@ -20,6 +20,7 @@ package org.elasticsearch.plugins; import java.io.IOException; +import java.net.MalformedURLException; import java.net.URL; import java.nio.charset.StandardCharsets; import java.nio.file.DirectoryStream; @@ -205,6 +206,14 @@ public class InstallPluginCommandTests extends ESTestCase { assertPlugin("fake", pluginDir, env); } + public void testMalformedUrlNotMaven() throws Exception { + // has two colons, so it appears similar to maven coordinates + MalformedURLException e = expectThrows(MalformedURLException.class, () -> { + installPlugin("://host:1234", createEnv()); + }); + assertTrue(e.getMessage(), e.getMessage().contains("no protocol")); + } + public void testPluginsDirMissing() throws Exception { Environment env = createEnv(); Files.delete(env.pluginsFile());