From 128360856d50d7b39473644e6c1c21ba11766195 Mon Sep 17 00:00:00 2001 From: Erik Hatcher Date: Wed, 11 Dec 2019 12:36:14 -0500 Subject: [PATCH] SOLR-14025: VelocityResponseWriter hardening --- solr/CHANGES.txt | 3 + .../response/SolrParamResourceLoader.java | 73 -------- .../solr/response/VelocityResponseWriter.java | 133 ++++++++------- .../solr/collection1/conf/solrconfig.xml | 3 - .../collection1/conf/velocity/custom_tool.vm | 1 - .../solr/collection1/conf/velocity/foreach.vm | 1 - .../conf/velocity/locale_number.vm | 1 + .../conf/velocity/outside_the_box.vm | 2 +- .../conf/velocity/sandbox_intersection.vm | 2 +- solr/contrib/velocity/src/test/custom_tool.vm | 19 +++ solr/contrib/velocity/src/test/foreach.vm | 14 ++ .../velocity/VelocityResponseWriterTest.java | 157 ++++++++++++------ .../src/velocity-response-writer.adoc | 30 ++-- 13 files changed, 228 insertions(+), 211 deletions(-) delete mode 100644 solr/contrib/velocity/src/java/org/apache/solr/response/SolrParamResourceLoader.java delete mode 100644 solr/contrib/velocity/src/test-files/velocity/solr/collection1/conf/velocity/custom_tool.vm delete mode 100644 solr/contrib/velocity/src/test-files/velocity/solr/collection1/conf/velocity/foreach.vm create mode 100644 solr/contrib/velocity/src/test-files/velocity/solr/collection1/conf/velocity/locale_number.vm create mode 100644 solr/contrib/velocity/src/test/custom_tool.vm create mode 100644 solr/contrib/velocity/src/test/foreach.vm diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt index 5203372d2ff..f8400da0900 100644 --- a/solr/CHANGES.txt +++ b/solr/CHANGES.txt @@ -119,6 +119,9 @@ Upgrade Notes third-party components will work the same as before due to type erasure but source code changes may be required. +* SOLR-14025: VelocityResponseWriter has been hardened - only trusted configsets can render configset provided + templates and rendering templates from request parameters has been removed. + New Features --------------------- * SOLR-13821: A Package store to store and load package artifacts (noble, Ishan Chattopadhyaya) diff --git a/solr/contrib/velocity/src/java/org/apache/solr/response/SolrParamResourceLoader.java b/solr/contrib/velocity/src/java/org/apache/solr/response/SolrParamResourceLoader.java deleted file mode 100644 index dda63f6180b..00000000000 --- a/solr/contrib/velocity/src/java/org/apache/solr/response/SolrParamResourceLoader.java +++ /dev/null @@ -1,73 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.solr.response; - -import org.apache.solr.common.params.SolrParams; -import org.apache.solr.request.SolrQueryRequest; -import org.apache.velocity.runtime.resource.loader.ResourceLoader; -import org.apache.velocity.runtime.resource.Resource; -import org.apache.velocity.exception.ResourceNotFoundException; -import org.apache.velocity.util.ExtProperties; - -import java.io.Reader; -import java.io.StringReader; -import java.util.HashMap; -import java.util.Iterator; -import java.util.Map; - -public class SolrParamResourceLoader extends ResourceLoader { - public static final String TEMPLATE_PARAM_PREFIX = VelocityResponseWriter.TEMPLATE + "."; - - private Map templates = new HashMap<>(); - public SolrParamResourceLoader(SolrQueryRequest request) { - super(); - - // TODO: Consider using content streams, but need a template name associated with each stream - // for now, a custom param convention of template.=