spring-projects / spring-projects/spring-security

Consider CSRF protection with a fixed custom header

Open
#13,717 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

OWASP lists Custom Request Headers in their CSRF cheat sheet, which says "the client appends a custom header to requests that require CSRF protection" and "the API checks for the existence of this header". It can't be used with native <form>s but I think applications that can benefit from it are common enough.

The Spring Security documentation mentions that "there are known exploits in which headers can be set by another domain" when explaining "why the expected CSRF token is not stored in a cookie by default", but it seems that things has changed now. The OWASP cheat sheet doesn't say it is vulnerable, unlike "Naive Double Submit Cookie" which "remains vulnerable to certain attacks".

So it seems that simply checking for the existence of a custom header set by client-side script is safer than what is currently recommended for SPAs? If so it would be nice if Spring Security provide something like httpSecurity.csrf(csrf -> csrf.customHeader("X-YOURSITE-CSRF-PROTECTION")).

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 comparing the OWASP CSRF cheat sheet with Spring Security's CSRF considerations and JavaScript SPA integration documentation cited in the issue. Determine whether checking a fixed custom header is safe and what configuration, documentation, and tests would be needed for a supported API; done means the security behavior and scope are decided.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, spring
Domain
security
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.