spring-projects / spring-projects/spring-security

RequestCacheConfigurer default request matcher doesn't allow saving POST requests when csrf is enabled

Open
#7,365 5 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

Summary

In a web application with Spring Security 4.2.x, RequestCacheConfigurer configures a default request matcher that doesn't allow saving POST requests when csrf is enabled.

Actual Behavior

When we submit a POST request against a secured endpoint the application redirects to the login page. After successful login the original POST request isn't restored so the invocation fails.

Expected Behavior

The original POST request is restored.

Configuration

I'm relying on Spring Security default configurations for the request cache. The key part is here RequestCacheConfigurer :

	private RequestMatcher createDefaultSavedRequestMatcher(H http) {
                ...
                if (isCsrfEnabled) {
			RequestMatcher getRequests = new AntPathRequestMatcher("/**", "GET");
			matchers.add(0, getRequests);
		}

If csrf is enabled only get requests will be cached.

Is there any security related reason why this matcher isn't supporting POST invocations?

Version

4.2.12

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 in RequestCacheConfigurer, specifically createDefaultSavedRequestMatcher, and inspect how the CSRF-enabled matcher handles POST requests. Reproduce a secured POST followed by login using the default request-cache configuration. Done means the original POST request is restored after successful login.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.