Repository navigation
docs: add a guide for migrating to a strict CSP - #6789
totally-not-ai[bot] wants to merge 15 commits into
Conversation
Document @JsStringFallback, which lets an application declare the exact JavaScript strings an add-on sends so they run from the bundle instead of being refused under the built-in strict Content Security Policy. Updates the Content Security Policy page. Documents vaadin/flow#27128 (`60ebba0e1cd03b876938f40b306bf74f1e48aad9`).
Show the add-on call next to the fallback that matches it, for executeJs, JsFunction.of, listener filters and event data, and list the limitations of fallbacks as bullets, with a code example for a string that joins a value into the JavaScript.
Shows how applications find the calls that don't work under the strict Content Security Policy mode with the warn mode, what to replace each string-based JavaScript API with, how to handle add-ons and external resources, and what add-on maintainers need to change.
Preview DeploymentThis PR has been deployed for preview. URL: https://docs-preview-pr-6789.fly.dev Changed pagesAdded content is highlighted in green; removed content is marked in red on each page.
Built from 53be17d |
|
@totally-not-ai update the content based on the latest changes in the Flow repository |
|
@mcollovati I updated the guide for the Flow changes merged into 25.4 since it was written:
The Spring Security header fix doesn't change what the guide says: the bootstrap page still carries only the policy Vaadin sends. The new section links to Importing Module Exports, which is on |
|
I followed the guide step by step on an application that was not ready for a strict policy, with one commit per step: The test application:
The guide was read at Result: 29 of 30 features work in a production build under The guide works. Most examples worked as written: Important
Add-on maintainers
Smaller points
Not tested: |
|
@mcollovati Thanks for running the guide end to end. All the points are addressed: Important
Add-on maintainers Smaller points
|
Summary
Adds a how-to guide under Building Apps > Security for moving an application or an add-on to the strict, nonce-based Content Security Policy mode (
contentSecurityPolicy=strict). It starts from thewarnmode, which logs every call that wouldn't work under the policy, and walks through fixing them.The Spring Security paragraph describes the behavior of vaadin/flow#27471 (also in 25.4); the reference section it links to is updated for that behavior in #6808 / #6821, so merge one of those together with this PR.
What changed
building-apps/security/strict-content-security-policy.adoc(marked as a preview, like the strict mode itself):warn: what is logged, the stack traces that have only framework frames (Lit renderers, chart options, shortcut locators), compiler deprecation warnings as a second list, editing the suggested declarations, strings with changing ids that aren't flagged, the per-call-site limits, and whatwarncan't find (browser-side blocks).executeJs(String),JsFunction.of(),addJsInitializer(String),addDynamicImport(String),setFilter(String),addEventData(String),LitRenderer.of(String), chart string functions,setShortcutListenOnElement(String),executeJsWhenAttached(), inlineon…handler attributes) to its replacement, with links to the reference. Notes onwithArguments(), and on dynamic imports of server-served URLs that now fail the build.callJsFunction(),@DomEventfilters,@EventData, built-in renderers), and the@Usescaveat for optimized production builds.JsInvokersmethod without@JsExpression, which calls the element function of the same name, and a call that returns a value.CompiledLitTemplate.@JsDefinitionImport, or withJsModuleInvokersandPage.executeModuleJs(Class)when later calls depend on the first one. Turning a global-object connector into named exports, and dropping its@JsModule.${fn}→${functions.fn}.@JsStringFallback, the cases only the maintainers can fix, finding the add-on behind a bundle error, and how an uncovered call fails understrict.frame-src, and the app's own directives), removing otherContent-Security-Policyheaders together with the switch tostrict, the manual nonce/override approach, and Spring Security, where the policy and its sources stay in the Spring Security configuration.strictand testing a production build with the browser console, including blocks that only a web worker's console shows.JsFunctioninstead of a JavaScript string, and testing against a production build.Test summary
main.Follow-ups:
JsModuleInvokerspart to the reference section that docs: document calling JavaScript module exports via Page #6805 adds, once it's merged.CompiledLitTemplateisn't documented on the Grid renderers reference page yet. The guide shows a short example in the meantime.Working on behalf of Mikhail