-
Notifications
You must be signed in to change notification settings - Fork 6.1k
Closed
Labels
in: webAn issue in web modules (web, webmvc)An issue in web modules (web, webmvc)status: duplicateA duplicate of another issueA duplicate of another issuetype: enhancementA general enhancementA general enhancement
Description
For a SPA, the current recommendation for configuration CSRF is three-fold:
- set the
CsrfTokenRepository
toCsrfTokenRepository#withHttpOnlyFalse
- set the
CsrfAttributeHandler
to a custom class listed in the reference manual - add a custom filter that "subscribes" to the deferred cookie so that the cookie header is written
The current state of the recommendation could be improved in a way that is less error-prone and requires less custom boilerplate for users.
One possibility is to provide a customizer like so:
.csrf(CsrfCustomizers.spaDefaults())
Where said customizer would apply these three rules for them. I imagine this might look something like the following:
public static Customizer<CsrfConfigurer> spaDefaults() {
return (csrf) -> csrf
.csrfTokenRepositorySubscription(CookieCsrfTokenRepository.withHttpOnlyFalse())
.csrfTokenRequestHandler(new SpaCsrfTokenRequestHandler())
)
}
Where csrfTokenRepositorySubscription
is pseudocode for a way to supply the repository and indicate that the filter chain should automatically subscribe to the cookie as part of formulating the response (#3 in the above list) and SpaCsrfTokenRequestHandler
is pseudocode for an implementation that is similar to the sample in the reference guide.
ch4mpy, Toerktumlare, AntonioSoto01, rcrlik, void-spark and 5 more
Metadata
Metadata
Assignees
Labels
in: webAn issue in web modules (web, webmvc)An issue in web modules (web, webmvc)status: duplicateA duplicate of another issueA duplicate of another issuetype: enhancementA general enhancementA general enhancement