Skip to content

Commit 4e61136

Browse files
committed
Enable CSRF protection by default
See gh-11758
1 parent 85f45ad commit 4e61136

File tree

3 files changed

+10
-3
lines changed

3 files changed

+10
-3
lines changed

spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/SecurityProperties.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,7 @@ public class SecurityProperties implements SecurityPrerequisite {
7575
/**
7676
* Enable Cross Site Request Forgery support.
7777
*/
78-
// Flip this when session creation is disabled by default
79-
private boolean enableCsrf = false;
78+
private boolean enableCsrf = true;
8079

8180
private Basic basic = new Basic();
8281

spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/security/SecurityPropertiesTests.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,4 +122,12 @@ public void testRole() {
122122
assertThat(this.security.getUser().getRole().toString()).isEqualTo("[ADMIN]");
123123
}
124124

125+
@Test
126+
public void testCSrf() {
127+
assertThat(this.security.isEnableCsrf()).isEqualTo(true);
128+
this.binder.bind(new MutablePropertyValues(
129+
Collections.singletonMap("security.enable-csrf", false)));
130+
assertThat(this.security.isEnableCsrf()).isEqualTo(false);
131+
}
132+
125133
}

spring-boot-docs/src/main/asciidoc/appendix-application-properties.adoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -447,7 +447,7 @@ content into your application; rather pick only the properties that you need.
447447
security.basic.enabled=true # Enable basic authentication.
448448
security.basic.path=/** # Comma-separated list of paths to secure.
449449
security.basic.realm=Spring # HTTP basic realm name.
450-
security.enable-csrf=false # Enable Cross Site Request Forgery support.
450+
security.enable-csrf=true # Enable Cross Site Request Forgery support.
451451
security.filter-order=0 # Security filter chain order.
452452
security.filter-dispatcher-types=ASYNC, FORWARD, INCLUDE, REQUEST # Security filter chain dispatcher types.
453453
security.headers.cache=true # Enable cache control HTTP headers.

0 commit comments

Comments
 (0)