Skip to content

Commit e51be1a

Browse files
authored
SOLR-18014: Improve filestore "getFrom" validation (#3925)
1 parent 64e029e commit e51be1a

File tree

5 files changed

+42
-1
lines changed

5 files changed

+42
-1
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# See https://github.com/apache/solr/blob/main/dev-docs/changelog.adoc
2+
title: Ensure File Store API "getFrom" param rejects values not in liveNodes
3+
type: security # added, changed, fixed, deprecated, removed, dependency_update, security, other
4+
authors:
5+
- name: Jason Gerlowski
6+
- name: monkeontheroof
7+
links:
8+
- name: SOLR-18014
9+
url: https://issues.apache.org/jira/browse/SOLR-18014

solr/api/src/java/org/apache/solr/client/api/endpoint/ClusterFileStoreApis.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,9 @@ SolrJerseyResponse fetchFile(
107107
@Parameter(description = "Path to a file or directory within the filestore")
108108
@PathParam("path")
109109
String path,
110-
@Parameter(description = "An optional Solr node name to fetch the file from")
110+
@Parameter(
111+
description =
112+
"An optional Solr node name to fetch the file from, typically in the form \"host:port_solr\".")
111113
@QueryParam("getFrom")
112114
String getFrom);
113115

solr/core/src/java/org/apache/solr/cloud/ZkController.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1297,6 +1297,9 @@ public void removeEphemeralLiveNode() throws KeeperException, InterruptedExcepti
12971297
});
12981298
}
12991299

1300+
/**
1301+
* @return the "live node" name of this Solr process, in the form "${host}:${port}_solr"
1302+
*/
13001303
public String getNodeName() {
13011304
return nodeName;
13021305
}

solr/core/src/java/org/apache/solr/filestore/ClusterFileStore.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
package org.apache.solr.filestore;
1919

2020
import static java.nio.charset.StandardCharsets.UTF_8;
21+
import static org.apache.solr.common.SolrException.ErrorCode.BAD_REQUEST;
2122
import static org.apache.solr.handler.admin.api.ReplicationAPIBase.FILE_STREAM;
2223
import static org.apache.solr.response.RawResponseWriter.CONTENT;
2324

@@ -320,6 +321,19 @@ public SolrJerseyResponse fetchFile(String path, String getFrom) {
320321
if (path == null) {
321322
path = "";
322323
}
324+
325+
// Ensure 'getFrom' points to a node in this cluster
326+
final var zkStateReader = coreContainer.getZkController().getZkStateReader();
327+
if (StrUtils.isNotBlank(getFrom)
328+
&& !getFrom.equals("*")
329+
&& !zkStateReader.isNodeLive(getFrom)) {
330+
throw new SolrException(
331+
BAD_REQUEST,
332+
"File store cannot fetch from source node ["
333+
+ getFrom
334+
+ "] as it does not appear in live-nodes");
335+
}
336+
323337
pullFileFromNode(coreContainer, fileStore, path, getFrom);
324338
return response;
325339
}

solr/core/src/test/org/apache/solr/filestore/TestDistribFileStore.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,19 @@ public void testFileStoreManagement() throws Exception {
169169
String url = baseUrl + "/cluster/filestore/metadata/package/mypkg/v1.0?wt=javabin";
170170
assertResponseValues(10, new Fetcher(url, jettySolrRunner), expected);
171171
}
172+
173+
// Ensure that invalid 'getFrom' parameter causes failures
174+
for (JettySolrRunner jettySolrRunner : cluster.getJettySolrRunners()) {
175+
final var fetchReq = new FileStoreApi.FetchFile("/package/mypkg/v1.0/runtimelibs.jar2");
176+
fetchReq.setGetFrom("someFakeSolrNode:8983_solr");
177+
try (final var solrClient = jettySolrRunner.newClient()) {
178+
final var asdf = fetchReq.process(solrClient);
179+
assertEquals(400, asdf.responseHeader.status);
180+
assertThat(asdf.error.msg, containsString("File store cannot fetch from source node"));
181+
assertThat(asdf.error.msg, containsString("does not appear in live-nodes"));
182+
}
183+
}
184+
172185
// Delete Jars
173186
DistribFileStore.deleteZKFileEntry(
174187
cluster.getZkClient(), "/package/mypkg/v1.0/runtimelibs.jar");

0 commit comments

Comments
 (0)