From 668371c945b8ad4e5d263a9db3eb3d2bb2db8dd1 Mon Sep 17 00:00:00 2001 From: xuzha Date: Tue, 29 Sep 2015 12:17:51 -0700 Subject: [PATCH] Forbid index name with '.' and '..'. Fixes #13858 --- .../metadata/MetaDataCreateIndexService.java | 3 +++ .../elasticsearch/indexing/IndexActionIT.java | 20 ++++++++++++++++++- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/core/src/main/java/org/elasticsearch/cluster/metadata/MetaDataCreateIndexService.java b/core/src/main/java/org/elasticsearch/cluster/metadata/MetaDataCreateIndexService.java index 272bf61e777..99ce095df55 100644 --- a/core/src/main/java/org/elasticsearch/cluster/metadata/MetaDataCreateIndexService.java +++ b/core/src/main/java/org/elasticsearch/cluster/metadata/MetaDataCreateIndexService.java @@ -203,6 +203,9 @@ public class MetaDataCreateIndexService extends AbstractComponent { if (state.metaData().hasAlias(index)) { throw new InvalidIndexNameException(new Index(index), index, "already exists as alias"); } + if (index.equals(".") || index.equals("..")) { + throw new InvalidIndexNameException(new Index(index), index, "must not be '.' or '..'"); + } } private void createIndex(final CreateIndexClusterStateUpdateRequest request, final ActionListener listener, final Semaphore mdLock) { diff --git a/core/src/test/java/org/elasticsearch/indexing/IndexActionIT.java b/core/src/test/java/org/elasticsearch/indexing/IndexActionIT.java index 970084146a5..1c914c10c03 100644 --- a/core/src/test/java/org/elasticsearch/indexing/IndexActionIT.java +++ b/core/src/test/java/org/elasticsearch/indexing/IndexActionIT.java @@ -203,7 +203,7 @@ public class IndexActionIT extends ESIntegTestCase { try { // Catch chars that are more than a single byte - client().prepareIndex(randomAsciiOfLength(MetaDataCreateIndexService.MAX_INDEX_NAME_BYTES -1).toLowerCase(Locale.ROOT) + + client().prepareIndex(randomAsciiOfLength(MetaDataCreateIndexService.MAX_INDEX_NAME_BYTES - 1).toLowerCase(Locale.ROOT) + "Ϟ".toLowerCase(Locale.ROOT), "mytype").setSource("foo", "bar").get(); fail("exception should have been thrown on too-long index name"); @@ -215,4 +215,22 @@ public class IndexActionIT extends ESIntegTestCase { // we can create an index of max length createIndex(randomAsciiOfLength(MetaDataCreateIndexService.MAX_INDEX_NAME_BYTES).toLowerCase(Locale.ROOT)); } + + public void testInvalidIndexName() { + try { + createIndex("."); + fail("exception should have been thrown on dot index name"); + } catch (InvalidIndexNameException e) { + assertThat("exception contains message about index name is dot " + e.getMessage(), + e.getMessage().contains("Invalid index name [.], must not be \'.\' or '..'"), equalTo(true)); + } + + try { + createIndex(".."); + fail("exception should have been thrown on dot index name"); + } catch (InvalidIndexNameException e) { + assertThat("exception contains message about index name is dot " + e.getMessage(), + e.getMessage().contains("Invalid index name [..], must not be \'.\' or '..'"), equalTo(true)); + } + } }