Class ContentSecurityPolicySettings


  • public class ContentSecurityPolicySettings
    extends Object
    Build the CSP configuration like this:
     
      myApplication.getCspSettings().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();
     	
     
    See CSPHeaderConfiguration for more details on specifying the configuration.
    Author:
    Sven Haster, Emond Papegaaij
    See Also:
    https://www.w3.org/TR/CSP2, https://developer.mozilla.org/en-US/docs/Web/Security/CSP
    • Constructor Detail

      • ContentSecurityPolicySettings

        public ContentSecurityPolicySettings​(Application application)
    • Method Detail

      • setProtectedFilter

        public ContentSecurityPolicySettings setProtectedFilter​(Predicate<org.apache.wicket.request.IRequestHandler> protectedFilter)
        Sets the predicate that determines which requests must be protected by the CSP. When the predicate evaluates to false, the request will not be protected.
        Parameters:
        protectedFilter - The new filter, must not be null.
        Returns:
        this for chaining.
      • mustProtectRequest

        protected boolean mustProtectRequest​(org.apache.wicket.request.IRequestHandler handler)
        Should any request be protected by CSP.
        Parameters:
        handler -
        Returns:
        true by default
        See Also:
        setProtectedFilter(Predicate)
      • isNonceEnabled

        public final boolean isNonceEnabled()
        Returns true if any of the headers includes a directive with a nonce.
        Returns:
        If a nonce is used in the CSP.
      • createNonce

        protected String createNonce()
      • enforce

        public void enforce​(WebApplication application)
        Enforce CSP settings on an application.
        Parameters:
        application - application