Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in / Register
Toggle navigation
S
spring-boot
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
DEMO
spring-boot
Commits
51de220b
Commit
51de220b
authored
Feb 16, 2018
by
Madhura Bhave
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Enable CSRF protection by default
Fixes gh-11758
parent
c5f4f45f
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
26 additions
and
8 deletions
+26
-8
SpringBootWebSecurityConfiguration.java
.../security/servlet/SpringBootWebSecurityConfiguration.java
+0
-7
spring-boot-features.adoc
...ing-boot-docs/src/main/asciidoc/spring-boot-features.adoc
+10
-0
ShutdownSampleActuatorApplicationTests.java
...mple/actuator/ShutdownSampleActuatorApplicationTests.java
+16
-1
No files found.
spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/servlet/SpringBootWebSecurityConfiguration.java
View file @
51de220b
...
@@ -23,7 +23,6 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplicat
...
@@ -23,7 +23,6 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplicat
import
org.springframework.boot.autoconfigure.security.SecurityProperties
;
import
org.springframework.boot.autoconfigure.security.SecurityProperties
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.core.annotation.Order
;
import
org.springframework.core.annotation.Order
;
import
org.springframework.security.config.annotation.web.builders.HttpSecurity
;
import
org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter
;
import
org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter
;
/**
/**
...
@@ -45,12 +44,6 @@ public class SpringBootWebSecurityConfiguration {
...
@@ -45,12 +44,6 @@ public class SpringBootWebSecurityConfiguration {
@Order
(
SecurityProperties
.
BASIC_AUTH_ORDER
)
@Order
(
SecurityProperties
.
BASIC_AUTH_ORDER
)
static
class
DefaultConfigurerAdapter
extends
WebSecurityConfigurerAdapter
{
static
class
DefaultConfigurerAdapter
extends
WebSecurityConfigurerAdapter
{
@Override
protected
void
configure
(
HttpSecurity
http
)
throws
Exception
{
super
.
configure
(
http
);
http
.
csrf
().
disable
();
}
}
}
}
}
spring-boot-project/spring-boot-docs/src/main/asciidoc/spring-boot-features.adoc
View file @
51de220b
...
@@ -3155,7 +3155,17 @@ NOTE: Before setting the `management.endpoints.web.exposure.include`, ensure tha
...
@@ -3155,7 +3155,17 @@ NOTE: Before setting the `management.endpoints.web.exposure.include`, ensure tha
exposed actuators do not contain sensitive information and/or are secured by placing them
exposed actuators do not contain sensitive information and/or are secured by placing them
behind a firewall or by something like Spring Security.
behind a firewall or by something like Spring Security.
==== Cross Site Request Forgery Protection
Since Spring Boot relies on Spring Security's defaults, CSRF protection is turned on by default.
This means that the actuator endpoints that require a `POST` (shutdown and loggers endpoints), `PUT`
or `DELETE` will get a 403 forbidden error when the default security configuration is in use.
NOTE: We recommend disabling CSRF protection completely only if you are creating a service that
is used by non-browser clients.
Additional information about CSRF protection can be found in the {spring-security-reference}#csrf[Spring
Security Reference Guide].
[[boot-features-sql]]
[[boot-features-sql]]
== Working with SQL Databases
== Working with SQL Databases
...
...
spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/ShutdownSampleActuatorApplicationTests.java
View file @
51de220b
...
@@ -25,8 +25,11 @@ import org.springframework.beans.factory.annotation.Autowired;
...
@@ -25,8 +25,11 @@ import org.springframework.beans.factory.annotation.Autowired;
import
org.springframework.boot.test.context.SpringBootTest
;
import
org.springframework.boot.test.context.SpringBootTest
;
import
org.springframework.boot.test.context.SpringBootTest.WebEnvironment
;
import
org.springframework.boot.test.context.SpringBootTest.WebEnvironment
;
import
org.springframework.boot.test.web.client.TestRestTemplate
;
import
org.springframework.boot.test.web.client.TestRestTemplate
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.http.HttpStatus
;
import
org.springframework.http.HttpStatus
;
import
org.springframework.http.ResponseEntity
;
import
org.springframework.http.ResponseEntity
;
import
org.springframework.security.config.annotation.web.builders.HttpSecurity
;
import
org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter
;
import
org.springframework.test.annotation.DirtiesContext
;
import
org.springframework.test.annotation.DirtiesContext
;
import
org.springframework.test.context.junit4.SpringRunner
;
import
org.springframework.test.context.junit4.SpringRunner
;
...
@@ -38,7 +41,9 @@ import static org.assertj.core.api.Assertions.assertThat;
...
@@ -38,7 +41,9 @@ import static org.assertj.core.api.Assertions.assertThat;
* @author Dave Syer
* @author Dave Syer
*/
*/
@RunWith
(
SpringRunner
.
class
)
@RunWith
(
SpringRunner
.
class
)
@SpringBootTest
(
webEnvironment
=
WebEnvironment
.
RANDOM_PORT
)
@SpringBootTest
(
classes
=
{
ShutdownSampleActuatorApplicationTests
.
SecurityConfiguration
.
class
,
SampleActuatorApplication
.
class
},
webEnvironment
=
WebEnvironment
.
RANDOM_PORT
)
public
class
ShutdownSampleActuatorApplicationTests
{
public
class
ShutdownSampleActuatorApplicationTests
{
@Autowired
@Autowired
...
@@ -72,4 +77,14 @@ public class ShutdownSampleActuatorApplicationTests {
...
@@ -72,4 +77,14 @@ public class ShutdownSampleActuatorApplicationTests {
return
"password"
;
return
"password"
;
}
}
@Configuration
static
class
SecurityConfiguration
extends
WebSecurityConfigurerAdapter
{
@Override
protected
void
configure
(
HttpSecurity
http
)
throws
Exception
{
http
.
csrf
().
disable
();
}
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment