Fixed: Server-Side Template Injection using Static (OFBIZ-11871)
Thanks to Alvaro's explanations, the problem was in MacroFormRenderer where, for lookups, we retrieve _LAST_VIEW_NAME_ as a parameter without encoding it. I have added getEncodedParameter method in UtilHttp and removed now useless (after OFBIZ-11907) getEnvironment from MacroFormRenderer.java Thanks: Alvaro for advice
This commit is contained in:
@@ -31,8 +31,10 @@ import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.net.FileNameMap;
|
||||
import java.net.URLConnection;
|
||||
import java.net.URLEncoder;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.sql.Timestamp;
|
||||
import java.time.LocalDateTime;
|
||||
@@ -756,7 +758,7 @@ public final class UtilHttp {
|
||||
* check first the parameter _method before return the request method
|
||||
*
|
||||
* @param request
|
||||
* @return
|
||||
* @return method
|
||||
*/
|
||||
public static String getRequestMethod(HttpServletRequest request) {
|
||||
return request.getParameter("_method") != null
|
||||
@@ -1049,6 +1051,15 @@ public final class UtilHttp {
|
||||
return buf.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Encodes a query parameter
|
||||
*
|
||||
* @throws UnsupportedEncodingException
|
||||
*/
|
||||
public static String getEncodedParameter(String parameter) throws UnsupportedEncodingException {
|
||||
return URLEncoder.encode(parameter, "UTF-8");
|
||||
}
|
||||
|
||||
public static String getRequestUriFromTarget(String target) {
|
||||
if (UtilValidate.isEmpty(target)) {
|
||||
return null;
|
||||
|
||||
+2
-11
@@ -38,7 +38,6 @@ import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import javax.servlet.http.HttpSession;
|
||||
|
||||
import org.apache.ofbiz.security.CsrfUtil;
|
||||
import org.apache.ofbiz.base.util.Debug;
|
||||
import org.apache.ofbiz.base.util.StringUtil;
|
||||
import org.apache.ofbiz.base.util.UtilCodec;
|
||||
@@ -51,6 +50,7 @@ import org.apache.ofbiz.base.util.UtilValidate;
|
||||
import org.apache.ofbiz.base.util.string.FlexibleStringExpander;
|
||||
import org.apache.ofbiz.base.util.template.FreeMarkerWorker;
|
||||
import org.apache.ofbiz.entity.Delegator;
|
||||
import org.apache.ofbiz.security.CsrfUtil;
|
||||
import org.apache.ofbiz.webapp.control.RequestHandler;
|
||||
import org.apache.ofbiz.webapp.taglib.ContentUrlTag;
|
||||
import org.apache.ofbiz.widget.WidgetWorker;
|
||||
@@ -171,16 +171,6 @@ public final class MacroFormRenderer implements FormStringRenderer {
|
||||
ftlWriter.executeMacro(writer, macro);
|
||||
}
|
||||
|
||||
private Environment getEnvironment(Appendable writer) throws TemplateException, IOException {
|
||||
Environment environment = environments.get(writer);
|
||||
if (environment == null) {
|
||||
Map<String, Object> input = UtilMisc.toMap("key", null);
|
||||
environment = FreeMarkerWorker.renderTemplate(macroLibrary, input, writer);
|
||||
environments.put(writer, environment);
|
||||
}
|
||||
return environment;
|
||||
}
|
||||
|
||||
private String encode(String value, ModelFormField modelFormField, Map<String, Object> context) {
|
||||
if (UtilValidate.isEmpty(value)) {
|
||||
return value;
|
||||
@@ -2322,6 +2312,7 @@ public final class MacroFormRenderer implements FormStringRenderer {
|
||||
if (UtilValidate.isEmpty(lastViewName)) {
|
||||
lastViewName = "";
|
||||
}
|
||||
lastViewName = UtilHttp.getEncodedParameter(lastViewName);
|
||||
String tabindex = modelFormField.getTabindex();
|
||||
StringWriter sr = new StringWriter();
|
||||
sr.append("<@renderLookupField ");
|
||||
|
||||
Reference in New Issue
Block a user