Skip to content

Commit 83366e7

Browse files
committed
Merge pull request #13862 from xuzha/index_name_dot
Forbid index name `.` and `..`
2 parents d3cef85 + 668371c commit 83366e7

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

core/src/main/java/org/elasticsearch/cluster/metadata/MetaDataCreateIndexService.java

+3
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,9 @@ public void validateIndexName(String index, ClusterState state) {
203203
if (state.metaData().hasAlias(index)) {
204204
throw new InvalidIndexNameException(new Index(index), index, "already exists as alias");
205205
}
206+
if (index.equals(".") || index.equals("..")) {
207+
throw new InvalidIndexNameException(new Index(index), index, "must not be '.' or '..'");
208+
}
206209
}
207210

208211
private void createIndex(final CreateIndexClusterStateUpdateRequest request, final ActionListener<ClusterStateUpdateResponse> listener, final Semaphore mdLock) {

core/src/test/java/org/elasticsearch/indexing/IndexActionIT.java

+19-1
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ public void testCreateIndexWithLongName() {
203203

204204
try {
205205
// Catch chars that are more than a single byte
206-
client().prepareIndex(randomAsciiOfLength(MetaDataCreateIndexService.MAX_INDEX_NAME_BYTES -1).toLowerCase(Locale.ROOT) +
206+
client().prepareIndex(randomAsciiOfLength(MetaDataCreateIndexService.MAX_INDEX_NAME_BYTES - 1).toLowerCase(Locale.ROOT) +
207207
"Ϟ".toLowerCase(Locale.ROOT),
208208
"mytype").setSource("foo", "bar").get();
209209
fail("exception should have been thrown on too-long index name");
@@ -215,4 +215,22 @@ public void testCreateIndexWithLongName() {
215215
// we can create an index of max length
216216
createIndex(randomAsciiOfLength(MetaDataCreateIndexService.MAX_INDEX_NAME_BYTES).toLowerCase(Locale.ROOT));
217217
}
218+
219+
public void testInvalidIndexName() {
220+
try {
221+
createIndex(".");
222+
fail("exception should have been thrown on dot index name");
223+
} catch (InvalidIndexNameException e) {
224+
assertThat("exception contains message about index name is dot " + e.getMessage(),
225+
e.getMessage().contains("Invalid index name [.], must not be \'.\' or '..'"), equalTo(true));
226+
}
227+
228+
try {
229+
createIndex("..");
230+
fail("exception should have been thrown on dot index name");
231+
} catch (InvalidIndexNameException e) {
232+
assertThat("exception contains message about index name is dot " + e.getMessage(),
233+
e.getMessage().contains("Invalid index name [..], must not be \'.\' or '..'"), equalTo(true));
234+
}
235+
}
218236
}

0 commit comments

Comments
 (0)