Apache Lucene open-source search software
SOLR-12316: Do not allow to use absolute URIs for including other files in solrconfig.xml and schema parsing
Uwe Schindler1b760114216f
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txtindex efebe91a751..48f9ad5d910 100644--- a/solr/CHANGES.txt+++ b/solr/CHANGES.txt@@ -212,6 +212,9 @@ Bug Fixes* SOLR-12293: Updates need to use their own connection pool to maintain connection reuse and prevent spuriousrecoveries. (Mark Miller)+* SOLR-12316: Do not allow to use absolute URIs for including other files in solrconfig.xml and schema parsing.+ (Ananthesh, Ishan Chattopadhyaya, Uwe Schindler)+Optimizations----------------------diff --git a/solr/core/src/java/org/apache/solr/util/SystemIdResolver.java b/solr/core/src/java/org/apache/solr/util/SystemIdResolver.javaindex 6fda14fdd50..c2085209a40 100644--- a/solr/core/src/java/org/apache/solr/util/SystemIdResolver.java+++ b/solr/core/src/java/org/apache/solr/util/SystemIdResolver.java@@ -16,9 +16,6 @@*/package org.apache.solr.util;-import org.slf4j.Logger;-import org.slf4j.LoggerFactory;-import org.apache.lucene.analysis.util.ResourceLoader;import org.xml.sax.InputSource;@@ -26,7 +23,6 @@ import org.xml.sax.EntityResolver;import org.xml.sax.ext.EntityResolver2;import java.io.File;import java.io.IOException;-import java.lang.invoke.MethodHandles;import java.net.URI;import java.net.URISyntaxException;import javax.xml.transform.Source;@@ -55,7 +51,6 @@ import javax.xml.stream.XMLStreamException;* </pre>*/public final class SystemIdResolver implements EntityResolver, EntityResolver2 {- private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());public static final String RESOURCE_LOADER_URI_SCHEME = "solrres";public static final String RESOURCE_LOADER_AUTHORITY_ABSOLUTE = "@";@@ -126,8 +121,9 @@ public final class SystemIdResolver implements EntityResolver, EntityResolver2 {@Overridepublic InputSource resolveEntity(String name, String publicId, String baseURI, String systemId) throws IOException {- if (systemId == null)+ if (systemId == null) {return null;+ }try {final URI uri = resolveRelativeURI(baseURI, systemId);@@ -147,12 +143,10 @@ public final class SystemIdResolver implements EntityResolver, EntityResolver2 {throw new IOException(re.getMessage(), re);}} else {- // resolve all other URIs using the standard resolver- return null;+ throw new IOException("Cannot resolve absolute systemIDs / external entities (only relative paths work): " + systemId);}} catch (URISyntaxException use) {- log.warn("An URI systax problem occurred during resolving SystemId, falling back to default resolver", use);- return null;+ throw new IOException("An URI syntax problem occurred during resolving systemId: " + systemId, use);}}diff --git a/solr/core/src/test/org/apache/solr/util/TestSystemIdResolver.java b/solr/core/src/test/org/apache/solr/util/TestSystemIdResolver.javaindex 7980a592483..4c2677df690 100644--- a/solr/core/src/test/org/apache/solr/util/TestSystemIdResolver.java+++ b/solr/core/src/test/org/apache/solr/util/TestSystemIdResolver.java@@ -17,6 +17,7 @@package org.apache.solr.util;import java.io.File;+import java.io.IOException;import java.nio.file.Path;import org.apache.commons.io.IOUtils;@@ -76,8 +77,22 @@ public class TestSystemIdResolver extends LuceneTestCase {assertEntityResolving(resolver, SystemIdResolver.createSystemIdFromResourceName(testHome+"/crazy-path-to-schema.xml"),SystemIdResolver.createSystemIdFromResourceName(testHome+"/crazy-path-to-config.xml"), "crazy-path-to-schema.xml");- // test, that resolving works if somebody uses an absolute file:-URI in a href attribute, the resolver should return null (default fallback)- assertNull(resolver.resolveEntity(null, null, "solrres:/solrconfig.xml", fileUri));+ // if somebody uses an absolute uri (e.g., file://) we should fail resolving:+ IOException ioe = expectThrows(IOException.class, () -> {+ resolver.resolveEntity(null, null, "solrres:/solrconfig.xml", fileUri);+ });+ assertTrue(ioe.getMessage().startsWith("Cannot resolve absolute"));++ ioe = expectThrows(IOException.class, () -> {+ resolver.resolveEntity(null, null, "solrres:/solrconfig.xml", "http://lucene.apache.org/test.xml");+ });+ assertTrue(ioe.getMessage().startsWith("Cannot resolve absolute"));++ // check that we can't escape with absolute file paths:+ ioe = expectThrows(IOException.class, () -> {+ resolver.resolveEntity(null, null, "solrres:/solrconfig.xml", "/etc/passwd");+ });+ assertTrue(ioe.getMessage().startsWith("Can't find resource '/etc/passwd' in classpath or"));}}