Skip to content

Commit

Permalink
Serving _site plugins do not pick up on index.html for sub directories
Browse files Browse the repository at this point in the history
If one asks for `http://es:9200/_plugin/PLUGIN_NAME/` and the the plugin's _site directory contains an index.html file, it will be correctly served.

This is not the case for sub directories: a _site/folder/index.html is not served when requesting  `http://es:9200/_plugin/PLUGIN_NAME/folder/` but one gets a 403 Forbidden response as if trying to browse the folder.

Closes #4845.
  • Loading branch information
dadoonet committed Jan 28, 2014
1 parent 088968d commit 5ab23a7
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/main/java/org/elasticsearch/http/HttpServer.java
Expand Up @@ -177,8 +177,17 @@ void handlePluginSite(HttpRequest request, HttpChannel channel) {
return;
}
if (!file.isFile()) {
channel.sendResponse(new StringRestResponse(FORBIDDEN));
return;
// If it's not a dir, we send a 403
if (!file.isDirectory()) {
channel.sendResponse(new StringRestResponse(FORBIDDEN));
return;
}
// We don't serve dir but if index.html exists in dir we should serve it
file = new File(file, "index.html");
if (!file.exists() || file.isHidden() || !file.isFile()) {
channel.sendResponse(new StringRestResponse(FORBIDDEN));
return;
}
}
if (!file.getAbsolutePath().startsWith(siteFile.getAbsolutePath())) {
channel.sendResponse(new StringRestResponse(FORBIDDEN));
Expand Down
28 changes: 28 additions & 0 deletions src/test/java/org/elasticsearch/plugin/SitePluginTests.java
Expand Up @@ -74,4 +74,32 @@ public void testRedirectSitePlugin() throws Exception {
assertThat(response.errorCode(), equalTo(RestStatus.OK.getStatus()));
assertThat(response.response(), containsString("<title>Dummy Site Plugin</title>"));
}

/**
* Test direct access to an existing file (index.html)
*/
@Test
public void testAnyPage() throws Exception {
HttpClientResponse response = httpClient("test").request("/_plugin/dummy/index.html");
assertThat(response.errorCode(), equalTo(RestStatus.OK.getStatus()));
assertThat(response.response(), containsString("<title>Dummy Site Plugin</title>"));
}

/**
* Test case for #4845: https://github.com/elasticsearch/elasticsearch/issues/4845
* Serving _site plugins do not pick up on index.html for sub directories
*/
@Test
public void testWelcomePageInSubDirs() throws Exception {
HttpClientResponse response = httpClient("test").request("/_plugin/subdir/dir/");
assertThat(response.errorCode(), equalTo(RestStatus.OK.getStatus()));
assertThat(response.response(), containsString("<title>Dummy Site Plugin (subdir)</title>"));

response = httpClient("test").request("/_plugin/subdir/dir_without_index/");
assertThat(response.errorCode(), equalTo(RestStatus.FORBIDDEN.getStatus()));

response = httpClient("test").request("/_plugin/subdir/dir_without_index/page.html");
assertThat(response.errorCode(), equalTo(RestStatus.OK.getStatus()));
assertThat(response.response(), containsString("<title>Dummy Site Plugin (page)</title>"));
}
}
@@ -0,0 +1,9 @@
<!DOCTYPE html>
<html>
<head>
<title>Dummy Site Plugin (subdir)</title>
</head>
<body>
<p>Welcome to this dummy elasticsearch plugin</p>
</body>
</html>
@@ -0,0 +1,9 @@
<!DOCTYPE html>
<html>
<head>
<title>Dummy Site Plugin (page)</title>
</head>
<body>
<p>Welcome to this dummy elasticsearch plugin</p>
</body>
</html>

0 comments on commit 5ab23a7

Please sign in to comment.