Skip to content

Forbid index name . and .. #13862

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 5, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,9 @@ public void validateIndexName(String index, ClusterState state) {
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<ClusterStateUpdateResponse> listener, final Semaphore mdLock) {
Expand Down
20 changes: 19 additions & 1 deletion core/src/test/java/org/elasticsearch/indexing/IndexActionIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ public void testCreateIndexWithLongName() {

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");
Expand All @@ -215,4 +215,22 @@ public void testCreateIndexWithLongName() {
// 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));
}
}
}