Fixed: Prevent Host Header Injection (CVE-2019-12425)

(OFBIZ-11583)
This commit is contained in:
Jacques Le Roux
2020-04-04 19:32:02 +02:00
parent ba548f626e
commit e0f0d5271a
3 changed files with 26 additions and 0 deletions
@@ -604,6 +604,19 @@ public final class UtilMisc {
return LocaleHolder.availableLocaleList;
}
/** List of domains or IP addresses to be checked to prevent Host Header Injection,
* no spaces after commas,no wildcard, can be extended of course...
* @return List of domains or IP addresses to be checked to prevent Host Header Injection,
*/
public static List<String> getHostHeadersAllowed() {
String hostHeadersAllowedString = UtilProperties.getPropertyValue("security", "host-headers-allowed", "localhost");
List<String> hostHeadersAllowed = null;
if (UtilValidate.isNotEmpty(hostHeadersAllowedString)) {
hostHeadersAllowed = StringUtil.split(hostHeadersAllowedString, ",");
}
return Collections.unmodifiableList(hostHeadersAllowed);
}
/** @deprecated use Thread.sleep() */
@Deprecated
public static void staticWait(long timeout) throws InterruptedException {
@@ -152,6 +152,10 @@ security.internal.sso.enabled=false
# -- The secret key for the JWT token signature. Read Passwords and JWT (JSON Web Tokens) usage documentation to choose the way you want to store this key
security.token.key=security.token.key
# -- List of domains or IP addresses to be checked to prevent Host Header Injection,
# -- no spaces after commas,no wildcard, can be extended of course...
host-headers-allowed=localhost,127.0.0.1,demo-trunk.ofbiz.apache.org,demo-stable.ofbiz.apache.org,demo-old.ofbiz.apache.org
# -- By default the SameSite value in SameSiteFilter is strict. This allows to change it to lax if needed
SameSiteCookieAttribute=
@@ -86,6 +86,7 @@ public class RequestHandler {
private final URL controllerConfigURL;
private final boolean trackServerHit;
private final boolean trackVisit;
private final List hostHeadersAllowed;
private ControllerConfig ccfg;
public static RequestHandler getRequestHandler(ServletContext servletContext) {
@@ -111,6 +112,9 @@ public class RequestHandler {
this.trackServerHit = !"false".equalsIgnoreCase(context.getInitParameter("track-serverhit"));
this.trackVisit = !"false".equalsIgnoreCase(context.getInitParameter("track-visit"));
hostHeadersAllowed = UtilMisc.getHostHeadersAllowed();
}
public ConfigXMLReader.ControllerConfig getControllerConfig() {
@@ -209,6 +213,11 @@ public class RequestHandler {
public void doRequest(HttpServletRequest request, HttpServletResponse response, String chain,
GenericValue userLogin, Delegator delegator) throws RequestHandlerException, RequestHandlerExceptionAllowExternalRequests {
if (!hostHeadersAllowed.contains(request.getServerName())) {
Debug.logError("Domain " + request.getServerName() + " not accepted to prevent host header injection ", module);
throw new RequestHandlerException("Domain " + request.getServerName() + " not accepted to prevent host header injection ");
}
final boolean throwRequestHandlerExceptionOnMissingLocalRequest = EntityUtilProperties.propertyValueEqualsIgnoreCase(
"requestHandler", "throwRequestHandlerExceptionOnMissingLocalRequest", "Y", delegator);
long startTime = System.currentTimeMillis();