spring-projects / spring-projects/spring-security
overload CsrfConfigurer.spa() to take a custom CsrfTokenRepository-object as argument
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 9.6k
- Forks
- 6.3k
- Avg merge
- 2d 11h
- Merged PRs (30d)
- 52
Description
Expected Behavior
I can configure a custom CookieCsrfTokenRepository and use it in the spa()-configurationMethod:
CookieCsrfTokenRepository customCookieRepo = CookieCsrfTokenRepository.withHttpOnlyFalse();
customCookieRepo .setCookieName( customCookieName );
customCookieRepo .setHeaderName( customHeaderName );
http.csrf(csrf -> csrf.spa( customCookieRepo ));
Goal: to have a little more convenience and a more intuitive configuration.
Current Behavior
http.csrf(csrf -> csrf.spa());
was introduced with the new version - short and elegant, but it lacks the possibility to configure the CookieCsrfTokenRepository with a custom cookieName etc.,
Context
I need to configure a custom cookieName (our reverse proxy in the infrastructure requires each application to use a unique cookieName), which made me -after some investigation - add an additional line:
http.csrf(csrf -> csrf.spa());
csrf.csrfTokenRepository( customCookieRepo ))
I am not sure, if this was the intended solution for this case ?
Of course, that’s not a big problem, but it’s not very pretty either, and in my opinion, it’s certainly not intuitive.
The biggest issue here is that it’s not intuitive, and it takes time to understand how spa() works and how you can still set the CsrfTokenRepository.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at CsrfConfigurer.spa() and the CookieCsrfTokenRepository usage described in the issue, then inspect the surrounding CSRF configuration tests. Done means spa() accepts a custom CsrfTokenRepository while preserving the existing no-argument behavior and allows custom cookie and header names to be used.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, spring
- Domain
- security
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Clearly specified
- Newbie friendliness
- 62/100