You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by us...@apache.org on 2018/05/06 12:25:32 UTC
lucene-solr:branch_7x: SOLR-12316: Do not allow to use absolute URIs
for including other files in solrconfig.xml and schema parsing
Repository: lucene-solr
Updated Branches:
refs/heads/branch_7x 2558a06f3 -> 96f079b4b
SOLR-12316: Do not allow to use absolute URIs for including other files in solrconfig.xml and schema parsing
# Conflicts:
# solr/CHANGES.txt
Project: http://git-wip-us.apache.org/repos/asf/lucene-solr/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucene-solr/commit/96f079b4
Tree: http://git-wip-us.apache.org/repos/asf/lucene-solr/tree/96f079b4
Diff: http://git-wip-us.apache.org/repos/asf/lucene-solr/diff/96f079b4
Branch: refs/heads/branch_7x
Commit: 96f079b4b47eaadff65c7aaf0e5bafe68e30ec3b
Parents: 2558a06
Author: Uwe Schindler <us...@apache.org>
Authored: Sun May 6 14:21:34 2018 +0200
Committer: Uwe Schindler <us...@apache.org>
Committed: Sun May 6 14:25:17 2018 +0200
----------------------------------------------------------------------
solr/CHANGES.txt | 3 +++
.../org/apache/solr/util/SystemIdResolver.java | 14 ++++----------
.../apache/solr/util/TestSystemIdResolver.java | 19 +++++++++++++++++--
3 files changed, 24 insertions(+), 12 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/96f079b4/solr/CHANGES.txt
----------------------------------------------------------------------
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt
index 6eeb301..d201b28 100644
--- a/solr/CHANGES.txt
+++ b/solr/CHANGES.txt
@@ -186,6 +186,9 @@ Bug Fixes
* SOLR-12202: Fix errors in solr-exporter.cmd. (Minoru Osuka via koji)
+* 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
----------------------
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/96f079b4/solr/core/src/java/org/apache/solr/util/SystemIdResolver.java
----------------------------------------------------------------------
diff --git a/solr/core/src/java/org/apache/solr/util/SystemIdResolver.java b/solr/core/src/java/org/apache/solr/util/SystemIdResolver.java
index 6fda14f..c208520 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 {
@Override
public 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);
}
}
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/96f079b4/solr/core/src/test/org/apache/solr/util/TestSystemIdResolver.java
----------------------------------------------------------------------
diff --git a/solr/core/src/test/org/apache/solr/util/TestSystemIdResolver.java b/solr/core/src/test/org/apache/solr/util/TestSystemIdResolver.java
index 7980a59..4c2677d 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"));
}
}