Repository navigation
Conversation
Preview DeploymentThis PR has been deployed for preview. URL: https://docs-preview-pr-6808.fly.dev Changed pagesAdded content is highlighted in green; removed content is marked in red on each page.
Built from 57db756 |
vaadin-review-bot
left a comment
There was a problem hiding this comment.
Reviewed the changes — left 5 comments.
| Finding | |
|---|---|
| The development-mode paragraph now contradicts the new Spring Security section | |
| The IndexHtmlRequestListener instructions above are now wrong for a Spring Security policy, and only the Spring Security section says so | |
| 🧩 | The request matcher example silently produces the unprotected case that the section warns about |
| 💬 | The requirement to set the parameter to strict comes after all three examples |
| The new behavior is stated without the version badge that the section it links to carries |
There was a problem hiding this comment.
Around line 141 — could not attach to the exact diff line.
Line 141 still says: "In development mode, no Content-Security-Policy header is sent and no nonce is added to the page, because the development server and the development tools need eval."
The new section says the opposite for a Spring Security application (line 232: "Spring Security sends the policy in development mode too, and Vaadin puts the nonce on the scripts there as well"), and line 234 says the development tools and Copilot work under that policy. A reader of a Spring Boot application — the common case — meets the general claim first and its stated reason, and will not expect the policy in development mode.
Suggestion: qualify line 141, for example "Vaadin itself sends the policy only in production mode. In development mode, Vaadin sends no Content-Security-Policy header and adds no nonce to the page, unless Spring Security sends a policy, see <<#spring-security,Spring Security>>."
content-security-policy.adoc:141 · accuracy
There was a problem hiding this comment.
Qualified the sentence and linked to the section.
There was a problem hiding this comment.
Around line 158 — could not attach to the exact diff line.
Line 150 instructs: "To allow a resource that the default policy doesn't ... add an [interfacename]IndexHtmlRequestListener and add sources to the [classname]ContentSecurityPolicy of the response", and the examples carry the comment // null unless contentSecurityPolicy is strict.
With the change, the policy is also null in strict mode when Spring Security sends the policy, as line 218 states. A reader of a Spring Boot application who copies the listener from this section gets a listener that silently does nothing, and the comment tells them that cannot happen.
Suggestion: amend the comment to // null unless contentSecurityPolicy is strict and Vaadin sends the policy, and point from this section to <<#spring-security,Spring Security>>.
content-security-policy.adoc:158 · accuracy
There was a problem hiding this comment.
Changed the comment in the example and added a pointer to the section.
| [source,java] | ||
| ---- | ||
| http.with(vaadin(), vaadin -> vaadin.contentSecurityPolicy(policy -> { | ||
| }, config -> config.requestMatchers("/app/**"))); |
There was a problem hiding this comment.
🧩 The request matcher example silently produces the unprotected case that the section warns about
The example restricts the policy to /app/**:
http.with(vaadin(), vaadin -> vaadin.contentSecurityPolicy(policy -> {
}, config -> config.requestMatchers("/app/**")));The table below lists "A policy with a request matcher that doesn't match the request" as a case where the page is sent without any policy, and line 260 says nothing is logged. A reader with routes at / who copies this loses the policy on every bootstrap page with no sign of it.
Add one sentence to the example, such as: "The matcher must cover the routes of the application; a bootstrap page outside it is sent without a policy."
content-security-policy.adoc:225 · examples
There was a problem hiding this comment.
Added a sentence after the example.
|
|
||
| Calling [methodname]`contentSecurityPolicy()` on [classname]`VaadinSecurityConfigurer` replaces a policy that the same filter chain configures with [methodname]`HttpSecurity.headers()`. If the application has disabled the headers of Spring Security for the filter chain, only the `Content-Security-Policy` header is added. | ||
|
|
||
| Use it together with the `strict` value of the `contentSecurityPolicy` parameter. With `off` or `warn`, the bootstrap page loads, but the browser blocks the JavaScript that the server sends as strings, such as the expression of [methodname]`executeJs()`. |
There was a problem hiding this comment.
💬 The requirement to set the parameter to strict comes after all three examples
"Use it together with the strict value of the contentSecurityPolicy parameter. With off or warn, the bootstrap page loads, but the browser blocks the JavaScript that the server sends as strings" appears three examples after the configuration it applies to.
A reader who arrives through the link on line 177 and copies the first example without setting vaadin.contentSecurityPolicy=strict ships an application whose string JavaScript, such as executeJs(), is blocked in the browser. Move this requirement before the first example, or into the paragraph that introduces it.
content-security-policy.adoc:230 · clarity
There was a problem hiding this comment.
Moved before the first example.
| Leave `script-src` unchanged: it holds the nonce and `'strict-dynamic'`, so replacing it blocks every script on the page, and host sources added to it are ignored by the browser. To load a script from another origin instead, add a `<script>` element to the document, which gets the nonce automatically. | ||
|
|
||
| Setting the `Content-Security-Policy` header another way, such as from a servlet filter that runs before Vaadin or the listener in <<#creating-random-nonce,Creating Random Nonce>>, isn't compatible with this: in production mode, the request fails if the header is already set when the page is written, so that the page is never sent without Vaadin's own policy. A policy configured in Spring Security doesn't fail the request. See <<#spring-security,Spring Security>> for how the two policies work together. | ||
| Setting the `Content-Security-Policy` header another way, such as from a servlet filter that runs before Vaadin or the listener in <<#creating-random-nonce,Creating Random Nonce>>, isn't compatible with this. In production mode, the request fails if the header is already set when the page is written. This way, the page is never sent without Vaadin's own policy. A policy configured in Spring Security is the exception: Vaadin then uses the nonce of that policy and sends no policy of its own. See <<#spring-security,Spring Security>>. |
There was a problem hiding this comment.
"A policy configured in Spring Security is the exception: Vaadin then uses the nonce of that policy and sends no policy of its own."
The section this sentence links to is badged since:com.vaadin:vaadin@V25.5, and pom.xml pins 25.4.0-beta4. A reader on 25.4 takes this sentence as current behavior, while in 25.4 the bootstrap page carries only the policy of Vaadin. Badge the clause the same way, for example [since:com.vaadin:vaadin@V25.5]#A policy configured in Spring Security is the exception: ...#.
content-security-policy.adoc:177 · accuracy
There was a problem hiding this comment.
Added the badge to the sentence.
…ity-nonce # Conflicts: # articles/flow/security/protections/content-security-policy.adoc
mcollovati
left a comment
There was a problem hiding this comment.
The Flow PR is merged and cherry-picked to 25.4, so this can go in once the comments are addressed. A few pages outside this PR need an update for the Spring Security case:
Map page (articles/components/map/index.adoc, "Content Security Policy" section, added in #6807)
The section tells the reader to add the map service origins in an IndexHtmlRequestListener (line 621), with the comment // null unless contentSecurityPolicy is strict (line 629). When Spring Security sends the policy, getContentSecurityPolicy() returns null. The listener then silently does nothing, and the map shows no background in production. Line 641 ("Vaadin sends the policy only in production mode") doesn't hold either, since Spring Security sends the policy in development mode too.
Please add the Spring Security variant, with a link to <<{articles}/flow/security/protections/content-security-policy#spring-security,Spring Security>>:
http.with(vaadin(), vaadin -> vaadin.contentSecurityPolicy(policy -> policy
.addSources("img-src", "https://maps.example.com")
.addSources("img-src", "https://*.tile.openstreetmap.org")));The comment in the listener example should also match the one on the CSP page: // null unless contentSecurityPolicy is strict and Vaadin sends the policy.
Security Configuration (articles/flow/security/spring/security-configuration.adoc)
This page lists the methods of VaadinSecurityConfigurer under "Configuration Methods", but not the new contentSecurityPolicy() overloads. The documentation bot's PR for the same Flow change, #6821, already has a "Content Security Policy Configuration" subsection for them, before "Request Matchers". Please take it over into this PR, and we close #6821 as a duplicate. Its changes to the CSP page overlap with this PR and would conflict with it. The subsection needs a few changes:
- Add
[role="since:com.vaadin:vaadin@V25.4"]above the heading, since nothing else on the page marks the methods as new. - Use
[methodname]forHttpSecurity.headers(), like the rest of the page. - Also list
HeadersConfigurerunder "Applied Configurers", since the configurer applies it whencontentSecurityPolicy()is called.
Configuration Properties (articles/flow/configuration/properties.adoc, line 141)
With
strict, Vaadin sends a nonce-basedContent-Security-Policyheader in production mode
This isn't true when Spring Security sends the policy. Something like "…in production mode, unless Spring Security sends the policy" would do.
| Set the parameter to `warn` to log every call in the application that wouldn't work under such a policy. Each log entry is a [classname]`ContentSecurityPolicyViolationException`, whose stack trace leads to the code that made the call. | ||
|
|
||
| Set the parameter to `strict` to have Vaadin send the policy. Vaadin sends it only in production mode. In development mode, no `Content-Security-Policy` header is sent and no nonce is added to the page, because the development server and the development tools need `eval`. An API that sends JavaScript to the browser as a string, such as [methodname]`executeJs()` with a string expression, throws a [classname]`ContentSecurityPolicyViolationException` in both production and development mode. However, the browser doesn't block anything the policy wouldn't allow, such as a request to an external API or an image from another origin, until the application runs as a production build. Test a production build of the application under the policy before you rely on it. | ||
| Set the parameter to `strict` to have Vaadin send the policy. Vaadin sends it only in production mode. In development mode, Vaadin sends no `Content-Security-Policy` header and adds no nonce to the page, unless Spring Security sends a policy. See <<#spring-security,Spring Security>>. An API that sends JavaScript to the browser as a string, such as [methodname]`executeJs()` with a string expression, throws a [classname]`ContentSecurityPolicyViolationException` in both production and development mode. However, the browser doesn't block anything the policy wouldn't allow, such as a request to an external API or an image from another origin, until the application runs as a production build. Test a production build of the application under the policy before you rely on it. |
There was a problem hiding this comment.
In development mode, Vaadin sends no
Content-Security-Policyheader and adds no nonce to the page, unless Spring Security sends a policy.
The "unless" applies to both parts of the sentence, so it reads as if Vaadin sends a header in development mode when Spring Security has a policy. Vaadin never sends one in that case. It only puts the nonce of Spring Security on the scripts. Maybe split it:
| Set the parameter to `strict` to have Vaadin send the policy. Vaadin sends it only in production mode. In development mode, Vaadin sends no `Content-Security-Policy` header and adds no nonce to the page, unless Spring Security sends a policy. See <<#spring-security,Spring Security>>. An API that sends JavaScript to the browser as a string, such as [methodname]`executeJs()` with a string expression, throws a [classname]`ContentSecurityPolicyViolationException` in both production and development mode. However, the browser doesn't block anything the policy wouldn't allow, such as a request to an external API or an image from another origin, until the application runs as a production build. Test a production build of the application under the policy before you rely on it. | |
| Set the parameter to `strict` to have Vaadin send the policy. Vaadin sends it only in production mode. In development mode, Vaadin sends no `Content-Security-Policy` header. It adds no nonce to the page either, unless Spring Security sends a policy. See <<#spring-security,Spring Security>>. An API that sends JavaScript to the browser as a string, such as [methodname]`executeJs()` with a string expression, throws a [classname]`ContentSecurityPolicyViolationException` in both production and development mode. However, the browser doesn't block anything the policy wouldn't allow, such as a request to an external API or an image from another origin, until the application runs as a production build. Test a production build of the application under the policy before you rely on it. |
|
|
||
| An application that already has a policy in Spring Security keeps it unchanged when the `contentSecurityPolicy` parameter is set to `strict`. Check that the policy has the `{nonce}` placeholder in `script-src`, and neither `'unsafe-inline'` nor `'unsafe-eval'` there. | ||
|
|
||
| A filter chain without a policy isn't affected: Vaadin sends its own policy for the bootstrap pages that it serves. An application can have the policy of Vaadin on the Vaadin pages and another policy elsewhere. Use two filter chains for that, and configure a policy only in the one that doesn't serve Vaadin pages. |
There was a problem hiding this comment.
| A filter chain without a policy isn't affected: Vaadin sends its own policy for the bootstrap pages that it serves. An application can have the policy of Vaadin on the Vaadin pages and another policy elsewhere. Use two filter chains for that, and configure a policy only in the one that doesn't serve Vaadin pages. | |
| A filter chain without a policy isn't affected: Vaadin sends its own policy for the bootstrap pages that it serves. An application can have the policy of Vaadin on the Vaadin pages and another policy elsewhere. Use two filter chains for that, and configure a policy only in the one that doesn't serve Vaadin pages. See <<{articles}/flow/security/spring/security-configuration#multiple-filter-chains,Multiple Filter Chains>> for how to set them up. |
The feature ships in 25.4, so the badges say so. The Map, Security Configuration and Configuration Properties pages now cover the case where Spring Security sends the policy.
|
All done in 0d14c2b.
#6821 can be closed as a duplicate. |
Part of vaadin/platform#9488
Depends on vaadin/flow#27471
This PR rewrites the "Spring Security" section of the Content Security Policy page for the behavior of vaadin/flow#27471: the policy is configured in Spring Security, and Vaadin uses its nonce and sends no policy of its own.
VaadinSecurityConfigurer.contentSecurityPolicy(): the default call, changing the policy, and setting the other Spring Security options for itHttpSecurity.headers(), and adds only the policy header when the headers are disabledstrictmode; withofforwarnthe page loads, but JavaScript sent as strings is blocked{nonce}placeholder written withHttpSecurity.headers()strictis turned onNotes for the reviewer:
sincebadge for 25.5, which is the version of Flowmaintoday. It needs a change if the Flow PR is also released in another version.