Skip to content

Add a csp mode setting (off, warn, strict) #26147

Closed

Description

@totally-not-ai

Describe your motivation

Running a Vaadin application under a strict Content Security Policy (script-src 'nonce-…', no unsafe-inline, no unsafe-eval) needs one explicit switch that the rest of the strict-CSP work can key off, see vaadin/platform#9488.

Describe the solution you'd like

A csp configuration setting with three values:

  • off (default): exactly today's behaviour.
  • warn: the application runs unchanged, but every call that would not work under a strict policy is logged.
  • strict: Vaadin sends a nonce-based policy, and APIs that need eval throw.

It is configured like other Vaadin settings: servlet init parameter / system property (vaadin.csp) and the Spring Boot property, and exposed through DeploymentConfiguration so framework code can query the active mode.

This issue covers only the setting and its plumbing. The behaviour of warn and strict is tracked in separate sub-issues of the parent issue.

Activity

  1. totally-not-ai commented on Oct 2, 2026

    @totally-not-ai
    ContributorAuthor

    Analysis

    This is a valid, self-contained request: there is no CSP-related setting in Flow yet, and the later warn/strict behaviour needs a single switch to key off.

    Flow already has a direct precedent for an enum-valued setting: sessionLockCheckStrategy / SessionLockCheckStrategy. It is an InitParameters constant, a default method on DeploymentConfiguration, and parsing in DefaultDeploymentConfiguration, where an unrecognized value logs a warning and falls back to the default. Following the same shape gives every requested configuration source for free:

    • servlet init parameter csp
    • system property / application property vaadin.csp (via getApplicationOrSystemProperty)
    • Spring Boot vaadin.csp: SpringServlet already forwards every InitParameters constant from the Spring environment, so no Spring-specific code is needed

    Proposed change (draft PR follows)

    • New enum com.vaadin.flow.server.CspMode { OFF, WARN, STRICT }
    • InitParameters.CSP = "csp"
    • DeploymentConfiguration#getCspMode(): a default method that returns CspMode.OFF, so other DeploymentConfiguration implementations keep working unchanged
    • DefaultDeploymentConfiguration parses the value case-insensitively. An unknown value adds a warning (WARNING_CSP_MODE_NOT_RECOGNIZED) and falls back to OFF.

    With the default off, behaviour does not change at all. Nothing reads the mode yet; warn/strict behaviour is left to the sibling sub-issues, as the issue describes.

  2. vaadin-bot commented on Nov 6, 2026

    @vaadin-bot
    Collaborator

    This ticket/PR has been released with Vaadin 25.4.0-alpha5.

  3. added a commit that references this issue on Nov 8, 2026
    7fbbc3d
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions