spring-projects / spring-projects/spring-security

remember me, csrf, ajax

Open
#4,060 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

status: waiting-for-triage
Dominant language
Java
Stars
9.6k
Forks
6.3k
Avg merge
2d 11h
Merged PRs (30d)
52

Description

If I leave a authorizationed page open as long as the session timeout(use CookieCsrfTokenRepository), and then send two ajax requests on the page to the server, the first request work good, but the second access denied as csrf token is changed when remember me authentication success, how can i make it work on this condition?

I have modify the CsrfAuthenticationStrategy class like this

@Override
  public void onAuthentication(Authentication authentication, HttpServletRequest request,
      HttpServletResponse response) throws SessionAuthenticationException {
    boolean containsToken = this.csrfTokenRepository.loadToken(request) != null;
    // if RememberMeAuthenticationToken do not refresh csrf token
    if (containsToken && !(authentication instanceof RememberMeAuthenticationToken)) {
      this.csrfTokenRepository.saveToken(null, request, response);

      CsrfToken newToken = this.csrfTokenRepository.generateToken(request);
      this.csrfTokenRepository.saveToken(newToken, request, response);

      request.setAttribute(CsrfToken.class.getName(), newToken);
      request.setAttribute(newToken.getParameterName(), newToken);
    }
  }

and it works good

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 by reading CsrfAuthenticationStrategy and the interaction between CookieCsrfTokenRepository and RememberMeAuthenticationToken during authentication. Reproduce the two AJAX requests after the session timeout, then verify that remember-me authentication does not cause the second request to be rejected while CSRF protection remains effective.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, spring
Domain
authentication, security
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.