You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@wicket.apache.org by sv...@apache.org on 2020/03/11 21:19:16 UTC
[wicket] branch master updated (030cd2e -> 88e8d36)
This is an automated email from the ASF dual-hosted git repository.
svenmeier pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/wicket.git.
from 030cd2e WICKET-6747: fix typename after rename
new 227d421 remove obsolete ajax setting
new 88e8d36 WICKET-6747 csp settings aligned
The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
Summary of changes:
.../apache/wicket/cdi/ConversationPropagator.java | 31 +----
.../org/apache/wicket/cdi/CdiWicketTester.java | 3 +-
.../main/java/org/apache/wicket/Application.java | 2 +-
.../core/request/handler/IPageRequestHandler.java | 27 ++++
.../wicket/csp/CSPDirectiveSandboxValue.java | 2 +-
.../apache/wicket/csp/CSPDirectiveSrcValue.java | 6 +-
.../apache/wicket/csp/CSPHeaderConfiguration.java | 6 +-
.../csp/CSPNonceHeaderResponseDecorator.java | 10 +-
.../java/org/apache/wicket/csp/CSPRenderable.java | 4 +-
.../apache/wicket/csp/CSPRequestCycleListener.java | 91 +++++++++++++
.../wicket/csp/ContentSecurityPolicySettings.java | 129 ++++++------------
.../java/org/apache/wicket/csp/FixedCSPValue.java | 2 +-
.../org/apache/wicket/csp/RelativeURICSPValue.java | 2 +-
.../wicket/csp/ReportCSPViolationMapper.java | 8 +-
.../org/apache/wicket/mock/MockApplication.java | 2 +-
.../wicket/protocol/http/WebApplication.java | 58 ++++----
.../csp/CSPSettingRequestCycleListenerTest.java | 148 +++++++++------------
.../head/filter/FilteringHeaderResponseTest.java | 4 +-
.../wicket/examples/WicketExampleApplication.java | 2 +-
.../MyAuthenticatedWebApplication.java | 2 +-
.../wicket/examples/images/ImagesApplication.java | 2 +-
.../wicket/examples/media/VideosApplication.java | 2 +-
.../examples/websocket/JSR356Application.java | 2 +-
23 files changed, 278 insertions(+), 267 deletions(-)
create mode 100644 wicket-core/src/main/java/org/apache/wicket/csp/CSPRequestCycleListener.java
[wicket] 02/02: WICKET-6747 csp settings aligned
Posted by sv...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
svenmeier pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/wicket.git
commit 88e8d36ddf2255c8728298d586ffe344d64819fe
Author: Sven Meier <sv...@apache.org>
AuthorDate: Tue Mar 10 17:34:53 2020 +0100
WICKET-6747 csp settings aligned
---
.../apache/wicket/cdi/ConversationPropagator.java | 31 +----
.../org/apache/wicket/cdi/CdiWicketTester.java | 3 +-
.../main/java/org/apache/wicket/Application.java | 2 +-
.../core/request/handler/IPageRequestHandler.java | 27 ++++
.../wicket/csp/CSPDirectiveSandboxValue.java | 2 +-
.../apache/wicket/csp/CSPDirectiveSrcValue.java | 6 +-
.../apache/wicket/csp/CSPHeaderConfiguration.java | 6 +-
.../csp/CSPNonceHeaderResponseDecorator.java | 10 +-
.../java/org/apache/wicket/csp/CSPRenderable.java | 4 +-
.../apache/wicket/csp/CSPRequestCycleListener.java | 91 +++++++++++++
.../wicket/csp/ContentSecurityPolicySettings.java | 129 ++++++------------
.../java/org/apache/wicket/csp/FixedCSPValue.java | 2 +-
.../org/apache/wicket/csp/RelativeURICSPValue.java | 2 +-
.../wicket/csp/ReportCSPViolationMapper.java | 8 +-
.../org/apache/wicket/mock/MockApplication.java | 2 +-
.../wicket/protocol/http/WebApplication.java | 41 +++---
.../csp/CSPSettingRequestCycleListenerTest.java | 148 +++++++++------------
.../head/filter/FilteringHeaderResponseTest.java | 4 +-
.../wicket/examples/WicketExampleApplication.java | 2 +-
.../MyAuthenticatedWebApplication.java | 2 +-
.../wicket/examples/images/ImagesApplication.java | 2 +-
.../wicket/examples/media/VideosApplication.java | 2 +-
.../examples/websocket/JSR356Application.java | 2 +-
23 files changed, 277 insertions(+), 251 deletions(-)
diff --git a/wicket-cdi/src/main/java/org/apache/wicket/cdi/ConversationPropagator.java b/wicket-cdi/src/main/java/org/apache/wicket/cdi/ConversationPropagator.java
index 160d459..c6fbd33 100644
--- a/wicket-cdi/src/main/java/org/apache/wicket/cdi/ConversationPropagator.java
+++ b/wicket-cdi/src/main/java/org/apache/wicket/cdi/ConversationPropagator.java
@@ -139,7 +139,7 @@ public class ConversationPropagator implements IRequestCycleListener
return;
}
- if (propagation.propagatesVia(handler, getPage(handler)))
+ if (propagation.propagatesVia(handler, IPageRequestHandler.getPage(handler)))
{
logger.debug(
"Propagating non-transient conversation {} via page parameters of handler {}",
@@ -173,7 +173,7 @@ public class ConversationPropagator implements IRequestCycleListener
return;
}
- if (propagation.propagatesVia(handler, getPage(handler)))
+ if (propagation.propagatesVia(handler, IPageRequestHandler.getPage(handler)))
{
logger.debug("Propagating non-transient conversation {} via url", conversation.getId());
url.setQueryParameter(CID, conversation.getId());
@@ -231,7 +231,7 @@ public class ConversationPropagator implements IRequestCycleListener
public static void markPageWithConversationId(IRequestHandler handler, String cid)
{
- Page page = getPage(handler);
+ Page page = IPageRequestHandler.getPage(handler);
if (page != null)
{
page.setMetaData(CONVERSATION_ID_KEY, cid);
@@ -249,31 +249,6 @@ public class ConversationPropagator implements IRequestCycleListener
}
/**
- * Resolves a page instance from the request handler iff the page instance
- * is already created
- *
- * @param handler
- * @return page or {@code null} if none
- */
- public static Page getPage(IRequestHandler handler)
- {
- while (handler instanceof IRequestHandlerDelegate)
- {
- handler = ((IRequestHandlerDelegate)handler).getDelegateHandler();
- }
-
- if (handler instanceof IPageRequestHandler)
- {
- IPageRequestHandler pageHandler = (IPageRequestHandler)handler;
- if (pageHandler.isPageInstanceCreated())
- {
- return (Page)pageHandler.getPage();
- }
- }
- return null;
- }
-
- /**
* Resolves page parameters from a request handler
*
* @param handler
diff --git a/wicket-cdi/src/test/java/org/apache/wicket/cdi/CdiWicketTester.java b/wicket-cdi/src/test/java/org/apache/wicket/cdi/CdiWicketTester.java
index c887cd5..0ce51f3 100644
--- a/wicket-cdi/src/test/java/org/apache/wicket/cdi/CdiWicketTester.java
+++ b/wicket-cdi/src/test/java/org/apache/wicket/cdi/CdiWicketTester.java
@@ -26,6 +26,7 @@ import javax.annotation.PreDestroy;
import javax.inject.Inject;
import org.apache.wicket.Page;
+import org.apache.wicket.core.request.handler.IPageRequestHandler;
import org.apache.wicket.protocol.http.WebApplication;
import org.apache.wicket.protocol.http.mock.MockHttpServletRequest;
import org.apache.wicket.request.IRequestHandler;
@@ -79,7 +80,7 @@ public class CdiWicketTester extends WicketTester
{
Url ret = super.urlFor(handler);
final CdiConfiguration configuration = CdiConfiguration.get(getApplication());
- Page page = ConversationPropagator.getPage(handler);
+ Page page = IPageRequestHandler.getPage(handler);
if (configuration.getPropagation().propagatesVia(handler, page))
{
if (page != null)
diff --git a/wicket-core/src/main/java/org/apache/wicket/Application.java b/wicket-core/src/main/java/org/apache/wicket/Application.java
index af2632d..78fd57f 100644
--- a/wicket-core/src/main/java/org/apache/wicket/Application.java
+++ b/wicket-core/src/main/java/org/apache/wicket/Application.java
@@ -1303,7 +1303,7 @@ public abstract class Application implements UnboundListener, IEventSink, IMetad
/**
*
*/
- private void checkSettingsAvailable()
+ protected void checkSettingsAvailable()
{
if (!settingsAccessible)
{
diff --git a/wicket-core/src/main/java/org/apache/wicket/core/request/handler/IPageRequestHandler.java b/wicket-core/src/main/java/org/apache/wicket/core/request/handler/IPageRequestHandler.java
index cc10287..626c314 100644
--- a/wicket-core/src/main/java/org/apache/wicket/core/request/handler/IPageRequestHandler.java
+++ b/wicket-core/src/main/java/org/apache/wicket/core/request/handler/IPageRequestHandler.java
@@ -16,6 +16,9 @@
*/
package org.apache.wicket.core.request.handler;
+import org.apache.wicket.Page;
+import org.apache.wicket.request.IRequestHandler;
+import org.apache.wicket.request.IRequestHandlerDelegate;
import org.apache.wicket.request.component.IRequestablePage;
/**
@@ -54,4 +57,28 @@ public interface IPageRequestHandler extends IPageClassRequestHandler
* @see IRequestablePage#getRenderCount()
*/
Integer getRenderCount();
+
+ /**
+ * Resolves a page instance from the request handler iff the page instance is already created
+ *
+ * @param handler The request handler
+ * @return page or {@code null} if none
+ */
+ public static Page getPage(IRequestHandler handler)
+ {
+ while (handler instanceof IRequestHandlerDelegate)
+ {
+ handler = ((IRequestHandlerDelegate) handler).getDelegateHandler();
+ }
+
+ if (handler instanceof IPageRequestHandler)
+ {
+ IPageRequestHandler pageHandler = (IPageRequestHandler) handler;
+ if (pageHandler.isPageInstanceCreated())
+ {
+ return (Page) pageHandler.getPage();
+ }
+ }
+ return null;
+ }
}
diff --git a/wicket-core/src/main/java/org/apache/wicket/csp/CSPDirectiveSandboxValue.java b/wicket-core/src/main/java/org/apache/wicket/csp/CSPDirectiveSandboxValue.java
index b821040..f8c48e9 100644
--- a/wicket-core/src/main/java/org/apache/wicket/csp/CSPDirectiveSandboxValue.java
+++ b/wicket-core/src/main/java/org/apache/wicket/csp/CSPDirectiveSandboxValue.java
@@ -43,7 +43,7 @@ public enum CSPDirectiveSandboxValue implements CSPRenderable
}
@Override
- public String render(ContentSecurityPolicySettings listener, RequestCycle cycle,
+ public String render(ContentSecurityPolicySettings settings, RequestCycle cycle,
IRequestHandler currentHandler)
{
return value;
diff --git a/wicket-core/src/main/java/org/apache/wicket/csp/CSPDirectiveSrcValue.java b/wicket-core/src/main/java/org/apache/wicket/csp/CSPDirectiveSrcValue.java
index b186d8d..f6be6d3 100644
--- a/wicket-core/src/main/java/org/apache/wicket/csp/CSPDirectiveSrcValue.java
+++ b/wicket-core/src/main/java/org/apache/wicket/csp/CSPDirectiveSrcValue.java
@@ -33,10 +33,10 @@ public enum CSPDirectiveSrcValue implements CSPRenderable
NONCE("'nonce-%1$s'")
{
@Override
- public String render(ContentSecurityPolicySettings listener, RequestCycle cycle,
+ public String render(ContentSecurityPolicySettings settings, RequestCycle cycle,
IRequestHandler currentHandler)
{
- return String.format(getValue(), listener.getNonce(cycle, currentHandler));
+ return String.format(getValue(), settings.getNonce(cycle, currentHandler));
}
};
@@ -48,7 +48,7 @@ public enum CSPDirectiveSrcValue implements CSPRenderable
}
@Override
- public String render(ContentSecurityPolicySettings listener, RequestCycle cycle,
+ public String render(ContentSecurityPolicySettings settings, RequestCycle cycle,
IRequestHandler currentHandler)
{
return value;
diff --git a/wicket-core/src/main/java/org/apache/wicket/csp/CSPHeaderConfiguration.java b/wicket-core/src/main/java/org/apache/wicket/csp/CSPHeaderConfiguration.java
index cef5091..7616344 100644
--- a/wicket-core/src/main/java/org/apache/wicket/csp/CSPHeaderConfiguration.java
+++ b/wicket-core/src/main/java/org/apache/wicket/csp/CSPHeaderConfiguration.java
@@ -315,7 +315,7 @@ public class CSPHeaderConfiguration
* Renders this {@code CSPHeaderConfiguration} into an HTTP header. The returned String will be
* in the form {@code "key1 value1a value1b; key2 value2a; key3 value3a value3b value3c"}.
*
- * @param listener
+ * @param settings
* The {@link ContentSecurityPolicySettings} that renders the header.
* @param cycle
* The current {@link RequestCycle}.
@@ -323,7 +323,7 @@ public class CSPHeaderConfiguration
* The handler that is currently being evaluated or executed.
* @return the rendered header.
*/
- public String renderHeaderValue(ContentSecurityPolicySettings listener, RequestCycle cycle,
+ public String renderHeaderValue(ContentSecurityPolicySettings settings, RequestCycle cycle,
IRequestHandler currentHandler)
{
return directives.entrySet()
@@ -331,7 +331,7 @@ public class CSPHeaderConfiguration
.map(e -> e.getKey().getValue() + " "
+ e.getValue()
.stream()
- .map(r -> r.render(listener, cycle, currentHandler))
+ .map(r -> r.render(settings, cycle, currentHandler))
.collect(Collectors.joining(" ")))
.collect(Collectors.joining("; "));
}
diff --git a/wicket-core/src/main/java/org/apache/wicket/csp/CSPNonceHeaderResponseDecorator.java b/wicket-core/src/main/java/org/apache/wicket/csp/CSPNonceHeaderResponseDecorator.java
index 46f7847..faa9d30 100644
--- a/wicket-core/src/main/java/org/apache/wicket/csp/CSPNonceHeaderResponseDecorator.java
+++ b/wicket-core/src/main/java/org/apache/wicket/csp/CSPNonceHeaderResponseDecorator.java
@@ -29,19 +29,19 @@ import org.apache.wicket.request.cycle.RequestCycle;
*/
public class CSPNonceHeaderResponseDecorator extends DecoratingHeaderResponse
{
- private final ContentSecurityPolicySettings listener;
+ private final ContentSecurityPolicySettings settings;
- public CSPNonceHeaderResponseDecorator(IHeaderResponse real, ContentSecurityPolicySettings listener)
+ public CSPNonceHeaderResponseDecorator(IHeaderResponse real, ContentSecurityPolicySettings settings)
{
super(real);
- this.listener = listener;
+ this.settings = settings;
}
@Override
public void render(HeaderItem item)
{
- if (listener.isNonceEnabled())
+ if (settings.isNonceEnabled())
{
HeaderItem checkitem = item;
while (checkitem instanceof IWrappedHeaderItem)
@@ -51,7 +51,7 @@ public class CSPNonceHeaderResponseDecorator extends DecoratingHeaderResponse
if (checkitem instanceof AbstractCspHeaderItem)
{
- ((AbstractCspHeaderItem) checkitem).setNonce(listener.getNonce(RequestCycle.get(),
+ ((AbstractCspHeaderItem) checkitem).setNonce(settings.getNonce(RequestCycle.get(),
RequestCycle.get().getActiveRequestHandler()));
}
}
diff --git a/wicket-core/src/main/java/org/apache/wicket/csp/CSPRenderable.java b/wicket-core/src/main/java/org/apache/wicket/csp/CSPRenderable.java
index 4004bfb..8610cc0 100644
--- a/wicket-core/src/main/java/org/apache/wicket/csp/CSPRenderable.java
+++ b/wicket-core/src/main/java/org/apache/wicket/csp/CSPRenderable.java
@@ -33,7 +33,7 @@ public interface CSPRenderable
/**
* Renders the value that should be put in the CSP header.
*
- * @param listener
+ * @param settings
* The {@link ContentSecurityPolicySettings} that renders this value.
* @param cycle
* The current {@link RequestCycle}.
@@ -41,7 +41,7 @@ public interface CSPRenderable
* The handler that is currently being evaluated or executed.
* @return The rendered value.
*/
- String render(ContentSecurityPolicySettings listener, RequestCycle cycle,
+ String render(ContentSecurityPolicySettings settings, RequestCycle cycle,
IRequestHandler currentHandler);
/**
diff --git a/wicket-core/src/main/java/org/apache/wicket/csp/CSPRequestCycleListener.java b/wicket-core/src/main/java/org/apache/wicket/csp/CSPRequestCycleListener.java
new file mode 100644
index 0000000..f0acc52
--- /dev/null
+++ b/wicket-core/src/main/java/org/apache/wicket/csp/CSPRequestCycleListener.java
@@ -0,0 +1,91 @@
+/*
+ * 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.csp;
+
+import org.apache.wicket.core.request.handler.BufferedResponseRequestHandler;
+import org.apache.wicket.core.request.handler.IPageClassRequestHandler;
+import org.apache.wicket.request.IRequestHandler;
+import org.apache.wicket.request.IRequestHandlerDelegate;
+import org.apache.wicket.request.cycle.IRequestCycleListener;
+import org.apache.wicket.request.cycle.RequestCycle;
+import org.apache.wicket.request.http.WebResponse;
+
+/**
+ * An {@link IRequestCycleListener} that adds {@code Content-Security-Policy} and/or
+ * {@code Content-Security-Policy-Report-Only} headers based on the supplied configuration.
+ *
+ * @author Sven Haster
+ * @author Emond Papegaaij
+ */
+public class CSPRequestCycleListener implements IRequestCycleListener
+{
+ private ContentSecurityPolicySettings settings;
+
+ public CSPRequestCycleListener(ContentSecurityPolicySettings settings)
+ {
+ this.settings = settings;
+ }
+
+ @Override
+ public void onRequestHandlerResolved(RequestCycle cycle, IRequestHandler handler)
+ {
+ if (!mustProtect(handler) || !(cycle.getResponse() instanceof WebResponse))
+ {
+ return;
+ }
+
+ WebResponse webResponse = (WebResponse)cycle.getResponse();
+ if (!webResponse.isHeaderSupported())
+ {
+ return;
+ }
+
+ settings.getConfiguration().entrySet().stream().filter(entry -> entry.getValue().isSet())
+ .forEach(entry -> {
+ CSPHeaderMode mode = entry.getKey();
+ CSPHeaderConfiguration config = entry.getValue();
+ String headerValue = config.renderHeaderValue(settings, cycle, handler);
+ webResponse.setHeader(mode.getHeader(), headerValue);
+ if (config.isAddLegacyHeaders())
+ {
+ webResponse.setHeader(mode.getLegacyHeader(), headerValue);
+ }
+ });
+ }
+
+ /**
+ * Must the given handler be protected.
+ *
+ * @param handler
+ * handler
+ * @return <code>true</code> if must protected
+ * @see ContentSecurityPolicySettings#mustProtectPageRequest(IPageClassRequestHandler)
+ */
+ protected boolean mustProtect(IRequestHandler handler)
+ {
+ if (handler instanceof IRequestHandlerDelegate)
+ {
+ return mustProtect(((IRequestHandlerDelegate)handler).getDelegateHandler());
+ }
+ if (handler instanceof IPageClassRequestHandler)
+ {
+ return settings.mustProtectPageRequest((IPageClassRequestHandler)handler);
+ }
+ return !(handler instanceof BufferedResponseRequestHandler);
+ }
+
+}
diff --git a/wicket-core/src/main/java/org/apache/wicket/csp/ContentSecurityPolicySettings.java b/wicket-core/src/main/java/org/apache/wicket/csp/ContentSecurityPolicySettings.java
index 2c852ad..df58497 100644
--- a/wicket-core/src/main/java/org/apache/wicket/csp/ContentSecurityPolicySettings.java
+++ b/wicket-core/src/main/java/org/apache/wicket/csp/ContentSecurityPolicySettings.java
@@ -24,32 +24,25 @@ import java.util.function.Predicate;
import org.apache.wicket.Application;
import org.apache.wicket.MetaDataKey;
import org.apache.wicket.Page;
-import org.apache.wicket.core.request.handler.BufferedResponseRequestHandler;
import org.apache.wicket.core.request.handler.IPageClassRequestHandler;
import org.apache.wicket.core.request.handler.IPageRequestHandler;
+import org.apache.wicket.protocol.http.WebApplication;
import org.apache.wicket.request.IRequestHandler;
-import org.apache.wicket.request.IRequestHandlerDelegate;
-import org.apache.wicket.request.cycle.IRequestCycleListener;
import org.apache.wicket.request.cycle.RequestCycle;
-import org.apache.wicket.request.http.WebResponse;
-import org.apache.wicket.settings.SecuritySettings;
import org.apache.wicket.util.lang.Args;
/**
- * An {@link IRequestCycleListener} that adds {@code Content-Security-Policy} and/or
- * {@code Content-Security-Policy-Report-Only} headers based on the supplied configuration.
- *
* Build the CSP configuration like this:
*
* <pre>
* {@code
- * myApplication.getCspSettings().blocking().clear()
+ * myApplication.getContentSecuritySettings().blocking().clear()
* .add(CSPDirective.DEFAULT_SRC, CSPDirectiveSrcValue.NONE)
* .add(CSPDirective.SCRIPT_SRC, CSPDirectiveSrcValue.SELF)
* .add(CSPDirective.IMG_SRC, CSPDirectiveSrcValue.SELF)
* .add(CSPDirective.FONT_SRC, CSPDirectiveSrcValue.SELF));
*
- * myApplication.getCspSettings().reporting().strict();
+ * myApplication.getContentSecuritySettings().reporting().strict();
* }
* </pre>
*
@@ -62,7 +55,7 @@ import org.apache.wicket.util.lang.Args;
* @author Sven Haster
* @author Emond Papegaaij
*/
-public class ContentSecurityPolicySettings implements IRequestCycleListener
+public class ContentSecurityPolicySettings
{
// The number of bytes to use for a nonce, 12 will result in a 16 char nonce.
private static final int NONCE_LENGTH = 12;
@@ -73,9 +66,10 @@ public class ContentSecurityPolicySettings implements IRequestCycleListener
};
private final Application application;
-
- private final Map<CSPHeaderMode, CSPHeaderConfiguration> configs = new EnumMap<>(CSPHeaderMode.class);
-
+
+ private final Map<CSPHeaderMode, CSPHeaderConfiguration> configs = new EnumMap<>(
+ CSPHeaderMode.class);
+
private Predicate<IPageClassRequestHandler> protectedPageFilter = handler -> true;
public ContentSecurityPolicySettings(Application application)
@@ -90,9 +84,10 @@ public class ContentSecurityPolicySettings implements IRequestCycleListener
public CSPHeaderConfiguration reporting()
{
- return configs.computeIfAbsent(CSPHeaderMode.REPORT_ONLY, x -> new CSPHeaderConfiguration());
+ return configs.computeIfAbsent(CSPHeaderMode.REPORT_ONLY,
+ x -> new CSPHeaderConfiguration());
}
-
+
/**
* Sets the predicate that determines which requests must be protected by the CSP. When the
* predicate evaluates to false, the request for the page will not be protected.
@@ -101,60 +96,27 @@ public class ContentSecurityPolicySettings implements IRequestCycleListener
* The new filter, must not be null.
* @return {@code this} for chaining.
*/
- public ContentSecurityPolicySettings
- setProtectedPageFilter(Predicate<IPageClassRequestHandler> protectedPageFilter)
+ public ContentSecurityPolicySettings setProtectedPageFilter(
+ Predicate<IPageClassRequestHandler> protectedPageFilter)
{
Args.notNull(protectedPageFilter, "protectedPageFilter");
this.protectedPageFilter = protectedPageFilter;
return this;
}
- protected boolean mustProtect(IRequestHandler handler)
- {
- if (handler instanceof IRequestHandlerDelegate)
- {
- return mustProtect(((IRequestHandlerDelegate) handler).getDelegateHandler());
- }
- if (handler instanceof IPageClassRequestHandler)
- {
- return mustProtectPageRequest((IPageClassRequestHandler) handler);
- }
- return !(handler instanceof BufferedResponseRequestHandler);
- }
-
+ /**
+ * Should any request to the given page be protected by CSP.
+ *
+ * @param handler
+ * @return <code>true</code> by default
+ *
+ * @see #setProtectedPageFilter(Predicate)
+ */
protected boolean mustProtectPageRequest(IPageClassRequestHandler handler)
{
return protectedPageFilter.test(handler);
}
- @Override
- public void onRequestHandlerResolved(RequestCycle cycle, IRequestHandler handler)
- {
- if (!mustProtect(handler) || !(cycle.getResponse() instanceof WebResponse))
- {
- return;
- }
-
- WebResponse webResponse = (WebResponse) cycle.getResponse();
- if (!webResponse.isHeaderSupported())
- {
- return;
- }
-
- configs.entrySet().stream().
- filter(entry -> entry.getValue().isSet())
- .forEach(entry -> {
- CSPHeaderMode mode = entry.getKey();
- CSPHeaderConfiguration config = entry.getValue();
- String headerValue = config.renderHeaderValue(this, cycle, handler);
- webResponse.setHeader(mode.getHeader(), headerValue);
- if (config.isAddLegacyHeaders())
- {
- webResponse.setHeader(mode.getLegacyHeader(), headerValue);
- }
- });
- }
-
/**
* Returns true if any of the headers includes a directive with a nonce.
*
@@ -167,9 +129,9 @@ public class ContentSecurityPolicySettings implements IRequestCycleListener
public String getNonce(RequestCycle cycle, IRequestHandler handler)
{
- String nonce = cycle.getMetaData(NONCE_KEY);
- Page currentPage = getPage(handler);
+ Page currentPage = IPageRequestHandler.getPage(handler);
+ String nonce = cycle.getMetaData(NONCE_KEY);
if (nonce == null)
{
if (currentPage != null)
@@ -178,7 +140,7 @@ public class ContentSecurityPolicySettings implements IRequestCycleListener
}
if (nonce == null)
{
- nonce = getSecuritySettings().getRandomSupplier().getRandomBase64(NONCE_LENGTH);
+ nonce = createNonce();
}
cycle.setMetaData(NONCE_KEY, nonce);
}
@@ -187,38 +149,15 @@ public class ContentSecurityPolicySettings implements IRequestCycleListener
{
currentPage.setMetaData(NONCE_KEY, nonce);
}
+
return nonce;
}
- /**
- * Resolves a page instance from the request handler iff the page instance is already created
- *
- * @param handler The request handler
- * @return page or {@code null} if none
- */
- public static Page getPage(IRequestHandler handler)
+ protected String createNonce()
{
- while (handler instanceof IRequestHandlerDelegate)
- {
- handler = ((IRequestHandlerDelegate) handler).getDelegateHandler();
- }
-
- if (handler instanceof IPageRequestHandler)
- {
- IPageRequestHandler pageHandler = (IPageRequestHandler) handler;
- if (pageHandler.isPageInstanceCreated())
- {
- return (Page) pageHandler.getPage();
- }
- }
- return null;
+ return application.getSecuritySettings().getRandomSupplier().getRandomBase64(NONCE_LENGTH);
}
- private SecuritySettings getSecuritySettings()
- {
- return application.getSecuritySettings();
- }
-
/**
* Returns the CSP configuration per {@link CSPHeaderMode}.
*
@@ -228,4 +167,18 @@ public class ContentSecurityPolicySettings implements IRequestCycleListener
{
return Collections.unmodifiableMap(configs);
}
+
+ /**
+ * Enforce CSP settings on an application.
+ *
+ * @param application
+ * application
+ */
+ public void enforce(WebApplication application)
+ {
+ application.getRequestCycleListeners().add(new CSPRequestCycleListener(this));
+ application.getHeaderResponseDecorators()
+ .add(response -> new CSPNonceHeaderResponseDecorator(response, this));
+ application.mount(new ReportCSPViolationMapper(this));
+ }
}
diff --git a/wicket-core/src/main/java/org/apache/wicket/csp/FixedCSPValue.java b/wicket-core/src/main/java/org/apache/wicket/csp/FixedCSPValue.java
index 1383bfc..4056f16 100644
--- a/wicket-core/src/main/java/org/apache/wicket/csp/FixedCSPValue.java
+++ b/wicket-core/src/main/java/org/apache/wicket/csp/FixedCSPValue.java
@@ -48,7 +48,7 @@ public class FixedCSPValue implements CSPRenderable
}
@Override
- public String render(ContentSecurityPolicySettings listener, RequestCycle cycle,
+ public String render(ContentSecurityPolicySettings settings, RequestCycle cycle,
IRequestHandler currentHandler)
{
return value;
diff --git a/wicket-core/src/main/java/org/apache/wicket/csp/RelativeURICSPValue.java b/wicket-core/src/main/java/org/apache/wicket/csp/RelativeURICSPValue.java
index 107fe9c..81ad2a3 100644
--- a/wicket-core/src/main/java/org/apache/wicket/csp/RelativeURICSPValue.java
+++ b/wicket-core/src/main/java/org/apache/wicket/csp/RelativeURICSPValue.java
@@ -45,7 +45,7 @@ public class RelativeURICSPValue implements CSPRenderable
}
@Override
- public String render(ContentSecurityPolicySettings listener, RequestCycle cycle,
+ public String render(ContentSecurityPolicySettings settings, RequestCycle cycle,
IRequestHandler currentHandler)
{
return cycle.getUrlRenderer().renderContextRelativeUrl(relativeUri);
diff --git a/wicket-core/src/main/java/org/apache/wicket/csp/ReportCSPViolationMapper.java b/wicket-core/src/main/java/org/apache/wicket/csp/ReportCSPViolationMapper.java
index eaa240c..289d1c4 100644
--- a/wicket-core/src/main/java/org/apache/wicket/csp/ReportCSPViolationMapper.java
+++ b/wicket-core/src/main/java/org/apache/wicket/csp/ReportCSPViolationMapper.java
@@ -44,11 +44,11 @@ public class ReportCSPViolationMapper extends AbstractMapper
private static final Logger log = LoggerFactory.getLogger(ReportCSPViolationMapper.class);
- private final ContentSecurityPolicySettings csp;
+ private final ContentSecurityPolicySettings settings;
- public ReportCSPViolationMapper(ContentSecurityPolicySettings csp)
+ public ReportCSPViolationMapper(ContentSecurityPolicySettings settings)
{
- this.csp = csp;
+ this.settings = settings;
}
@Override
@@ -108,7 +108,7 @@ public class ReportCSPViolationMapper extends AbstractMapper
{
return false;
}
- for (CSPHeaderConfiguration curConfig : csp.getConfiguration().values())
+ for (CSPHeaderConfiguration curConfig : settings.getConfiguration().values())
{
String mountPath = curConfig.getReportUriMountPath();
if (mountPath != null
diff --git a/wicket-core/src/main/java/org/apache/wicket/mock/MockApplication.java b/wicket-core/src/main/java/org/apache/wicket/mock/MockApplication.java
index ecee55c..8dd8920 100644
--- a/wicket-core/src/main/java/org/apache/wicket/mock/MockApplication.java
+++ b/wicket-core/src/main/java/org/apache/wicket/mock/MockApplication.java
@@ -75,6 +75,6 @@ public class MockApplication extends WebApplication
// and isn't needed, because the markup isn't rendered by a browser
getResourceSettings().disableWicketCoreCSS();
// disable nonces, CSP is not needed anyway during tests
- getCspSettings().blocking().disabled();
+ getContentSecurityPolicySettings().blocking().disabled();
}
}
diff --git a/wicket-core/src/main/java/org/apache/wicket/protocol/http/WebApplication.java b/wicket-core/src/main/java/org/apache/wicket/protocol/http/WebApplication.java
index 6c777ed..6c02a29 100644
--- a/wicket-core/src/main/java/org/apache/wicket/protocol/http/WebApplication.java
+++ b/wicket-core/src/main/java/org/apache/wicket/protocol/http/WebApplication.java
@@ -74,6 +74,7 @@ import org.apache.wicket.request.resource.JavaScriptResourceReference;
import org.apache.wicket.request.resource.ResourceReference;
import org.apache.wicket.resource.bundles.ReplacementResourceBundleReference;
import org.apache.wicket.session.HttpSessionStore;
+import org.apache.wicket.settings.JavaScriptLibrarySettings;
import org.apache.wicket.util.crypt.CharEncoding;
import org.apache.wicket.util.file.FileCleaner;
import org.apache.wicket.util.file.IFileCleaner;
@@ -750,23 +751,6 @@ public abstract class WebApplication extends Application
getResourceSettings().setFileCleaner(new FileCleaner());
- cspSettings = newCspEnforcer();
- getRequestCycleListeners().add(getCspSettings());
- getHeaderResponseDecorators()
- .add(response -> new CSPNonceHeaderResponseDecorator(response, getCspSettings()));
- mount(new ReportCSPViolationMapper(getCspSettings()));
- getCspSettings().blocking().strict();
-
- if (getConfigurationType() == RuntimeConfigurationType.DEVELOPMENT)
- {
- // Add optional sourceFolder for resources.
- String resourceFolder = getInitParameter("sourceFolder");
- if (resourceFolder != null)
- {
- getResourceSettings().getResourceFinders().add(new Path(resourceFolder));
- }
- getCspSettings().blocking().reportBack();
- }
setPageRendererProvider(WebPageRenderer::new);
setSessionStoreProvider(HttpSessionStore::new);
setAjaxRequestTargetProvider(AjaxRequestHandler::new);
@@ -779,8 +763,21 @@ public abstract class WebApplication extends Application
});
});
+ getContentSecurityPolicySettings().enforce(this);
+
// Configure the app.
configure();
+ if (getConfigurationType() == RuntimeConfigurationType.DEVELOPMENT)
+ {
+ // Add optional sourceFolder for resources.
+ String resourceFolder = getInitParameter("sourceFolder");
+ if (resourceFolder != null)
+ {
+ getResourceSettings().getResourceFinders().add(new Path(resourceFolder));
+ }
+ getContentSecurityPolicySettings().blocking().reportBack();
+ }
+ getContentSecurityPolicySettings().blocking().strict();
}
/**
@@ -1097,7 +1094,7 @@ public abstract class WebApplication extends Application
*
* @return The newly created CSP enforcer.
*/
- protected ContentSecurityPolicySettings newCspEnforcer()
+ protected ContentSecurityPolicySettings newContentSecurityPolicySettings()
{
return new ContentSecurityPolicySettings(this);
}
@@ -1111,8 +1108,14 @@ public abstract class WebApplication extends Application
* @see ContentSecurityPolicySettings
* @see CSPHeaderConfiguration
*/
- public ContentSecurityPolicySettings getCspSettings()
+ public ContentSecurityPolicySettings getContentSecurityPolicySettings()
{
+ checkSettingsAvailable();
+
+ if (cspSettings == null)
+ {
+ cspSettings = newContentSecurityPolicySettings();
+ }
return cspSettings;
}
}
\ No newline at end of file
diff --git a/wicket-core/src/test/java/org/apache/wicket/csp/CSPSettingRequestCycleListenerTest.java b/wicket-core/src/test/java/org/apache/wicket/csp/CSPSettingRequestCycleListenerTest.java
index e0d4123..64788ca 100644
--- a/wicket-core/src/test/java/org/apache/wicket/csp/CSPSettingRequestCycleListenerTest.java
+++ b/wicket-core/src/test/java/org/apache/wicket/csp/CSPSettingRequestCycleListenerTest.java
@@ -37,39 +37,35 @@ import java.util.stream.Collectors;
import java.util.stream.Stream;
import org.apache.wicket.mock.MockHomePage;
+import org.apache.wicket.protocol.http.WebApplication;
import org.apache.wicket.util.tester.WicketTestCase;
import org.apache.wicket.util.tester.WicketTester;
import org.junit.jupiter.api.Assertions;
-import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
public class CSPSettingRequestCycleListenerTest extends WicketTestCase
{
- private WicketTester wicketTester;
-
- @BeforeEach
- public void setUp()
+ @Override
+ protected WicketTester newWicketTester(WebApplication app)
{
- wicketTester = new WicketTester(MockHomePage.class);
+ return new WicketTester(MockHomePage.class);
}
@Test
public void testNullSrcInputIsRejected()
{
- ContentSecurityPolicySettings cspListener =
- new ContentSecurityPolicySettings(tester.getApplication());
+ ContentSecurityPolicySettings settings = tester.getApplication().getContentSecurityPolicySettings();
Assertions.assertThrows(IllegalArgumentException.class, () -> {
- cspListener.blocking().add(DEFAULT_SRC, (String) null);
+ settings.blocking().add(DEFAULT_SRC, (String) null);
});
}
@Test
public void testEmptySrcInputIsRejected()
{
- ContentSecurityPolicySettings cspListener =
- new ContentSecurityPolicySettings(tester.getApplication());
+ ContentSecurityPolicySettings settings = tester.getApplication().getContentSecurityPolicySettings();
Assertions.assertThrows(IllegalArgumentException.class, () -> {
- cspListener.blocking().add(DEFAULT_SRC, "");
+ settings.blocking().add(DEFAULT_SRC, "");
});
}
@@ -80,10 +76,9 @@ public class CSPSettingRequestCycleListenerTest extends WicketTestCase
@Test
public void testInvalidSrcInputIsRejected()
{
- ContentSecurityPolicySettings cspListener =
- new ContentSecurityPolicySettings(tester.getApplication());
+ ContentSecurityPolicySettings settings = tester.getApplication().getContentSecurityPolicySettings();
Assertions.assertThrows(IllegalArgumentException.class, () -> {
- cspListener.blocking().add(DEFAULT_SRC, "abc?^()-_\'xyz");
+ settings.blocking().add(DEFAULT_SRC, "abc?^()-_\'xyz");
});
}
@@ -94,10 +89,9 @@ public class CSPSettingRequestCycleListenerTest extends WicketTestCase
@Test
public void testMultipleSrcInputWithNoneIsRejected1()
{
- ContentSecurityPolicySettings cspListener =
- new ContentSecurityPolicySettings(tester.getApplication());
+ ContentSecurityPolicySettings settings = tester.getApplication().getContentSecurityPolicySettings();
Assertions.assertThrows(IllegalArgumentException.class, () -> {
- cspListener.blocking().add(DEFAULT_SRC, SELF, NONE);
+ settings.blocking().add(DEFAULT_SRC, SELF, NONE);
});
}
@@ -108,10 +102,9 @@ public class CSPSettingRequestCycleListenerTest extends WicketTestCase
@Test
public void testMultipleSrcInputWithNoneIsRejected2()
{
- ContentSecurityPolicySettings cspListener =
- new ContentSecurityPolicySettings(tester.getApplication());
+ ContentSecurityPolicySettings settings = tester.getApplication().getContentSecurityPolicySettings();
Assertions.assertThrows(IllegalArgumentException.class, () -> {
- cspListener.blocking().add(DEFAULT_SRC, NONE, SELF);
+ settings.blocking().add(DEFAULT_SRC, NONE, SELF);
});
}
@@ -122,11 +115,10 @@ public class CSPSettingRequestCycleListenerTest extends WicketTestCase
@Test
public void testMultipleSrcInputWithStarIsRejected1()
{
- ContentSecurityPolicySettings cspListener =
- new ContentSecurityPolicySettings(tester.getApplication());
- cspListener.blocking().add(DEFAULT_SRC, SELF);
+ ContentSecurityPolicySettings settings = tester.getApplication().getContentSecurityPolicySettings();
+ settings.blocking().add(DEFAULT_SRC, SELF);
Assertions.assertThrows(IllegalArgumentException.class, () -> {
- cspListener.blocking().add(DEFAULT_SRC, WILDCARD);
+ settings.blocking().add(DEFAULT_SRC, WILDCARD);
});
}
@@ -137,119 +129,107 @@ public class CSPSettingRequestCycleListenerTest extends WicketTestCase
@Test
public void testMultipleSrcInputWithStarIsRejected2()
{
- ContentSecurityPolicySettings cspListener =
- new ContentSecurityPolicySettings(tester.getApplication());
- cspListener.blocking().add(DEFAULT_SRC, WILDCARD);
+ ContentSecurityPolicySettings settings = tester.getApplication().getContentSecurityPolicySettings();
+ settings.blocking().add(DEFAULT_SRC, WILDCARD);
Assertions.assertThrows(IllegalArgumentException.class, () -> {
- cspListener.blocking().add(DEFAULT_SRC, SELF);
+ settings.blocking().add(DEFAULT_SRC, SELF);
});
}
@Test
public void testWrongSrcInputIsRejected()
{
- ContentSecurityPolicySettings cspListener =
- new ContentSecurityPolicySettings(tester.getApplication());
+ ContentSecurityPolicySettings settings = tester.getApplication().getContentSecurityPolicySettings();
Assertions.assertThrows(IllegalArgumentException.class, () -> {
- cspListener.blocking().add(DEFAULT_SRC, ALLOW_FORMS);
+ settings.blocking().add(DEFAULT_SRC, ALLOW_FORMS);
});
}
@Test
public void testWrongSandboxInputIsRejected()
{
- ContentSecurityPolicySettings cspListener =
- new ContentSecurityPolicySettings(tester.getApplication());
+ ContentSecurityPolicySettings settings = tester.getApplication().getContentSecurityPolicySettings();
Assertions.assertThrows(IllegalArgumentException.class, () -> {
- cspListener.blocking().add(SANDBOX, SELF);
+ settings.blocking().add(SANDBOX, SELF);
});
}
@Test
public void testNullSandboxInputIsRejected()
{
- ContentSecurityPolicySettings cspListener =
- new ContentSecurityPolicySettings(tester.getApplication());
+ ContentSecurityPolicySettings settings = tester.getApplication().getContentSecurityPolicySettings();
Assertions.assertThrows(IllegalArgumentException.class, () -> {
- cspListener.blocking().add(SANDBOX, (String) null);
+ settings.blocking().add(SANDBOX, (String) null);
});
}
@Test
public void testEmptySandboxInputIsAccepted()
{
- ContentSecurityPolicySettings cspListener =
- new ContentSecurityPolicySettings(tester.getApplication());
- cspListener.blocking().add(SANDBOX, CSPDirectiveSandboxValue.EMPTY);
+ ContentSecurityPolicySettings settings = tester.getApplication().getContentSecurityPolicySettings();
+ settings.blocking().add(SANDBOX, CSPDirectiveSandboxValue.EMPTY);
}
@Test
public void testInvalidSandboxInputIsRejected()
{
- ContentSecurityPolicySettings cspListener =
- new ContentSecurityPolicySettings(tester.getApplication());
+ ContentSecurityPolicySettings settings = tester.getApplication().getContentSecurityPolicySettings();
Assertions.assertThrows(IllegalArgumentException.class, () -> {
- cspListener.blocking().add(SANDBOX, "abcxyz");
+ settings.blocking().add(SANDBOX, "abcxyz");
});
}
@Test
public void testMultipleSandboxInputWithEmptyStringIsRejected1()
{
- ContentSecurityPolicySettings cspListener =
- new ContentSecurityPolicySettings(tester.getApplication());
- cspListener.blocking().add(SANDBOX, ALLOW_FORMS);
+ ContentSecurityPolicySettings settings = tester.getApplication().getContentSecurityPolicySettings();
+ settings.blocking().add(SANDBOX, ALLOW_FORMS);
Assertions.assertThrows(IllegalArgumentException.class, () -> {
- cspListener.blocking().add(SANDBOX, EMPTY);
+ settings.blocking().add(SANDBOX, EMPTY);
});
}
@Test
public void testMultipleSandboxInputWithEmptyStringIsRejected2()
{
- ContentSecurityPolicySettings cspListener =
- new ContentSecurityPolicySettings(tester.getApplication());
- cspListener.blocking().add(SANDBOX, EMPTY);
+ ContentSecurityPolicySettings settings = tester.getApplication().getContentSecurityPolicySettings();
+ settings.blocking().add(SANDBOX, EMPTY);
Assertions.assertThrows(IllegalArgumentException.class, () -> {
- cspListener.blocking().add(SANDBOX, ALLOW_FORMS);
+ settings.blocking().add(SANDBOX, ALLOW_FORMS);
});
}
@Test
public void testNullReportUriInputIsRejected()
{
- ContentSecurityPolicySettings cspListener =
- new ContentSecurityPolicySettings(tester.getApplication());
+ ContentSecurityPolicySettings settings = tester.getApplication().getContentSecurityPolicySettings();
Assertions.assertThrows(IllegalArgumentException.class, () -> {
- cspListener.blocking().add(REPORT_URI, (String) null);
+ settings.blocking().add(REPORT_URI, (String) null);
});
}
@Test
public void testEmptyReportUriInputIsRejected()
{
- ContentSecurityPolicySettings cspListener =
- new ContentSecurityPolicySettings(tester.getApplication());
+ ContentSecurityPolicySettings settings = tester.getApplication().getContentSecurityPolicySettings();
Assertions.assertThrows(IllegalArgumentException.class, () -> {
- cspListener.blocking().add(REPORT_URI, "");
+ settings.blocking().add(REPORT_URI, "");
});
}
@Test
public void testInvalidReportUriInputIsRejected()
{
- ContentSecurityPolicySettings cspListener =
- new ContentSecurityPolicySettings(tester.getApplication());
+ ContentSecurityPolicySettings settings = tester.getApplication().getContentSecurityPolicySettings();
Assertions.assertThrows(IllegalArgumentException.class, () -> {
- cspListener.blocking().add(REPORT_URI, "abc?^()-_\'xyz");
+ settings.blocking().add(REPORT_URI, "abc?^()-_\'xyz");
});
}
@Test
public void testAllCSPSrcDefaultEnumsAreSetCorrectly() throws NoSuchAlgorithmException
{
- ContentSecurityPolicySettings cspListener =
- new ContentSecurityPolicySettings(tester.getApplication());
+ ContentSecurityPolicySettings settings = tester.getApplication().getContentSecurityPolicySettings();
final int cspDirectiveCount = CSPDirective.values().length;
final int cspDirectiveSrcValueCount = CSPDirectiveSrcValue.values().length;
@@ -261,13 +241,13 @@ public class CSPSettingRequestCycleListenerTest extends WicketTestCase
{
final CSPDirectiveSrcValue cspDirectiveValue =
CSPDirectiveSrcValue.values()[i % cspDirectiveSrcValueCount];
- cspListener.blocking().add(cspDirective, cspDirectiveValue);
+ settings.blocking().add(cspDirective, cspDirectiveValue);
- cspListener.reporting().add(cspDirective, cspDirectiveValue);
+ settings.reporting().add(cspDirective, cspDirectiveValue);
}
}
- List<String> headerErrors = checkHeaders(cspListener);
+ List<String> headerErrors = checkHeaders();
if (!headerErrors.isEmpty())
{
@@ -278,12 +258,11 @@ public class CSPSettingRequestCycleListenerTest extends WicketTestCase
@Test
public void testCSPReportUriDirectiveSetCorrectly()
{
- ContentSecurityPolicySettings cspListener =
- new ContentSecurityPolicySettings(tester.getApplication());
- cspListener.blocking().add(REPORT_URI, "http://report.example.com");
- cspListener.reporting().add(REPORT_URI, "/example-report-uri");
+ ContentSecurityPolicySettings settings = tester.getApplication().getContentSecurityPolicySettings();
+ settings.blocking().add(REPORT_URI, "http://report.example.com");
+ settings.reporting().add(REPORT_URI, "/example-report-uri");
- List<String> headerErrors = checkHeaders(cspListener);
+ List<String> headerErrors = checkHeaders();
if (!headerErrors.isEmpty())
{
@@ -294,8 +273,7 @@ public class CSPSettingRequestCycleListenerTest extends WicketTestCase
@Test
public void testCSPSandboxDirectiveSetCorrectly()
{
- ContentSecurityPolicySettings cspListener =
- new ContentSecurityPolicySettings(tester.getApplication());
+ ContentSecurityPolicySettings settings = tester.getApplication().getContentSecurityPolicySettings();
final int cspSandboxDirectiveValueCount = CSPDirectiveSandboxValue.values().length;
for (int i = 0; i < cspSandboxDirectiveValueCount; i++)
{
@@ -303,11 +281,11 @@ public class CSPSettingRequestCycleListenerTest extends WicketTestCase
if (cspDirectiveValue.equals(CSPDirectiveSandboxValue.EMPTY))
continue;
- cspListener.blocking().add(SANDBOX, cspDirectiveValue);
- cspListener.reporting().add(SANDBOX, cspDirectiveValue);
+ settings.blocking().add(SANDBOX, cspDirectiveValue);
+ settings.reporting().add(SANDBOX, cspDirectiveValue);
}
- List<String> headerErrors = checkHeaders(cspListener);
+ List<String> headerErrors = checkHeaders();
if (!headerErrors.isEmpty())
{
@@ -322,11 +300,10 @@ public class CSPSettingRequestCycleListenerTest extends WicketTestCase
@Test
public void testChildSrcDirectiveAlsoSetsFrameSrcDirective()
{
- ContentSecurityPolicySettings cspListener =
- new ContentSecurityPolicySettings(tester.getApplication());
- cspListener.blocking().add(CHILD_SRC, SELF);
- cspListener.reporting().add(CHILD_SRC, SELF);
- List<String> headerErrors = checkHeaders(cspListener);
+ ContentSecurityPolicySettings settings = tester.getApplication().getContentSecurityPolicySettings();
+ settings.blocking().add(CHILD_SRC, SELF);
+ settings.reporting().add(CHILD_SRC, SELF);
+ List<String> headerErrors = checkHeaders();
if (!headerErrors.isEmpty())
{
@@ -334,15 +311,14 @@ public class CSPSettingRequestCycleListenerTest extends WicketTestCase
}
}
- private List<String> checkHeaders(ContentSecurityPolicySettings cspListener)
+ private List<String> checkHeaders()
{
List<String> headerErrors = new ArrayList<>();
- wicketTester.getRequestCycle().getListeners().add(cspListener);
- wicketTester.executeUrl("/");
+ tester.executeUrl("/");
String cspHeaderValue =
- wicketTester.getLastResponse().getHeader(CSPHeaderMode.BLOCKING.getHeader());
+ tester.getLastResponse().getHeader(CSPHeaderMode.BLOCKING.getHeader());
String cspReportingHeaderValue =
- wicketTester.getLastResponse().getHeader(CSPHeaderMode.REPORT_ONLY.getHeader());
+ tester.getLastResponse().getHeader(CSPHeaderMode.REPORT_ONLY.getHeader());
if (cspHeaderValue == null)
{
diff --git a/wicket-core/src/test/java/org/apache/wicket/markup/head/filter/FilteringHeaderResponseTest.java b/wicket-core/src/test/java/org/apache/wicket/markup/head/filter/FilteringHeaderResponseTest.java
index da38317..2286a4c 100644
--- a/wicket-core/src/test/java/org/apache/wicket/markup/head/filter/FilteringHeaderResponseTest.java
+++ b/wicket-core/src/test/java/org/apache/wicket/markup/head/filter/FilteringHeaderResponseTest.java
@@ -45,7 +45,7 @@ class FilteringHeaderResponseTest extends WicketTestCase
return new MockApplication()
{
@Override
- protected ContentSecurityPolicySettings newCspEnforcer()
+ protected ContentSecurityPolicySettings newContentSecurityPolicySettings()
{
return new ContentSecurityPolicySettings(this)
{
@@ -117,7 +117,7 @@ class FilteringHeaderResponseTest extends WicketTestCase
@Test
void nonce() throws Exception
{
- tester.getApplication().getCspSettings().blocking().strict();
+ tester.getApplication().getContentSecurityPolicySettings().blocking().strict();
executeTest(CspNoncePage.class, "CspNoncePageExpected.html");
}
}
diff --git a/wicket-examples/src/main/java/org/apache/wicket/examples/WicketExampleApplication.java b/wicket-examples/src/main/java/org/apache/wicket/examples/WicketExampleApplication.java
index 2303b34..a2c7b1c 100644
--- a/wicket-examples/src/main/java/org/apache/wicket/examples/WicketExampleApplication.java
+++ b/wicket-examples/src/main/java/org/apache/wicket/examples/WicketExampleApplication.java
@@ -63,7 +63,7 @@ public abstract class WicketExampleApplication extends WebApplication
getDebugSettings().setDevelopmentUtilitiesEnabled(true);
getResourceSettings().setCssCompressor(new CssUrlReplacer());
- getCspSettings().blocking().strict().reportBack()
+ getContentSecurityPolicySettings().blocking().strict().reportBack()
.add(CSPDirective.STYLE_SRC,
"https://maxcdn.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.min.css")
.add(CSPDirective.FONT_SRC, "https://maxcdn.bootstrapcdn.com");
diff --git a/wicket-examples/src/main/java/org/apache/wicket/examples/authentication3/MyAuthenticatedWebApplication.java b/wicket-examples/src/main/java/org/apache/wicket/examples/authentication3/MyAuthenticatedWebApplication.java
index d01c1a1..6628679 100644
--- a/wicket-examples/src/main/java/org/apache/wicket/examples/authentication3/MyAuthenticatedWebApplication.java
+++ b/wicket-examples/src/main/java/org/apache/wicket/examples/authentication3/MyAuthenticatedWebApplication.java
@@ -54,7 +54,7 @@ public class MyAuthenticatedWebApplication extends AuthenticatedWebApplication
super.init();
getDebugSettings().setDevelopmentUtilitiesEnabled(true);
- getCspSettings().blocking()
+ getContentSecurityPolicySettings().blocking()
.strict()
.reportBack()
.add(CSPDirective.STYLE_SRC,
diff --git a/wicket-examples/src/main/java/org/apache/wicket/examples/images/ImagesApplication.java b/wicket-examples/src/main/java/org/apache/wicket/examples/images/ImagesApplication.java
index 4487be6..59eccc0 100644
--- a/wicket-examples/src/main/java/org/apache/wicket/examples/images/ImagesApplication.java
+++ b/wicket-examples/src/main/java/org/apache/wicket/examples/images/ImagesApplication.java
@@ -41,7 +41,7 @@ public class ImagesApplication extends WicketExampleApplication
super.init();
getSharedResources().add("cancelButton", new DefaultButtonImageResource("Cancel"));
- getCspSettings().blocking().add(CSPDirective.IMG_SRC, "data:");
+ getContentSecurityPolicySettings().blocking().add(CSPDirective.IMG_SRC, "data:");
}
}
diff --git a/wicket-examples/src/main/java/org/apache/wicket/examples/media/VideosApplication.java b/wicket-examples/src/main/java/org/apache/wicket/examples/media/VideosApplication.java
index 59dd0a3..8494511 100644
--- a/wicket-examples/src/main/java/org/apache/wicket/examples/media/VideosApplication.java
+++ b/wicket-examples/src/main/java/org/apache/wicket/examples/media/VideosApplication.java
@@ -49,7 +49,7 @@ public class VideosApplication extends WicketExampleApplication
guard.addPattern("+*.mp4");
}
- getCspSettings().blocking()
+ getContentSecurityPolicySettings().blocking()
.add(CSPDirective.MEDIA_SRC, CSPDirectiveSrcValue.SELF)
.add(CSPDirective.MEDIA_SRC, "https://w3c-test.org/media/movie_300.mp4");
}
diff --git a/wicket-examples/src/main/java/org/apache/wicket/examples/websocket/JSR356Application.java b/wicket-examples/src/main/java/org/apache/wicket/examples/websocket/JSR356Application.java
index b8c68cf..b72a300 100644
--- a/wicket-examples/src/main/java/org/apache/wicket/examples/websocket/JSR356Application.java
+++ b/wicket-examples/src/main/java/org/apache/wicket/examples/websocket/JSR356Application.java
@@ -65,7 +65,7 @@ public class JSR356Application extends WicketExampleApplication
// The websocket example loads JS from ajax.googleapis.com, which is not allowed by the CSP.
// This now serves as an example on how to disable CSP
- getCspSettings().blocking().disabled();
+ getContentSecurityPolicySettings().blocking().disabled();
}
@Override
[wicket] 01/02: remove obsolete ajax setting
Posted by sv...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
svenmeier pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/wicket.git
commit 227d42117fe64a7c7f439b1342fbd59b577a9141
Author: Sven Meier <sv...@apache.org>
AuthorDate: Wed Mar 11 21:35:37 2020 +0100
remove obsolete ajax setting
---
.../org/apache/wicket/protocol/http/WebApplication.java | 17 +----------------
1 file changed, 1 insertion(+), 16 deletions(-)
diff --git a/wicket-core/src/main/java/org/apache/wicket/protocol/http/WebApplication.java b/wicket-core/src/main/java/org/apache/wicket/protocol/http/WebApplication.java
index 1eda219..6c777ed 100644
--- a/wicket-core/src/main/java/org/apache/wicket/protocol/http/WebApplication.java
+++ b/wicket-core/src/main/java/org/apache/wicket/protocol/http/WebApplication.java
@@ -1115,19 +1115,4 @@ public abstract class WebApplication extends Application
{
return cspSettings;
}
-
- /**
- * If true, auto label css classes such as {@code error} and {@code required} will be updated
- * after form component processing during an ajax request. This allows auto labels to correctly
- * reflect the state of the form component even if they are not part of the ajax markup update.
- *
- * TODO in wicket-7 this should move into a settings object. cannot move in 6.x because it
- * requires a change to a setting interface.
- *
- * @return {@code true} iff enabled
- */
- public boolean getUpdateAutoLabelsOnAjaxRequests()
- {
- return true;
- }
-}
+}
\ No newline at end of file