Enum Class ContentSecurityPolicyMode

java.lang.Object
java.lang.Enum<ContentSecurityPolicyMode>
com.vaadin.flow.server.ContentSecurityPolicyMode
All Implemented Interfaces:
Serializable, Comparable<ContentSecurityPolicyMode>, Constable

public enum ContentSecurityPolicyMode extends Enum<ContentSecurityPolicyMode>
Modes for running the application under a strict Content Security Policy, i.e. a nonce-based script-src policy without 'unsafe-inline' and 'unsafe-eval'.

The mode is configured with the InitParameters.CONTENT_SECURITY_POLICY configuration parameter and read with DeploymentConfiguration.getContentSecurityPolicyMode().

The WARN and STRICT modes act on the APIs that send JavaScript to the browser as a string, such as Element.executeJs(String, Object...), because the browser has to compile it, which a strict policy blocks. This applies to the calls that Vaadin itself makes as well, and in development mode as much as in production mode. The STRICT mode also sends the Content Security Policy header in production mode.

Since:
25.4
  • Enum Constant Details

    • OFF

      public static final ContentSecurityPolicyMode OFF
      The default mode. The application behaves as if no strict Content Security Policy is in use.
    • WARN

      public static final ContentSecurityPolicyMode WARN
      The application runs unchanged, but every call that would not work under a strict Content Security Policy is logged as a warning, with a stack trace that leads from the API to its caller. A warning is logged once per call site, or, when a component reports what the JavaScript belongs to, once per call site and reported part, such as a chart option.
    • STRICT

      public static final ContentSecurityPolicyMode STRICT
      Vaadin sends a nonce-based Content Security Policy, and APIs that need eval throw a ContentSecurityPolicyViolationException, whose stack trace leads from the API to its caller.

      In production mode, every index HTML response gets a new nonce that is put on every <script> element of the page, and a Content-Security-Policy header that allows only the scripts with that nonce and the scripts they load. Applications adjust the policy through IndexHtmlResponse.getContentSecurityPolicy(). No header is sent in development mode, because the development server and the development tools need eval.

      Note: An API that needs eval throws for every caller, including a Vaadin component or an add-on that uses one. Run the application in the WARN mode first to find such uses. A string that the application declares in a JsStringFallback interface runs the bundled JavaScript instead, which makes an add-on that sends it work.

  • Method Details

    • values

      public static ContentSecurityPolicyMode[] values()
      Returns an array containing the constants of this enum class, in the order they are declared.
      Returns:
      an array containing the constants of this enum class, in the order they are declared
    • valueOf

      public static ContentSecurityPolicyMode valueOf(String name)
      Returns the enum constant of this class with the specified name. The string must match exactly an identifier used to declare an enum constant in this class. (Extraneous whitespace characters are not permitted.)
      Parameters:
      name - the name of the enum constant to be returned.
      Returns:
      the enum constant with the specified name
      Throws:
      IllegalArgumentException - if this enum class has no constant with the specified name
      NullPointerException - if the argument is null