spring-projects / spring-projects/spring-security

overload CsrfConfigurer.spa() to take a custom CsrfTokenRepository-object as argument

Open
#19,009 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

status: waiting-for-triage type: enhancement
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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.