Repository navigation
Description
Description
A csp mode setting — off (default, today's behaviour), warn (reports what would break), strict (Vaadin serves a nonce-based policy and eval-requiring APIs throw).
Tier
Free
License
Apache 2.0
Motivation
Background
A strict Content Security Policy (script-src 'nonce-…', no unsafe-inline, no unsafe-eval) is a standing requirement in banking, public sector, and anywhere a security audit gates deployment. Vaadin sends server-initiated JavaScript to the browser as strings that are compiled with new Function — exactly what unsafe-eval forbids.
Since 24.5 a nonce-based policy is possible: the application adds an IndexHtmlRequestListener that generates the nonce and puts it on the script tags, overrides window.Function and window.eval, and hand-maintains a map from every JavaScript string Vaadin, its components and its add-ons might send to a pre-defined function. That is the documented approach today.
Problem
- The workaround is not maintainable. The map has to be rebuilt whenever Flow, a component or an add-on changes a snippet, and entries are discovered by watching console warnings at runtime. The reference application for it already breaks on server-side navigation (csp.js file throws client-side error with backend navigation flow-crm-tutorial#314).
- The framework itself is not CSP-clean. Five places in the client engine compile strings into functions:
executeJsexpressions, server-sent JS functions (Support executeJs decomposition through passing an JS function to executeJs flow#24373), DOM event data expressions, DOM event filters, and on-demand chunk loading. Flow has ~100executeJscall sites and the components ~60, so an application that writes no JavaScript of its own still cannot run strictly. - Nothing tells you where you stand. Finding violations means enabling the policy in a browser and reading console errors that name generated JavaScript, not the Java code that caused it. There is no incremental path from "works" to "strict".
- The same string concatenation is an XSS risk. Building snippets by concatenating values into JavaScript is the failure mode declared JavaScript removes.
Solution
One setting that makes the state explicit:
off(default) — exactly today's behaviour. No application sees a change.warn— the application runs unchanged, but every API call that would not work under a strict policy is logged, with the Java call site.strict— Vaadin generates the nonce and sends the header itself, and the APIs that cannot work throw instead of failing silently in the browser.
Plus the mechanism that makes strict reachable: JavaScript declared as constants in Java, collected into the bundle by the build, invoked by naming the interface and method rather than by sending a script (vaadin/flow#10759).
@JsInvoker
public interface ScrollJs extends Serializable {
@JsExpression("this.scrollTo({ top: $0, behavior: 'smooth' })")
void scrollTo(int top);
}
container.getElement().getJsInvoker(ScrollJs.class).scrollTo(320);Notes
warn is what makes the migration tractable — it turns "somewhere in this application something uses eval" into a list. It is also the reason the mode is one setting with three values rather than a boolean: the middle state is where applications and add-ons will spend their time.
Update 25 Nov 2026: some names in this text changed during the work. The setting is now contentSecurityPolicy and @JsInvoker is @JsDefinition. The text is kept as written; see the comments for the current names and decisions.
Staging: off and warn together with the declared-JavaScript mechanism and Flow's own migration in 25.4. strict is announced as supported only once the core components are migrated and the violation test is green.
Requirements
- A
cspmode setting (off|warn|strict), configured like other Vaadin settings (init parameter / Spring property), defaulting tooff. - Declared JavaScript at element level:
@JsInvokerinterfaces whose@JsExpressionmethods the build collects into the bundle; an invocation names the interface and method instead of carrying a script (feat: run declared JavaScript without compiling it in the browser flow#25749). - The same at page level, for JavaScript with no element behind it (feat: run page level declared JavaScript without compiling it in the browser flow#25799).
- CSP-safe replacements for the remaining eval paths in the client engine: server-sent JS functions, DOM event data expressions, DOM event filters, and on-demand chunk loading.
- Flow's own server-initiated JavaScript goes through the declared mechanism. (
Focusable.focus()/blur()done in feat: run declared JavaScript without compiling it in the browser flow#25749.) - Vaadin components work in
strictmode, including their connectors — which means a connector declares its JavaScript as a module instead of publishing itself aswindow.Vaadin.Flow.*(Allow @JsDefinition to target a @JsModule flow#25814). Update 25 Nov 2026: the components run their integration tests instrictmode by default (chore: make strict CSP mode the default flow-components#10808). The connector part (Allow @JsDefinition to target a @JsModule flow#25814) is open. Update 2 Dec 2026: Allow @JsDefinition to target a @JsModule flow#25814 is closed.JsModuleInvokersandPage.executeModuleJscall the exports of a module (feat: add JsModuleInvokers and Page.executeModuleJs flow#27492). -
warnmode logs each call thatstrictwould reject, naming the API and the application call site, with no change in behaviour — and works in development mode, where the code is written. -
strictmode generates a per-response nonce, sends the header, and puts the nonce on every script Vaadin adds, with noIndexHtmlRequestListenerrequired from the application. A hook lets the application add or override directives it needs for its own resources (connect-src,img-src,report-uri, …). -
strictmode throws on the APIs that cannot work —Element.executeJs,Page.executeJs,DomListenerRegistration.setFilter(String), string-based event data — so the failure happens in Java, at the call, not as a console error. -
strictin development mode applies the API restrictions but does not send the header, since the dev server and dev tools needunsafe-eval. Violations surface during development; the policy is enforced in production. - The platform component test (
vaadin-platform-test,ComponentsView/ComponentsITat/prod-mode/) also runs instrictmode and fails on any CSP violation the browser reports. Update 25 Nov 2026: in progress in test: run integration tests in strict CSP mode #9910, which waits for feat: use JsDefinition interfaces instead of JavaScript strings collaboration-kit#165. Update 2 Dec 2026: merged in test: run integration tests in strict CSP mode #9910. - Documentation: the current article's
Function/evaloverriding recipe is replaced by the setting, the declared-JavaScript API, and a migration guide for applications and add-ons. Update 25 Nov 2026: the setting and the built-instrictmode are documented. The recipe is kept for applications that a preview limitation affects. The migration guide is not written. Update 2 Dec 2026: the migration guide is a draft in docs: add a guide for migrating to a strict CSP docs#6789. - Spring Security integration: mix policies or just document header overrides (Integrate the strict csp mode with Spring Security CSP headers flow#26688) Update 25 Nov 2026: header overrides are documented. Mixing policies is not done. Update 2 Dec 2026: done in feat: use Spring Security nonce for strict Content Security Policy flow#27471, also in 25.4. With a policy in Spring Security, Vaadin uses its nonce and sends no policy of its own. Documentation in docs: describe strict Content Security Policy with Spring Security docs#6808.
- Added 25 Nov 2026: an application can declare fallbacks for the JavaScript strings of add-ons that are not migrated yet (
@JsStringFallback, Allow declaring JavaScript expressions for string-based executeJs calls made by add-ons flow#26153).
Nice-to-haves
-
style-srclocked down as well, which needs the components to nonce or adopt the stylesheets they inject at runtime (Enable using nonce style-src based CSP with components web-components#8031). -
@JsInvokerergonomics: typed return values (Support typed return values from @JsDefinition methods flow#25811) and an implicitthis.method()shorthand (Call instance method for @JsDefinition methods without a @JsExpression annotation flow#25812). -
@JsInvokercode split per chunk the way@JsModuleimports are (Split @JsDefinition code in the JS bundle using the same logic as @JsModule splitting flow#25810). -
Content-Security-Policy-Report-Onlyin csp warn mode (flow/issues#26696). Update 2 Dec 2026: draft in feat: send report-only Content Security Policy in csp warn mode flow#27612.
Risks, limitations and breaking changes
Risks
- The migration surface is the whole framework plus the component set (~170 call sites). A partially migrated
strictlooks like a broken framework rather than an unfinished migration — which is whywarnand the violation test are requirements, not follow-ups. warnonly sees calls that actually execute, so a code path no one exercises stays unreported. It lowers the cost of migration; it does not prove completeness.- Add-ons and hand-written application JavaScript are outside Vaadin's control, so
strictstays out of reach for some applications until those migrate.
Limitations
- In
strictmode the header is sent in production mode only. - Charts passes string-defined JavaScript functions to the client (
_fn_formatter,_fn_positioner, …) where they are evaluated, and the Spreadsheet client callsevalduring its GWT bootstrap. Neither is usable instrictmode until reworked; both are tracked separately from this PRD. - Update 25 Nov 2026: the Charts and Spreadsheet integration tests now run in
strictmode. A chart function declared as aChartFunctionworks; a function set as a string still does not. AChartFunctionis not applied in server-side export withSVGGenerator, andChartAIControllerdoes not keep it (ChartAIController state should keep ChartFunction values flow-components#10803). - Added 25 Nov 2026: add-on fallbacks match fixed JavaScript strings only. An add-on that builds its JavaScript by concatenating values has to be fixed in the add-on.
Breaking changes
- None by default:
offis today's behaviour. - In
strictmode,executeJsand string-based event filters and event data throw. This is the point of the mode, and it is opt-in. - From feat: run declared JavaScript without compiling it in the browser flow#25749:
Focusable.focus()/blur()no longer schedule a script string, so code or tests that read the scheduled JavaScript must read the invoker call instead; and every application's bundle is rebuilt once.
Out of scope
- Trusted Types, and CSP directives unrelated to script execution beyond the application hook.
- A policy for the development server and dev tools.
- Migrating third-party add-ons.
- Hash-based policies and subresource integrity as an alternative to nonces.
Materials
- Enable invoking JS from the server in a way that is compatible with CSP and avoids XSS flow#10759 — the original design for declaring invokable JavaScript in Java
- feat: run declared JavaScript without compiling it in the browser flow#25749, feat: run page level declared JavaScript without compiling it in the browser flow#25799 — element-level and page-level implementation
- Allow @JsDefinition to target a @JsModule flow#25814 — connectors as JS modules instead of
window.Vaadin.Flow.* - Support executeJs decomposition through passing an JS function to executeJs flow#24373, Let the application handle JS expression evaluation flow#10810 — earlier attempts at the same problem
- Make Dashboard compatible with strict csp flow-components#7935, Make it possible to use Push with strict CSP mode flow#20329 — individual CSP fixes already done
- Current documentation:
flow/security/advanced-topics/strict-csp, and the reference application atvaadin/flow-crm-tutorial@24.5-strict-csp
Metrics
- A new application using the standard components can set
strictand run with zero CSP violations, without writing any JavaScript or anIndexHtmlRequestListener. - Enabling
warnon an existing application produces the complete list of what blocksstrict, each entry pointing at a Java call site. - The documentation article is the setting plus a migration guide — no overriding of
Functionoreval.
Pre-implementation checklist
- Estimated (estimate entered into Estimate custom field)
- Product Manager sign-off
- Engineering Manager sign-off
Pre-release checklist
- Documented (link to documentation provided in sub-issue or comment)
- UX/DX tests conducted and blockers addressed
- Approved for release by Product Manager
Security review
Security audit conducted
Metadata
Metadata
Assignees
Type
Projects
- StatusShow more project fieldsDecember 2026 (25.4)
- StatusShow more project fieldsNext Release
Activity
totally-not-ai commentedon Sep 19, 2026
One requirement above — "the platform component test also runs in
strictmode and fails on any CSP violation" — covers the components but says nothing about how Flow's own suite guards the migration. Proposal for that, to be tuned before sub-issues are created.Running every Flow test in
strictmode is not the right target:strictforbids.Element.executeJs,DomListenerRegistration.setFilter(String)and string-based event data stay supported public API inoffmode, and there are integration tests whose purpose is to exercise them. Instrictthey throw by design, so those must keep running inoff.unsafe-eval. Running them instrictwould only exercise the Java-side rejection, not the violation the browser reports — which is the failure being guarded against. That signal only exists in production-mode suites.Three layers instead, cheapest first:
new Function. Seconds per push, no browser, and this is what stops a newly addedexecuteJsfrom silently undoing the migration.warn, failing the build on an unexpected warning, with an allowlist for the tests that use those APIs on purpose. Near-complete coverage of the API-level problem at almost no CI cost, andwarnis the mode that can be enabled globally wherestrictcannot.securitypolicyviolationlistener reports; plus astrictvariant of one broad existing suite, reusing the same test sources under a second pom, the waytest-themes/pom-production.xmlandtest-router-custom-context-encoded-prodalready do.[-]Content Security Policy support: off, warn and strict modes[/-][+]Enabling Content Security Policy[/+]Legioth commentedon Sep 24, 2026
One additional "feature request": Add support for an application-wide "fallback definition" class that can carry
@JsExpressionannotations for add-on invocations that are passed as a string. These expressions get included in the bundle and the runtime checks anyexecuteJs(string)invocation against that list to avoid warning or raising errors due to those specific cases.mshabarov commentedon Oct 8, 2026
Some side cases that we may want to take into account. These we observed in 24.5 when we shipped CSP workarounds:
Risks
Minor
mshabarov commentedon Oct 26, 2026
Strict CSP: plan to beta
Goal for beta: all API in place and frozen. A Flow demo app runs in production mode with
csp=strictand zero CSP violations.Timeline, honestly: 3 weeks only if API decisions are made in the first 2 days and nothing needs a second round. Realistic estimate: 3–4 weeks. If 3 weeks is not enough, the items under "If we fall behind" move out first.
What changes, and where
flownew Function;@JsModule.warnmode logging the call site; string-based APIs throw instrict;@JsParams,@JsInvokeron@JsModule, typed return values,this.method()without@JsExpression;executeJs;cspproperty.strictintegration test module.flow-componentsexecuteJs→@JsInvokerin Grid, ComboBox, Dialog, Notification, Upload, DatePicker, Checkbox, Tabs, MenuBar and their connectors (~37 calls).LitRenderercolumns are not part of the MVP.platformComponentsITin strict in CI, non-blocking for now.docscspsetting,@JsInvoker, JsSnippet, what is not supported yet.Demo app: new repository.
Plan
Week 1
strictbehaviour;@JsModule;this.method().warn/strict;Week 2
strict/warn, JsSnippet;@JsModule;this.method().strictintegration test module, platform run.Week 3
strictmarked as "preview".Week 4 (buffer, realistic case)
@JsModuleand Grid.After beta
LitRendererin Grid and ComboBox via JsSnippet.@JsModule.warnin dev-mode tests. Platform test made blocking.style-srcwithout'unsafe-inline', splitting declared JS per chunk.If we fall behind
this.method()to the next minor. They only add API and break nothing.Risks
mcollovati commentedon Oct 26, 2026
Note on names:
@JsInvokerandgetJsInvoker(...)in the description are names from the review of vaadin/flow#25749. They were renamed before the merge, so they were never released. The names in Flow are:@JsInvoker→@JsDefinition(com.vaadin.flow.js.JsDefinition), together with@JsExpressionelement.getJsInvoker(X.class)→element.executeJs(X.class)page.getJsInvoker(X.class)→page.executeJs(X.class)The example in the description is now:
The Flow issues vaadin/flow#25810, vaadin/flow#25811, vaadin/flow#25812, vaadin/flow#25814, vaadin/flow#25837 and the epic vaadin/flow#26155 now use the new names.
docs: present strict CSP mode as a preview (#6687)
heruan commentedon Nov 25, 2026
Status and decisions, 25 Nov 2026
The description is kept as written. I only added dated notes to it. This comment records what changed since the plan above.
Decisions
contentSecurityPolicy(vaadin.contentSecurityPolicy), withContentSecurityPolicyModeandContentSecurityPolicyViolationException(refactor!: spell out ContentSecurityPolicy in CSP API names flow#27176).vaadin.cspfrom earlier 25.4 pre-releases is ignored.@JsStringFallback, feat: let applications declare CSP fallbacks for add-on string JavaScript flow#27128). JavaScript built by concatenation is a known limitation and has to be fixed in the add-on.strictmode by default (chore: make strict CSP mode the default flow-components#10808).setFilter(String)leaves the listener without a filter) is closed as not planned. It is an application bug.Open requirements
Questions
@JsDefinitiontypes with the bundle scanner whenoptimizeBundleis on flow#27022 (only reachable definitions in the bundle) a goal for the 25.4 RC?test: add strict CSP integration test module (vaadin#26734)
test(csp-strict): enable browser tests (vaadin#26975)
test(csp-strict): add push and lazy chunk scenarios (vaadin#26976)
test(csp-strict): add embedded web component scenario (vaadin#26997)
feat: use Spring Security nonce for strict Content Security Policy (#…
docs: describe strict Content Security Policy with Spring Security (#…
heruan commentedon Dec 2, 2026
Status, 2 Dec 2026
This replaces the open points of the status of 25 Nov.
Done since then
VaadinSecurityConfigurer.contentSecurityPolicy()configures the default policy there. Integrate the strict csp mode with Spring Security CSP headers flow#26688 is closed. Documented in docs: describe strict Content Security Policy with Spring Security docs#6808.strictmode: test: run integration tests in strict CSP mode #9910 is merged.@JsDefinitionImport,JsModuleInvokers).@JsDefinitiontypes with the bundle scanner whenoptimizeBundleis on flow#27022 is closed.Open
warnmode: Send the policy as Content-Security-Policy-Report-Only in csp warn mode flow#26696, draft in feat: send report-only Content Security Policy in csp warn mode flow#27612.Question
mcollovati commentedon Dec 2, 2026
For components there's a draft PR that needs a review from the DS team to make sure changes in frontend files are not breaking anything.