Skip to content

Commit 505c88c

Browse files
committed
Improved: Check parameters passed in URLs (OFBIZ-13295)
Thanks to Nicolas, improves previous commits that did not handle multipart element Also while at it, adds a space after "process" in deniedWebShellTokens of security.properties. I stumbled upon it after trying to upload a file created by a Canon camera. Anyway the deniedWebShellTokens comment suggest that when it's necessary. Conflicts handled by hand
1 parent e8ad44d commit 505c88c

File tree

3 files changed

+22
-19
lines changed

3 files changed

+22
-19
lines changed

‎framework/common/src/main/java/org/apache/ofbiz/common/UrlServletHelper.java‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@ private UrlServletHelper() { }
5050
public static void setRequestAttributes(ServletRequest request, Delegator delegator, ServletContext servletContext) {
5151
HttpServletRequest httpRequest = (HttpServletRequest) request;
5252
// check if multi tenant is enabled
53+
if (delegator == null) {
54+
delegator = WebAppUtil.getDelegator(servletContext);
55+
}
5356
boolean useMultitenant = EntityUtil.isMultiTenantEnabled();
5457
if (useMultitenant) {
5558
// get tenant delegator by domain name

‎framework/security/config/security.properties‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ csvformat=CSVFormat.DEFAULT
280280
deniedWebShellTokens=java.,beans,freemarker,<script,javascript,<body,body ,<form,<jsp:,<c:out,taglib,<prefix,<%@ page,<?php,exec(,alert(,\
281281
%eval,@eval,eval(,runtime,import,passthru,shell_exec,assert,str_rot13,system,decode,include,page ,\
282282
chmod,mkdir,fopen,fclose,new file,upload,getfilename,download,getoutputstring,readfile,iframe,object,embed,onload,build,\
283-
python,perl ,/perl,ruby ,/ruby,process,function,class,InputStream,to_server,wget ,static,assign,webappPath,\
283+
python,perl ,/perl,ruby ,/ruby,process ,function,class,InputStream,to_server,wget ,static,assign,webappPath,\
284284
ifconfig,route,crontab,netstat,uname ,hostname,iptables,whoami,"cmd",*cmd|,+cmd|,=cmd|,localhost,thread,require(,gzdeflate,\
285285
execute,println,calc,touch,curl,base64, tcp ,4444,base32, tr , xxd ,bash, od ,|od ,printf,echo
286286

‎framework/webapp/src/main/java/org/apache/ofbiz/webapp/control/ControlFilter.java‎

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@
2424
import java.net.URLDecoder;
2525
import java.util.ArrayList;
2626
import java.util.Arrays;
27+
import java.util.Collection;
2728
import java.util.Collections;
28-
import java.util.LinkedList;
2929
import java.util.List;
3030
import java.util.Map;
3131
import java.util.Set;
@@ -45,9 +45,11 @@
4545
import org.apache.logging.log4j.ThreadContext;
4646
import org.apache.ofbiz.base.util.Debug;
4747
import org.apache.ofbiz.base.util.StringUtil;
48+
import org.apache.ofbiz.base.util.UtilGenerics;
4849
import org.apache.ofbiz.base.util.UtilHttp;
4950
import org.apache.ofbiz.base.util.UtilProperties;
5051
import org.apache.ofbiz.base.util.UtilValidate;
52+
import org.apache.ofbiz.common.UrlServletHelper;
5153
import org.apache.ofbiz.entity.GenericValue;
5254
import org.apache.ofbiz.security.SecuredFreemarker;
5355
import org.apache.ofbiz.security.SecuredUpload;
@@ -169,35 +171,33 @@ public void doFilter(HttpServletRequest req, HttpServletResponse resp, FilterCha
169171

170172
// Prevents stream exploitation
171173
if (!isSolrTest()) {
174+
UrlServletHelper.setRequestAttributes(req, null, req.getServletContext());
172175
Map<String, Object> parameters = UtilHttp.getParameterMap(req);
173176
boolean reject = false;
174177
if (!parameters.isEmpty()) {
175178
for (String key : parameters.keySet()) {
176179
Object object = parameters.get(key);
177-
if (object.getClass().equals(String.class)) {
178-
String val = (String) object;
179-
if (val.contains("<")) {
180+
if (object.getClass().equals(String.class)
181+
|| object instanceof Collection) {
182+
try {
183+
List<String> toCheck = object.getClass().equals(String.class)
184+
? List.of((String) object)
185+
: UtilGenerics.checkCollection(object, String.class);
186+
reject = toCheck.stream()
187+
.anyMatch(val -> val.contains("<"));
188+
} catch (IllegalArgumentException e) {
189+
Debug.logWarning(e, MODULE);
180190
reject = true;
181191
}
182-
} else {
183-
@SuppressWarnings("unchecked")
184-
LinkedList<String> vals = (LinkedList<String>) parameters.get(key);
185-
for (String aVal : vals) {
186-
if (aVal.contains("<")) {
187-
reject = true;
188-
}
189-
}
190192
}
191-
}
192-
if (reject) {
193-
Debug.logError("For security reason this URL is not accepted", MODULE);
194-
throw new RuntimeException("For security reason this URL is not accepted");
193+
if (reject) {
194+
Debug.logError("For security reason this URL is not accepted", MODULE);
195+
throw new RuntimeException("For security reason this URL is not accepted");
196+
}
195197
}
196198
}
197199
}
198200

199-
200-
201201
// Check if we are told to redirect everything.
202202
if (redirectAll) {
203203
// little trick here so we don't loop on ourselves

0 commit comments

Comments
 (0)