Skip to content

armgit / solr

Public Imported from GitHub
0

Apache Solr open-source search software

SOLR-15169 SolrPaths.assertPathAllowed normalization problem (#22)

András Salamon963a81de1453
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt
index f83b9fd6be2..291fae0a9f8 100644
--- a/solr/CHANGES.txt
+++ b/solr/CHANGES.txt
@@ -242,6 +242,8 @@ Other Changes
* SOLR-15121: Move XSLT (tr param) response writer and update request handler to scripting contrib. (Eric Pugh, David Smiley)
+* SOLR-15169: SolrPaths.assertPathAllowed normalization problem (Andras Salamon via janhoy)
+
* SOLR-15292: SignatureUpdateProcessorFactory will fail to initialize if it is used in a SolrCloud cluster in a way that is
known to be problematic with multiple replicas. (hossman)
diff --git a/solr/core/src/java/org/apache/solr/core/CoreContainer.java b/solr/core/src/java/org/apache/solr/core/CoreContainer.java
index 0e6126edd22..88c71f5d9db 100644
--- a/solr/core/src/java/org/apache/solr/core/CoreContainer.java
+++ b/solr/core/src/java/org/apache/solr/core/CoreContainer.java
@@ -43,6 +43,7 @@ import java.util.concurrent.ExecutorService;
import java.util.concurrent.Future;
import java.util.concurrent.TimeoutException;
import java.util.function.Supplier;
+import java.util.stream.Collectors;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.collect.ImmutableMap;
@@ -373,13 +374,13 @@ public class CoreContainer {
new SolrNamedThreadFactory("replayUpdatesExecutor")));
this.allowPaths = new java.util.HashSet<>();
- this.allowPaths.add(cfg.getSolrHome());
- this.allowPaths.add(cfg.getCoreRootDirectory());
+ addToAllowPath(cfg.getSolrHome());
+ addToAllowPath(cfg.getCoreRootDirectory());
if (cfg.getSolrDataHome() != null) {
- this.allowPaths.add(cfg.getSolrDataHome());
+ addToAllowPath(cfg.getSolrDataHome());
}
if (!cfg.getAllowPaths().isEmpty()) {
- this.allowPaths.addAll(cfg.getAllowPaths());
+ addAllToAllowPath(cfg.getAllowPaths());
if (log.isInfoEnabled()) {
log.info("Allowing use of paths: {}", cfg.getAllowPaths());
}
@@ -393,6 +394,14 @@ public class CoreContainer {
}
}
+ private void addToAllowPath(Path path) {
+ this.allowPaths.add(path.normalize());
+ }
+
+ private void addAllToAllowPath(Set<Path> paths) {
+ this.allowPaths.addAll(paths.stream().map( path -> path.normalize()).collect(Collectors.toSet()));
+ }
+
@SuppressWarnings({"unchecked"})
private synchronized void initializeAuthorizationPlugin(Map<String, Object> authorizationConf) {
authorizationConf = Utils.getDeepCopy(authorizationConf, 4);
diff --git a/solr/core/src/test/org/apache/solr/core/TestCoreContainer.java b/solr/core/src/test/org/apache/solr/core/TestCoreContainer.java
index 2d408f2c19e..1dc977e0b6f 100644
--- a/solr/core/src/test/org/apache/solr/core/TestCoreContainer.java
+++ b/solr/core/src/test/org/apache/solr/core/TestCoreContainer.java
@@ -609,6 +609,28 @@ public class TestCoreContainer extends SolrTestCaseJ4 {
assertPathBlocked("\\\\unc-server\\share\\path");
}
+ @Test
+ public void assertAllowPathNormalization() throws Exception {
+ Assume.assumeFalse(OS.isFamilyWindows());
+ System.setProperty("solr.allowPaths", "/var/solr/../solr");
+ CoreContainer cc = init(ALLOW_PATHS_SOLR_XML);
+ cc.assertPathAllowed(Paths.get("/var/solr/foo"));
+ assertThrows("Path /tmp should not be allowed", SolrException.class, () -> { cc.assertPathAllowed(Paths.get("/tmp")); });
+ cc.shutdown();
+ System.clearProperty("solr.allowPaths");
+ }
+
+ @Test
+ public void assertAllowPathNormalizationWin() throws Exception {
+ Assume.assumeTrue(OS.isFamilyWindows());
+ System.setProperty("solr.allowPaths", "C:\\solr\\..\\solr");
+ CoreContainer cc = init(ALLOW_PATHS_SOLR_XML);
+ cc.assertPathAllowed(Paths.get("C:\\solr\\foo"));
+ assertThrows("Path C:\\tmp should not be allowed", SolrException.class, () -> { cc.assertPathAllowed(Paths.get("C:\\tmp")); });
+ cc.shutdown();
+ System.clearProperty("solr.allowPaths");
+ }
+
private static Set<Path> ALLOWED_PATHS = Set.of(Path.of("/var/solr"));
private static Set<Path> ALLOWED_PATHS_WIN = Set.of(Path.of("C:\\var\\solr"));