From b7ccb63dfd63a0d63ce28cb543246c53d46a8d7b Mon Sep 17 00:00:00 2001 From: Josh Cummings Date: Wed, 30 May 2018 13:15:56 -0600 Subject: [PATCH] Disable CSRF by Request Matcher This introduces an evolution on CsrfConfigurer#ignoreAntMatchers, allowing users to specify a RequestMatcher in the circumstance where more than just the path needs to be analyzed to determine whether CsrfFilter should require a token for the request. Simply put, a user can now selectively disable csrf by request matcher in addition to the way it can already be done with ant matchers. Fixes: gh-5477 --- .../web/configurers/CsrfConfigurer.java | 33 ++++- ...onfigurerIgnoringRequestMatchersTests.java | 127 ++++++++++++++++++ 2 files changed, 158 insertions(+), 2 deletions(-) create mode 100644 config/src/test/java/org/springframework/security/config/annotation/web/configurers/CsrfConfigurerIgnoringRequestMatchersTests.java diff --git a/config/src/main/java/org/springframework/security/config/annotation/web/configurers/CsrfConfigurer.java b/config/src/main/java/org/springframework/security/config/annotation/web/configurers/CsrfConfigurer.java index a1143cc3d5..9529703af6 100644 --- a/config/src/main/java/org/springframework/security/config/annotation/web/configurers/CsrfConfigurer.java +++ b/config/src/main/java/org/springframework/security/config/annotation/web/configurers/CsrfConfigurer.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2013 the original author or authors. + * Copyright 2002-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -128,7 +128,7 @@ public final class CsrfConfigurer> *

* *

- * The following will ensure CSRF protection ignores: + * For example, the following configuration will ensure CSRF protection ignores: *

*