Apache Lucene open-source search software
SOLR-12417: enforce valid function name for v.json
yonik107fd24ec784
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txtindex dbf99de4573..72af1ccbb70 100644--- a/solr/CHANGES.txt+++ b/solr/CHANGES.txt@@ -276,6 +276,8 @@ Bug Fixes* SOLR-12314: Use http timeout's defined in solr.xml for creating ConcurrentUpdateSolrClient duringindexing requests between leader and replica ( Mark Miller, Varun Thacker)+* SOLR-12417: velocity response writer should enforce valid function name for v.json parameter (yonik)+Optimizations----------------------diff --git a/solr/contrib/velocity/src/java/org/apache/solr/response/VelocityResponseWriter.java b/solr/contrib/velocity/src/java/org/apache/solr/response/VelocityResponseWriter.javaindex 133bc63284d..ad1ee39aec3 100644--- a/solr/contrib/velocity/src/java/org/apache/solr/response/VelocityResponseWriter.java+++ b/solr/contrib/velocity/src/java/org/apache/solr/response/VelocityResponseWriter.java@@ -35,6 +35,7 @@ import org.apache.commons.lang.StringUtils;import org.apache.solr.client.solrj.SolrResponse;import org.apache.solr.client.solrj.response.QueryResponse;import org.apache.solr.client.solrj.response.SolrResponseBase;+import org.apache.solr.common.SolrException;import org.apache.solr.common.params.CommonParams;import org.apache.solr.common.util.NamedList;import org.apache.solr.core.SolrCore;@@ -184,6 +185,11 @@ public class VelocityResponseWriter implements QueryResponseWriter, SolrCoreAwar}if (jsonWrapper != null) {+ for (int i=0; i<jsonWrapper.length(); i++) {+ if (!Character.isJavaIdentifierPart(jsonWrapper.charAt(i))) {+ throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "Invalid function name for " + JSON + ": '" + jsonWrapper + "'");+ }+ }writer.write(jsonWrapper + "(");writer.write(getJSONWrap(stringWriter.toString()));writer.write(')');diff --git a/solr/contrib/velocity/src/test/org/apache/solr/velocity/VelocityResponseWriterTest.java b/solr/contrib/velocity/src/test/org/apache/solr/velocity/VelocityResponseWriterTest.javaindex 336ee4bbde4..9b70e1b3468 100644--- a/solr/contrib/velocity/src/test/org/apache/solr/velocity/VelocityResponseWriterTest.java+++ b/solr/contrib/velocity/src/test/org/apache/solr/velocity/VelocityResponseWriterTest.java@@ -17,6 +17,7 @@package org.apache.solr.velocity;import org.apache.solr.SolrTestCaseJ4;+import org.apache.solr.common.SolrException;import org.apache.solr.common.util.NamedList;import org.apache.solr.response.QueryResponseWriter;import org.apache.solr.response.SolrParamResourceLoader;@@ -187,6 +188,11 @@ public class VelocityResponseWriterTest extends SolrTestCaseJ4 {VelocityResponseWriter.TEMPLATE, "numFound",VelocityResponseWriter.JSON,"foo",VelocityResponseWriter.LAYOUT,"layout")));++ assertQEx("Bad function name should throw exception", req("q", "*:*", "wt", "velocity",+ VelocityResponseWriter.TEMPLATE, "numFound",+ VelocityResponseWriter.JSON,"<foo>"), SolrException.ErrorCode.BAD_REQUEST+ );}@Test