martin-g commented on a change in pull request #442:
URL: https://github.com/apache/wicket/pull/442#discussion_r475578008



##########
File path: wicket-core/src/main/java/org/apache/wicket/Application.java
##########
@@ -33,6 +33,10 @@
 import org.apache.wicket.application.IComponentInitializationListener;
 import org.apache.wicket.application.IComponentInstantiationListener;
 import org.apache.wicket.application.OnComponentTagListenerCollection;
+import org.apache.wicket.coep.CoepRequestCycleListener;

Review comment:
       nit: I'd rename of Coep/Coop to their full name version - 
CrossOriginEmbedderPolicyRequestCycleListener.

##########
File path: 
wicket-core/src/main/java/org/apache/wicket/coep/CoepConfiguration.java
##########
@@ -0,0 +1,108 @@
+/*

Review comment:
       It'd have been better to put `coep` package under 
`org.apache.wicket.security` parent package but I see that the `csp` package is 
already in the root (`o.a.w`) so it would be inconsistent to do this now for 
`coep` and `coop` ... :-/

##########
File path: 
wicket-core/src/main/java/org/apache/wicket/coop/CoopRequestCycleListener.java
##########
@@ -0,0 +1,84 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.wicket.coop;
+
+import org.apache.wicket.request.IRequestHandler;
+import org.apache.wicket.request.cycle.IRequestCycleListener;
+import org.apache.wicket.request.cycle.RequestCycle;
+import org.apache.wicket.request.http.WebResponse;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.servlet.http.HttpServletRequest;
+
+/**
+ * Sets <a href="https://github.com/whatwg/html/pull/5334/files";>Cross-Origin 
Opener Policy</a>
+ * headers on the responses based on the policy specified by {@link 
CrossOriginOpenerPolicyConfiguration}. The header
+ * is not set for the paths that are exempted from COOP.
+ *
+ * COOP is a mitigation against cross-origin information leaks and is used to 
make websites
+ * cross-origin isolated. Setting the COOP header allows you to ensure that a 
top-level window is
+ * isolated from other documents by putting them in a different browsing 
context group, so they
+ * cannot directly interact with the top-level window. Using COEP and COOP 
together allows
+ * developers to safely use * powerful features such as 
<code>SharedArrayBuffer</code>,
+ * <code>performance.measureMemory()</code>, * and the JS Self-Profiling 
API.See
+ * {@link org.apache.wicket.coep.CoepRequestCycleListener} for instructions * 
on how to enable COOP.
+ * Read more about cross-origin isolation on
+ * <a href="https://web.dev/why-coop-coep/";>https://web.dev/why-coop-coep/</a>
+ *
+ *
+ * @author Santiago Diaz - sald...@google.com
+ * @author Ecenaz Jen Ozmen - ecen...@google.com
+ *
+ * @see CrossOriginOpenerPolicyConfiguration
+ * @see org.apache.wicket.settings.SecuritySettings
+ */
+public class CoopRequestCycleListener implements IRequestCycleListener
+{
+       private static final Logger log = 
LoggerFactory.getLogger(CoopRequestCycleListener.class);
+
+       static final String COOP_HEADER = "Cross-Origin-Opener-Policy";
+
+       private CrossOriginOpenerPolicyConfiguration coopConfig;
+
+       public CoopRequestCycleListener(CrossOriginOpenerPolicyConfiguration 
cooopConfig)
+       {
+               this.coopConfig = cooopConfig;
+       }
+
+       @Override
+       public void onRequestHandlerResolved(RequestCycle cycle, 
IRequestHandler handler)
+       {
+               HttpServletRequest request = 
(HttpServletRequest)cycle.getRequest().getContainerRequest();

Review comment:
       Better check that the container request is HttpServletRequest before 
casting it.
   Otherwise tests using MockWebRequest will have do manually disable these 
listeners.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


Reply via email to