spring-projects / spring-projects/spring-security

SEC-2655: CsrfFilter could return token as header

Open
#2,874 4 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

type: enhancement type: jira
Dominant language
Java
Stars
9.6k
Forks
6.3k
Avg merge
2d 11h
Merged PRs (30d)
52

Description

stripybadger (Migrated from SEC-2655) said:

The CsrfFilter sets the csrf token as an attribute in the request. This is great if you're using a jsp, as you can then embed the token into your page.

If you're not using a jsp, this is annoying. For example, many webapps now use simple html pages that load javascript, and then make ajax requests. It would be useful therefore if the CsrfFilter could set the token in a header as well. This would enable javascripty clients to extract the value from the header, store it, and then use it in subsequent ajax requests.

I'm aware that I could write an additional filter to achieve this, but it seems like something simple that could usefully be included in CsrfFilter.

Note that prior to https://github.com/spring-projects/spring-security/commit/48283ec0049b4245a8887ffaf89d60416fb12203#diff-21c30055f2a19cf6fb7e1f8116ed07e5L77 it did used to return the token in a header - I'm not clear why though.

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

Locate CsrfFilter and review how it currently places the CSRF token in the request, then compare that behavior with the referenced commit. Check the issue's comment thread for additional context. Done means the filter also exposes the token through a response header while preserving the existing request attribute behavior, with tests covering the change.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, spring
Domain
backend, security
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.