|
32 | 32 |
|
33 | 33 | import java.io.File;
|
34 | 34 | import java.net.URISyntaxException;
|
| 35 | +import java.util.ArrayList; |
| 36 | +import java.util.List; |
| 37 | +import java.util.Locale; |
35 | 38 |
|
36 | 39 | import static org.elasticsearch.common.settings.ImmutableSettings.settingsBuilder;
|
37 | 40 | import static org.elasticsearch.test.ElasticsearchIntegrationTest.Scope;
|
@@ -88,6 +91,34 @@ public void testAnyPage() throws Exception {
|
88 | 91 | assertThat(response.getBody(), containsString("<title>Dummy Site Plugin</title>"));
|
89 | 92 | }
|
90 | 93 |
|
| 94 | + /** |
| 95 | + * Test normalizing of path |
| 96 | + */ |
| 97 | + @Test |
| 98 | + public void testThatPathsAreNormalized() throws Exception { |
| 99 | + // more info: https://www.owasp.org/index.php/Path_Traversal |
| 100 | + List<String> notFoundUris = new ArrayList<>(); |
| 101 | + notFoundUris.add("/_plugin/dummy/../../../../../log4j.properties"); |
| 102 | + notFoundUris.add("/_plugin/dummy/../../../../../%00log4j.properties"); |
| 103 | + notFoundUris.add("/_plugin/dummy/..%c0%af..%c0%af..%c0%af..%c0%af..%c0%aflog4j.properties"); |
| 104 | + notFoundUris.add("/_plugin/dummy/%2E%2E/%2E%2E/%2E%2E/%2E%2E/index.html"); |
| 105 | + notFoundUris.add("/_plugin/dummy/%2e%2e/%2e%2e/%2e%2e/%2e%2e/index.html"); |
| 106 | + notFoundUris.add("/_plugin/dummy/%2e%2e%2f%2e%2e%2f%2e%2e%2f%2e%2e%2findex.html"); |
| 107 | + notFoundUris.add("/_plugin/dummy/%2E%2E/%2E%2E/%2E%2E/%2E%2E/index.html"); |
| 108 | + notFoundUris.add("/_plugin/dummy/..\\..\\..\\..\\..\\log4j.properties"); |
| 109 | + |
| 110 | + for (String uri : notFoundUris) { |
| 111 | + HttpResponse response = httpClient().path(uri).execute(); |
| 112 | + String message = String.format(Locale.ROOT, "URI [%s] expected to be not found", uri); |
| 113 | + assertThat(message, response.getStatusCode(), equalTo(RestStatus.NOT_FOUND.getStatus())); |
| 114 | + } |
| 115 | + |
| 116 | + // using relative path inside of the plugin should work |
| 117 | + HttpResponse response = httpClient().path("/_plugin/dummy/dir1/../dir1/../index.html").execute(); |
| 118 | + assertThat(response.getStatusCode(), equalTo(RestStatus.OK.getStatus())); |
| 119 | + assertThat(response.getBody(), containsString("<title>Dummy Site Plugin</title>")); |
| 120 | + } |
| 121 | + |
91 | 122 | /**
|
92 | 123 | * Test case for #4845: https://github.com/elasticsearch/elasticsearch/issues/4845
|
93 | 124 | * Serving _site plugins do not pick up on index.html for sub directories
|
|
0 commit comments