Skip to content

Commit 6d082d5

Browse files
uschindlerIshan Chattopadhyaya
authored and
Ishan Chattopadhyaya
committed
SOLR-12316: Do not allow to use absolute URIs for including other files in solrconfig.xml and schema parsing
# Conflicts: # solr/CHANGES.txt
1 parent ec50b22 commit 6d082d5

File tree

3 files changed

+43
-12
lines changed

3 files changed

+43
-12
lines changed

solr/CHANGES.txt

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,9 @@ when using one of Exact*StatsCache (Mikhail Khludnev)
155155
* SOLR-11177: CoreContainer.load needs to send lazily loaded core descriptors to the proper list rather than send
156156
them all to the transient lists. (Erick Erickson)
157157

158+
* SOLR-12316: Do not allow to use absolute URIs for including other files in solrconfig.xml and schema parsing.
159+
(Ananthesh, Ishan Chattopadhyaya, Uwe Schindler)
160+
158161
Optimizations
159162
----------------------
160163
* SOLR-10634: JSON Facet API: When a field/terms facet will retrieve all buckets (i.e. limit:-1)
@@ -218,6 +221,25 @@ Other Changes
218221
* SOLR-11122: Creating a core should write a core.properties file first and clean up on failure
219222
(Erick Erickson)
220223

224+
================== 6.6.4 ==================
225+
226+
Consult the LUCENE_CHANGES.txt file for additional, low level, changes in this release.
227+
228+
Versions of Major Components
229+
---------------------
230+
Apache Tika 1.13
231+
Carrot2 3.15.0
232+
Velocity 1.7 and Velocity Tools 2.0
233+
Apache UIMA 2.3.1
234+
Apache ZooKeeper 3.4.10
235+
Jetty 9.3.14.v20161028
236+
237+
Bug Fixes
238+
----------------------
239+
240+
* SOLR-12316: Do not allow to use absolute URIs for including other files in solrconfig.xml and schema parsing.
241+
(Ananthesh, Ishan Chattopadhyaya, Uwe Schindler)
242+
221243
================== 6.6.3 ==================
222244

223245
Consult the LUCENE_CHANGES.txt file for additional, low level, changes in this release.

solr/core/src/java/org/apache/solr/util/SystemIdResolver.java

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,13 @@
1616
*/
1717
package org.apache.solr.util;
1818

19-
import org.slf4j.Logger;
20-
import org.slf4j.LoggerFactory;
21-
2219
import org.apache.lucene.analysis.util.ResourceLoader;
2320

2421
import org.xml.sax.InputSource;
2522
import org.xml.sax.EntityResolver;
2623
import org.xml.sax.ext.EntityResolver2;
2724
import java.io.File;
2825
import java.io.IOException;
29-
import java.lang.invoke.MethodHandles;
3026
import java.net.URI;
3127
import java.net.URISyntaxException;
3228
import javax.xml.transform.Source;
@@ -55,7 +51,6 @@
5551
* </pre>
5652
*/
5753
public final class SystemIdResolver implements EntityResolver, EntityResolver2 {
58-
private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
5954

6055
public static final String RESOURCE_LOADER_URI_SCHEME = "solrres";
6156
public static final String RESOURCE_LOADER_AUTHORITY_ABSOLUTE = "@";
@@ -126,8 +121,9 @@ public InputSource getExternalSubset(String name, String baseURI) {
126121

127122
@Override
128123
public InputSource resolveEntity(String name, String publicId, String baseURI, String systemId) throws IOException {
129-
if (systemId == null)
124+
if (systemId == null) {
130125
return null;
126+
}
131127
try {
132128
final URI uri = resolveRelativeURI(baseURI, systemId);
133129

@@ -147,12 +143,10 @@ public InputSource resolveEntity(String name, String publicId, String baseURI, S
147143
throw new IOException(re.getMessage(), re);
148144
}
149145
} else {
150-
// resolve all other URIs using the standard resolver
151-
return null;
146+
throw new IOException("Cannot resolve absolute systemIDs / external entities (only relative paths work): " + systemId);
152147
}
153148
} catch (URISyntaxException use) {
154-
log.warn("An URI systax problem occurred during resolving SystemId, falling back to default resolver", use);
155-
return null;
149+
throw new IOException("An URI syntax problem occurred during resolving systemId: " + systemId, use);
156150
}
157151
}
158152

solr/core/src/test/org/apache/solr/util/TestSystemIdResolver.java

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package org.apache.solr.util;
1818

1919
import java.io.File;
20+
import java.io.IOException;
2021
import java.nio.file.Path;
2122

2223
import org.apache.commons.io.IOUtils;
@@ -76,8 +77,22 @@ public void testResolving() throws Exception {
7677
assertEntityResolving(resolver, SystemIdResolver.createSystemIdFromResourceName(testHome+"/crazy-path-to-schema.xml"),
7778
SystemIdResolver.createSystemIdFromResourceName(testHome+"/crazy-path-to-config.xml"), "crazy-path-to-schema.xml");
7879

79-
// test, that resolving works if somebody uses an absolute file:-URI in a href attribute, the resolver should return null (default fallback)
80-
assertNull(resolver.resolveEntity(null, null, "solrres:/solrconfig.xml", fileUri));
80+
// if somebody uses an absolute uri (e.g., file://) we should fail resolving:
81+
IOException ioe = expectThrows(IOException.class, () -> {
82+
resolver.resolveEntity(null, null, "solrres:/solrconfig.xml", fileUri);
83+
});
84+
assertTrue(ioe.getMessage().startsWith("Cannot resolve absolute"));
85+
86+
ioe = expectThrows(IOException.class, () -> {
87+
resolver.resolveEntity(null, null, "solrres:/solrconfig.xml", "http://lucene.apache.org/test.xml");
88+
});
89+
assertTrue(ioe.getMessage().startsWith("Cannot resolve absolute"));
90+
91+
// check that we can't escape with absolute file paths:
92+
ioe = expectThrows(IOException.class, () -> {
93+
resolver.resolveEntity(null, null, "solrres:/solrconfig.xml", "/etc/passwd");
94+
});
95+
assertTrue(ioe.getMessage().startsWith("Can't find resource '/etc/passwd' in classpath or"));
8196
}
8297

8398
}

0 commit comments

Comments
 (0)