Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1078,12 +1078,33 @@ public static void writeDataResourceText(GenericValue dataResource, String mimeT

if (url.getHost() != null) { // is absolute
checkUrlResourceAllowed(url);
int c;
try (InputStream in = url.openStream(); StringWriter sw = new StringWriter()) {
while ((c = in.read()) != -1) {
sw.write(c);
int connectTimeout = (int) UtilProperties.getPropertyNumber("security",
"content.data.url.resource.connect.timeout", 10000.0);
int readTimeout = (int) UtilProperties.getPropertyNumber("security",
"content.data.url.resource.read.timeout", 30000.0);
long maxResponseSize = (long) UtilProperties.getPropertyNumber("security",
"content.data.url.resource.max.response.size", (double) (10L * 1024 * 1024));
URLConnection con = url.openConnection();
con.setConnectTimeout(connectTimeout);
con.setReadTimeout(readTimeout);
// Disable automatic redirect-following to prevent SSRF bypass via redirect to private addresses
if (con instanceof HttpURLConnection) ((HttpURLConnection) con).setInstanceFollowRedirects(false);
con.connect();
// Reject redirects outright; we cannot safely re-validate an arbitrary Location header
if (con instanceof HttpURLConnection) {
HttpURLConnection httpCon = (HttpURLConnection) con;
int responseCode = httpCon.getResponseCode();
if (responseCode >= 300 && responseCode < 400) {
httpCon.disconnect();
throw new GeneralException("URL_RESOURCE request returned a redirect (" + responseCode
+ "); redirects are not followed for security reasons");
}
text = sw.toString();
}
try (InputStream limitedIn = BoundedInputStream.builder()
.setInputStream(con.getInputStream())
.setMaxCount(maxResponseSize)
.get()) {
text = IOUtils.toString(limitedIn, StandardCharsets.UTF_8);
}
} else {
String prefix = DataResourceWorker.buildRequestPrefix(delegator, locale, webSiteId, https);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@
import org.apache.ofbiz.entity.util.EntityUtilProperties;
import org.apache.ofbiz.entityext.EntityGroupUtil;
import org.apache.ofbiz.security.Security;
import org.apache.ofbiz.security.SecurityUtil;
import org.apache.ofbiz.service.DispatchContext;
import org.apache.ofbiz.service.GenericServiceException;
import org.apache.ofbiz.service.LocalDispatcher;
Expand Down Expand Up @@ -159,6 +160,11 @@ public static Map<String, Object> entityImport(DispatchContext dctx, Map<String,
return ServiceUtil.returnError(UtilProperties.getMessage(RESOURCE, "WebtoolsErrorReadingTemplateFile",
UtilMisc.toMap("filename", fmfilename, "errorString", "Template file not found."), locale));
}
try {
SecurityUtil.checkOfbizFileAllowList(fmFile);
} catch (GeneralException e) {
return ServiceUtil.returnError(e.getMessage());
}
try {
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
factory.setValidating(true);
Expand Down Expand Up @@ -515,6 +521,11 @@ public static Map<String, Object> entityExportAll(DispatchContext dctx, Map<Stri

if (UtilValidate.isNotEmpty(outpath)) {
File outdir = new File(outpath);
try {
SecurityUtil.checkOfbizFileAllowList(outdir);
} catch (GeneralException e) {
return ServiceUtil.returnError(e.getMessage());
}
if (!outdir.exists()) {
outdir.mkdir();
}
Expand Down
Loading