Enum Class CspMode

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

public enum CspMode extends Enum<CspMode>
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.CSP configuration parameter and read with DeploymentConfiguration.getCspMode().

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 CspMode OFF
      The default mode. The application behaves as if no strict Content Security Policy is in use.
    • WARN

      public static final CspMode WARN
      The application runs unchanged, but every call that would not work under a strict Content Security Policy is logged as a warning, once per call site, with a stack trace that leads from the API to its caller.
    • STRICT

      public static final CspMode STRICT
      Vaadin sends a nonce-based Content Security Policy, and APIs that need eval throw a CspViolationException, 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: Vaadin itself still uses APIs that need eval in some places, such as the event filters of double and single click listeners and of keyboard shortcuts. Until those are changed, they throw in this mode. Event data that is a property path, such as that of a click listener, does not need eval.

  • Method Details

    • values

      public static CspMode[] 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 CspMode 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