Skip to content

Commit

Permalink
Enable CSRF protection by default
Browse files Browse the repository at this point in the history
Fixes gh-11758
  • Loading branch information
mbhave committed Feb 16, 2018
1 parent c5f4f45 commit 51de220
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import org.springframework.boot.autoconfigure.security.SecurityProperties;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.annotation.Order;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;

/**
Expand All @@ -45,12 +44,6 @@ public class SpringBootWebSecurityConfiguration {
@Order(SecurityProperties.BASIC_AUTH_ORDER)
static class DefaultConfigurerAdapter extends WebSecurityConfigurerAdapter {

@Override
protected void configure(HttpSecurity http) throws Exception {
super.configure(http);
http.csrf().disable();
}

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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
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]]
== Working with SQL Databases
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,11 @@
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
import org.springframework.boot.test.web.client.TestRestTemplate;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.HttpStatus;
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.context.junit4.SpringRunner;

Expand All @@ -38,7 +41,9 @@
* @author Dave Syer
*/
@RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT)
@SpringBootTest(classes = { ShutdownSampleActuatorApplicationTests.SecurityConfiguration.class,
SampleActuatorApplication.class },
webEnvironment = WebEnvironment.RANDOM_PORT)
public class ShutdownSampleActuatorApplicationTests {

@Autowired
Expand Down Expand Up @@ -72,4 +77,14 @@ private String getPassword() {
return "password";
}

@Configuration
static class SecurityConfiguration extends WebSecurityConfigurerAdapter {

@Override
protected void configure(HttpSecurity http) throws Exception {
http.csrf().disable();
}

}

}

0 comments on commit 51de220

Please sign in to comment.