From 82ef7a58713607010bbc4c946068516306c9c03e Mon Sep 17 00:00:00 2001 From: Jacques Le Roux Date: Fri, 20 Mar 2020 17:50:17 +0100 Subject: [PATCH] Fixed: Ensure that the SameSite attribute is set to 'strict' for all cookies. (OFBIZ-11470) As reported by OWASP ZAP: A cookie has been set without the SameSite attribute, which means that the cookie can be sent as a result of a 'cross-site' request. The SameSite attribute is an effective counter measure to cross-site request forgery, cross-site script inclusion, and timing attacks. The solution was not obvious in OFBiz for 2 reasons: 1. There is no HttpServletResponse::setHeader. So we need to use a filter (SameSiteFilter) and even that is not enough because of 2: 2. To prevent session fixation we force Tomcat to generates a new jsessionId, ultimately put in cookie, in LoginWorker::login. So we need to add a call to SameSiteFilter::addSameSiteCookieAttribute in UtilHttp::setResponseBrowserDefaultSecurityHeaders. --- .../accounting/webapp/accounting/WEB-INF/web.xml | 9 +++++++++ applications/accounting/webapp/ap/WEB-INF/web.xml | 9 +++++++++ applications/accounting/webapp/ar/WEB-INF/web.xml | 9 +++++++++ applications/commonext/webapp/ofbizsetup/WEB-INF/web.xml | 9 +++++++++ applications/content/webapp/content/WEB-INF/web.xml | 9 +++++++++ applications/humanres/webapp/humanres/WEB-INF/web.xml | 9 +++++++++ .../manufacturing/webapp/manufacturing/WEB-INF/web.xml | 9 +++++++++ applications/marketing/webapp/sfa/WEB-INF/web.xml | 9 +++++++++ applications/order/webapp/ordermgr/WEB-INF/web.xml | 9 +++++++++ applications/product/webapp/catalog/WEB-INF/web.xml | 9 +++++++++ applications/product/webapp/facility/WEB-INF/web.xml | 9 +++++++++ applications/workeffort/webapp/ical/WEB-INF/web.xml | 9 +++++++++ .../workeffort/webapp/workeffort/WEB-INF/web.xml | 9 +++++++++ .../main/java/org/apache/ofbiz/base/util/UtilHttp.java | 3 +++ framework/resources/templates/web.xml | 6 ++++++ framework/webtools/webapp/webtools/WEB-INF/web.xml | 9 +++++++++ 16 files changed, 135 insertions(+) diff --git a/applications/accounting/webapp/accounting/WEB-INF/web.xml b/applications/accounting/webapp/accounting/WEB-INF/web.xml index b79233705e..261c9586a3 100644 --- a/applications/accounting/webapp/accounting/WEB-INF/web.xml +++ b/applications/accounting/webapp/accounting/WEB-INF/web.xml @@ -62,6 +62,11 @@ under the License. ContextFilter org.apache.ofbiz.webapp.control.ContextFilter + + SameSiteFilter + SameSiteFilter + org.apache.ofbiz.webapp.control.SameSiteFilter + ControlFilter /* @@ -70,6 +75,10 @@ under the License. ContextFilter /* + + SameSiteFilter + /* + org.apache.ofbiz.webapp.control.ControlEventListener org.apache.ofbiz.webapp.control.LoginEventListener diff --git a/applications/accounting/webapp/ap/WEB-INF/web.xml b/applications/accounting/webapp/ap/WEB-INF/web.xml index 0f12f57ea2..87b17f16f1 100644 --- a/applications/accounting/webapp/ap/WEB-INF/web.xml +++ b/applications/accounting/webapp/ap/WEB-INF/web.xml @@ -58,6 +58,11 @@ under the License. ContextFilter org.apache.ofbiz.webapp.control.ContextFilter + + SameSiteFilter + SameSiteFilter + org.apache.ofbiz.webapp.control.SameSiteFilter + ControlFilter /* @@ -66,6 +71,10 @@ under the License. ContextFilter /* + + SameSiteFilter + /* + org.apache.ofbiz.webapp.control.ControlEventListener org.apache.ofbiz.webapp.control.LoginEventListener diff --git a/applications/accounting/webapp/ar/WEB-INF/web.xml b/applications/accounting/webapp/ar/WEB-INF/web.xml index 23c89e65ba..1a43089bd4 100644 --- a/applications/accounting/webapp/ar/WEB-INF/web.xml +++ b/applications/accounting/webapp/ar/WEB-INF/web.xml @@ -62,6 +62,11 @@ under the License. ContextFilter org.apache.ofbiz.webapp.control.ContextFilter + + SameSiteFilter + SameSiteFilter + org.apache.ofbiz.webapp.control.SameSiteFilter + ControlFilter /* @@ -70,6 +75,10 @@ under the License. ContextFilter /* + + SameSiteFilter + /* + org.apache.ofbiz.webapp.control.ControlEventListener org.apache.ofbiz.webapp.control.LoginEventListener diff --git a/applications/commonext/webapp/ofbizsetup/WEB-INF/web.xml b/applications/commonext/webapp/ofbizsetup/WEB-INF/web.xml index 9691ceab53..75289376fc 100644 --- a/applications/commonext/webapp/ofbizsetup/WEB-INF/web.xml +++ b/applications/commonext/webapp/ofbizsetup/WEB-INF/web.xml @@ -57,6 +57,11 @@ ContextFilter org.apache.ofbiz.webapp.control.ContextFilter + + SameSiteFilter + SameSiteFilter + org.apache.ofbiz.webapp.control.SameSiteFilter + ControlFilter /* @@ -65,6 +70,10 @@ ContextFilter /* + + SameSiteFilter + /* + org.apache.ofbiz.webapp.control.ControlEventListener org.apache.ofbiz.webapp.control.LoginEventListener diff --git a/applications/content/webapp/content/WEB-INF/web.xml b/applications/content/webapp/content/WEB-INF/web.xml index d27167403e..fb2b0d0035 100644 --- a/applications/content/webapp/content/WEB-INF/web.xml +++ b/applications/content/webapp/content/WEB-INF/web.xml @@ -62,6 +62,11 @@ under the License. ContextFilter org.apache.ofbiz.webapp.control.ContextFilter + + SameSiteFilter + SameSiteFilter + org.apache.ofbiz.webapp.control.SameSiteFilter + ControlFilter /* @@ -70,6 +75,10 @@ under the License. ContextFilter /* + + SameSiteFilter + /* + org.apache.ofbiz.webapp.control.ControlEventListener org.apache.ofbiz.webapp.control.LoginEventListener diff --git a/applications/humanres/webapp/humanres/WEB-INF/web.xml b/applications/humanres/webapp/humanres/WEB-INF/web.xml index d4d9e7462d..530b64bb0d 100644 --- a/applications/humanres/webapp/humanres/WEB-INF/web.xml +++ b/applications/humanres/webapp/humanres/WEB-INF/web.xml @@ -57,6 +57,11 @@ under the License. ContextFilter org.apache.ofbiz.webapp.control.ContextFilter + + SameSiteFilter + SameSiteFilter + org.apache.ofbiz.webapp.control.SameSiteFilter + ControlFilter /* @@ -65,6 +70,10 @@ under the License. ContextFilter /* + + SameSiteFilter + /* + org.apache.ofbiz.webapp.control.ControlEventListener org.apache.ofbiz.webapp.control.LoginEventListener diff --git a/applications/manufacturing/webapp/manufacturing/WEB-INF/web.xml b/applications/manufacturing/webapp/manufacturing/WEB-INF/web.xml index 25e6f158a2..67ea6e9cab 100644 --- a/applications/manufacturing/webapp/manufacturing/WEB-INF/web.xml +++ b/applications/manufacturing/webapp/manufacturing/WEB-INF/web.xml @@ -62,6 +62,11 @@ under the License. ContextFilter org.apache.ofbiz.webapp.control.ContextFilter + + SameSiteFilter + SameSiteFilter + org.apache.ofbiz.webapp.control.SameSiteFilter + ControlFilter /* @@ -70,6 +75,10 @@ under the License. ContextFilter /* + + SameSiteFilter + /* + org.apache.ofbiz.webapp.control.ControlEventListener org.apache.ofbiz.webapp.control.LoginEventListener diff --git a/applications/marketing/webapp/sfa/WEB-INF/web.xml b/applications/marketing/webapp/sfa/WEB-INF/web.xml index 638e06a3b0..34098bfa9a 100644 --- a/applications/marketing/webapp/sfa/WEB-INF/web.xml +++ b/applications/marketing/webapp/sfa/WEB-INF/web.xml @@ -57,6 +57,11 @@ under the License. ContextFilter org.apache.ofbiz.webapp.control.ContextFilter + + SameSiteFilter + SameSiteFilter + org.apache.ofbiz.webapp.control.SameSiteFilter + ControlFilter /* @@ -65,6 +70,10 @@ under the License. ContextFilter /* + + SameSiteFilter + /* + org.apache.ofbiz.webapp.control.ControlEventListener org.apache.ofbiz.webapp.control.LoginEventListener diff --git a/applications/order/webapp/ordermgr/WEB-INF/web.xml b/applications/order/webapp/ordermgr/WEB-INF/web.xml index 41265cc8ef..cf3294bd69 100644 --- a/applications/order/webapp/ordermgr/WEB-INF/web.xml +++ b/applications/order/webapp/ordermgr/WEB-INF/web.xml @@ -57,6 +57,11 @@ under the License. ContextFilter org.apache.ofbiz.webapp.control.ContextFilter + + SameSiteFilter + SameSiteFilter + org.apache.ofbiz.webapp.control.SameSiteFilter + ControlFilter /* @@ -65,6 +70,10 @@ under the License. ContextFilter /* + + SameSiteFilter + /* + org.apache.ofbiz.webapp.control.ControlEventListener org.apache.ofbiz.webapp.control.LoginEventListener diff --git a/applications/product/webapp/catalog/WEB-INF/web.xml b/applications/product/webapp/catalog/WEB-INF/web.xml index a79e79898a..76e24ba0b8 100644 --- a/applications/product/webapp/catalog/WEB-INF/web.xml +++ b/applications/product/webapp/catalog/WEB-INF/web.xml @@ -57,6 +57,11 @@ under the License. ContextFilter org.apache.ofbiz.webapp.control.ContextFilter + + SameSiteFilter + SameSiteFilter + org.apache.ofbiz.webapp.control.SameSiteFilter + ControlFilter /* @@ -65,6 +70,10 @@ under the License. ContextFilter /* + + SameSiteFilter + /* + org.apache.ofbiz.webapp.control.ControlEventListener org.apache.ofbiz.webapp.control.LoginEventListener diff --git a/applications/product/webapp/facility/WEB-INF/web.xml b/applications/product/webapp/facility/WEB-INF/web.xml index 0a3464f395..6d3decc685 100644 --- a/applications/product/webapp/facility/WEB-INF/web.xml +++ b/applications/product/webapp/facility/WEB-INF/web.xml @@ -62,6 +62,11 @@ under the License. ContextFilter org.apache.ofbiz.webapp.control.ContextFilter + + SameSiteFilter + SameSiteFilter + org.apache.ofbiz.webapp.control.SameSiteFilter + ControlFilter /* @@ -70,6 +75,10 @@ under the License. ContextFilter /* + + SameSiteFilter + /* + org.apache.ofbiz.webapp.control.ControlEventListener org.apache.ofbiz.webapp.control.LoginEventListener diff --git a/applications/workeffort/webapp/ical/WEB-INF/web.xml b/applications/workeffort/webapp/ical/WEB-INF/web.xml index b890ca7b6f..52745d7ca0 100644 --- a/applications/workeffort/webapp/ical/WEB-INF/web.xml +++ b/applications/workeffort/webapp/ical/WEB-INF/web.xml @@ -56,6 +56,11 @@ under the License. ContextFilter org.apache.ofbiz.webapp.control.ContextFilter + + SameSiteFilter + SameSiteFilter + org.apache.ofbiz.webapp.control.SameSiteFilter + ControlFilter /* @@ -64,6 +69,10 @@ under the License. ContextFilter /* + + SameSiteFilter + /* + org.apache.ofbiz.webapp.control.ControlEventListener diff --git a/applications/workeffort/webapp/workeffort/WEB-INF/web.xml b/applications/workeffort/webapp/workeffort/WEB-INF/web.xml index c8aeb25ce0..3fc96daf28 100644 --- a/applications/workeffort/webapp/workeffort/WEB-INF/web.xml +++ b/applications/workeffort/webapp/workeffort/WEB-INF/web.xml @@ -59,6 +59,11 @@ under the License. ContextFilter org.apache.ofbiz.webapp.control.ContextFilter + + SameSiteFilter + SameSiteFilter + org.apache.ofbiz.webapp.control.SameSiteFilter + ControlFilter /* @@ -67,6 +72,10 @@ under the License. ContextFilter /* + + SameSiteFilter + /* + org.apache.ofbiz.webapp.control.ControlEventListener diff --git a/framework/base/src/main/java/org/apache/ofbiz/base/util/UtilHttp.java b/framework/base/src/main/java/org/apache/ofbiz/base/util/UtilHttp.java index ef373b46e9..fec25ff856 100644 --- a/framework/base/src/main/java/org/apache/ofbiz/base/util/UtilHttp.java +++ b/framework/base/src/main/java/org/apache/ofbiz/base/util/UtilHttp.java @@ -66,6 +66,7 @@ import org.apache.http.ssl.SSLContexts; import org.apache.ofbiz.entity.Delegator; import org.apache.ofbiz.entity.util.EntityUtilProperties; import org.apache.ofbiz.webapp.control.ConfigXMLReader; +import org.apache.ofbiz.webapp.control.SameSiteFilter; import org.apache.ofbiz.webapp.event.FileUploadProgressListener; import org.apache.ofbiz.widget.renderer.VisualTheme; import org.apache.oro.text.regex.MalformedPatternException; @@ -1152,6 +1153,8 @@ public final class UtilHttp { resp.setHeader("Content-Security-Policy-Report-Only", "default-src 'self'"); + SameSiteFilter.addSameSiteCookieAttribute(resp); + // TODO in custom project. Public-Key-Pins-Report-Only is interesting but can't be used OOTB because of demos (the letsencrypt certificate is renewed every 3 months) } diff --git a/framework/resources/templates/web.xml b/framework/resources/templates/web.xml index 2ca1b356d1..5db4f21e9b 100644 --- a/framework/resources/templates/web.xml +++ b/framework/resources/templates/web.xml @@ -61,8 +61,14 @@ under the License. ContextFilter org.apache.ofbiz.webapp.control.ContextFilter + + SameSiteFilter + SameSiteFilter + org.apache.ofbiz.webapp.control.SameSiteFilter + ControlFilter/* ContextFilter/* + SameSiteFilter/* org.apache.ofbiz.webapp.control.ControlEventListener org.apache.ofbiz.webapp.control.LoginEventListener diff --git a/framework/webtools/webapp/webtools/WEB-INF/web.xml b/framework/webtools/webapp/webtools/WEB-INF/web.xml index 635897b320..c46f4bbe69 100644 --- a/framework/webtools/webapp/webtools/WEB-INF/web.xml +++ b/framework/webtools/webapp/webtools/WEB-INF/web.xml @@ -63,6 +63,11 @@ under the License. ContextFilter org.apache.ofbiz.webapp.control.ContextFilter + + SameSiteFilter + SameSiteFilter + org.apache.ofbiz.webapp.control.SameSiteFilter + ControlFilter /* @@ -71,6 +76,10 @@ under the License. ContextFilter /* + + SameSiteFilter + /* + org.apache.ofbiz.webapp.control.ControlEventListener