2018-09-18 17:09:18 -05:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								[[webflux-headers]]
							 
						 
					
						
							
								
									
										
										
										
											2019-10-24 15:03:05 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								= Security HTTP Response Headers
							 
						 
					
						
							
								
									
										
										
										
											2018-09-18 17:09:18 -05:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2021-08-10 15:21:42 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								xref:features/exploits/headers.adoc#headers[Security HTTP Response Headers] can be used to increase the security of web applications.
							 
						 
					
						
							
								
									
										
										
										
											2019-11-07 10:55:27 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								This section is dedicated to WebFlux based support for Security HTTP Response Headers.
							 
						 
					
						
							
								
									
										
										
										
											2018-09-18 17:09:18 -05:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-11-07 10:55:27 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								[[webflux-headers-default]]
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								== Default Security Headers
							 
						 
					
						
							
								
									
										
										
										
											2018-09-18 17:09:18 -05:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2021-08-10 15:21:42 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								Spring Security provides a xref:features/exploits/headers.adoc#headers-default[default set of Security HTTP Response Headers] to provide secure defaults.
							 
						 
					
						
							
								
									
										
										
										
											2018-09-18 17:09:18 -05:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								While each of these headers are considered best practice, it should be noted that not all clients utilize the headers, so additional testing is encouraged.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								You can customize specific headers.
							 
						 
					
						
							
								
									
										
										
										
											2021-07-30 16:56:54 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								For example, assume that you want the defaults except you wish to specify `SAMEORIGIN` for xref:servlet/exploits/headers.adoc#servlet-headers-frame-options[X-Frame-Options].
							 
						 
					
						
							
								
									
										
										
										
											2018-09-18 17:09:18 -05:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2020-07-14 16:34:30 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								You can easily do this with the following Configuration:
							 
						 
					
						
							
								
									
										
										
										
											2018-09-18 17:09:18 -05:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2020-07-14 16:34:30 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								.Customize Default Security Headers
							 
						 
					
						
							
								
									
										
										
										
											2019-11-07 10:55:27 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								====
							 
						 
					
						
							
								
									
										
										
										
											2020-07-14 16:34:30 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								.Java
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								[source,java,role="primary"]
							 
						 
					
						
							
								
									
										
										
										
											2018-09-18 17:09:18 -05:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								----
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								@Bean
							 
						 
					
						
							
								
									
										
										
										
											2019-07-24 12:15:32 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								SecurityWebFilterChain springSecurityFilterChain(ServerHttpSecurity http) {
							 
						 
					
						
							
								
									
										
										
										
											2018-09-18 17:09:18 -05:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									http
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										// ...
							 
						 
					
						
							
								
									
										
										
										
											2020-01-10 13:10:36 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										.headers(headers -> headers
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											.frameOptions(frameOptions -> frameOptions
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												.mode(Mode.SAMEORIGIN)
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											)
							 
						 
					
						
							
								
									
										
										
										
											2019-07-22 09:31:10 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										);
							 
						 
					
						
							
								
									
										
										
										
											2018-09-18 17:09:18 -05:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									return http.build();
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								----
							 
						 
					
						
							
								
									
										
										
										
											2020-07-14 16:34:30 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								.Kotlin
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								[source,kotlin,role="secondary"]
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								----
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								@Bean
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								fun webFilterChain(http: ServerHttpSecurity): SecurityWebFilterChain {
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    return http {
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        // ...
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        headers {
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            frameOptions {
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                mode = Mode.SAMEORIGIN
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								----
							 
						 
					
						
							
								
									
										
										
										
											2019-11-07 10:55:27 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								====
							 
						 
					
						
							
								
									
										
										
										
											2018-09-18 17:09:18 -05:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								If you do not want the defaults to be added and want explicit control over what should be used, you can disable the defaults.
							 
						 
					
						
							
								
									
										
										
										
											2020-07-14 16:34:30 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								An example is provided below:
							 
						 
					
						
							
								
									
										
										
										
											2018-09-18 17:09:18 -05:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-11-07 10:55:27 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								.Disable HTTP Security Response Headers
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								====
							 
						 
					
						
							
								
									
										
										
										
											2020-07-14 16:34:30 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								.Java
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								[source,java,role="primary"]
							 
						 
					
						
							
								
									
										
										
										
											2018-09-18 17:09:18 -05:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								----
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								@Bean
							 
						 
					
						
							
								
									
										
										
										
											2019-07-24 12:15:32 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								SecurityWebFilterChain springSecurityFilterChain(ServerHttpSecurity http) {
							 
						 
					
						
							
								
									
										
										
										
											2018-09-18 17:09:18 -05:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									http
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										// ...
							 
						 
					
						
							
								
									
										
										
										
											2020-01-10 13:10:36 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										.headers(headers -> headers.disable());
							 
						 
					
						
							
								
									
										
										
										
											2018-09-18 17:09:18 -05:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									return http.build();
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								----
							 
						 
					
						
							
								
									
										
										
										
											2020-07-14 16:34:30 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								.Kotlin
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								[source,kotlin,role="secondary"]
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								----
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								@Bean
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								fun webFilterChain(http: ServerHttpSecurity): SecurityWebFilterChain {
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    return http {
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        // ...
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        headers {
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            disable()
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								----
							 
						 
					
						
							
								
									
										
										
										
											2019-11-07 10:55:27 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								====
							 
						 
					
						
							
								
									
										
										
										
											2018-09-18 17:09:18 -05:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								[[webflux-headers-cache-control]]
							 
						 
					
						
							
								
									
										
										
										
											2018-09-18 20:30:45 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								== Cache Control
							 
						 
					
						
							
								
									
										
										
										
											2018-09-18 17:09:18 -05:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2021-08-10 15:21:42 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								Spring Security includes xref:features/exploits/headers.adoc#headers-cache-control[Cache Control] headers by default.
							 
						 
					
						
							
								
									
										
										
										
											2018-09-18 17:09:18 -05:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-11-07 10:55:27 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								However, if you actually want to cache specific responses, your application can selectively add them to the https://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/http/server/reactive/ServerHttpResponse.html[ServerHttpResponse] to override the header set by Spring Security.
							 
						 
					
						
							
								
									
										
										
										
											2018-09-18 17:09:18 -05:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								This is useful to ensure things like CSS, JavaScript, and images are properly cached.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2021-08-15 15:08:52 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								When using Spring WebFlux, this is typically done within your configuration.
							 
						 
					
						
							
								
									
										
										
										
											2019-11-07 10:55:27 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								Details on how to do this can be found in the https://docs.spring.io/spring/docs/5.0.0.RELEASE/spring-framework-reference/web-reactive.html#webflux-config-static-resources[Static Resources] portion of the Spring Reference documentation
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								If necessary, you can also disable Spring Security's cache control HTTP response headers.
							 
						 
					
						
							
								
									
										
										
										
											2018-09-18 17:09:18 -05:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-11-07 10:55:27 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								.Cache Control Disabled
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								====
							 
						 
					
						
							
								
									
										
										
										
											2020-07-14 16:34:30 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								.Java
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								[source,java,role="primary"]
							 
						 
					
						
							
								
									
										
										
										
											2018-09-18 17:09:18 -05:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								----
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								@Bean
							 
						 
					
						
							
								
									
										
										
										
											2019-07-24 12:15:32 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								SecurityWebFilterChain springSecurityFilterChain(ServerHttpSecurity http) {
							 
						 
					
						
							
								
									
										
										
										
											2018-09-18 17:09:18 -05:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									http
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										// ...
							 
						 
					
						
							
								
									
										
										
										
											2020-01-10 13:10:36 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										.headers(headers -> headers
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											.cache(cache -> cache.disable())
							 
						 
					
						
							
								
									
										
										
										
											2019-07-22 09:31:10 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										);
							 
						 
					
						
							
								
									
										
										
										
											2018-09-18 17:09:18 -05:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									return http.build();
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								----
							 
						 
					
						
							
								
									
										
										
										
											2020-07-14 16:34:30 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								.Kotlin
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								[source,kotlin,role="secondary"]
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								----
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								@Bean
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								fun webFilterChain(http: ServerHttpSecurity): SecurityWebFilterChain {
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    return http {
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        // ...
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        headers {
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            cache {
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                disable()
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								----
							 
						 
					
						
							
								
									
										
										
										
											2019-11-07 10:55:27 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								====
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2018-09-18 17:09:18 -05:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								[[webflux-headers-content-type-options]]
							 
						 
					
						
							
								
									
										
										
										
											2018-09-18 20:30:45 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								== Content Type Options
							 
						 
					
						
							
								
									
										
										
										
											2021-08-10 15:21:42 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								Spring Security includes xref:features/exploits/headers.adoc#headers-content-type-options[Content-Type] headers by default.
							 
						 
					
						
							
								
									
										
										
										
											2020-07-14 16:34:30 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								However, you can disable it with:
							 
						 
					
						
							
								
									
										
										
										
											2018-09-18 17:09:18 -05:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2020-07-14 16:34:30 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								.Content Type Options Disabled
							 
						 
					
						
							
								
									
										
										
										
											2019-11-07 10:55:27 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								====
							 
						 
					
						
							
								
									
										
										
										
											2020-07-14 16:34:30 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								.Java
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								[source,java,role="primary"]
							 
						 
					
						
							
								
									
										
										
										
											2018-09-18 17:09:18 -05:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								----
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								@Bean
							 
						 
					
						
							
								
									
										
										
										
											2019-07-24 12:15:32 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								SecurityWebFilterChain springSecurityFilterChain(ServerHttpSecurity http) {
							 
						 
					
						
							
								
									
										
										
										
											2018-09-18 17:09:18 -05:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									http
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										// ...
							 
						 
					
						
							
								
									
										
										
										
											2020-01-10 13:10:36 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										.headers(headers -> headers
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											.contentTypeOptions(contentTypeOptions -> contentTypeOptions.disable())
							 
						 
					
						
							
								
									
										
										
										
											2019-07-22 09:31:10 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										);
							 
						 
					
						
							
								
									
										
										
										
											2018-09-18 17:09:18 -05:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									return http.build();
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								----
							 
						 
					
						
							
								
									
										
										
										
											2020-07-14 16:34:30 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								.Kotlin
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								[source,kotlin,role="secondary"]
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								----
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								@Bean
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								fun webFilterChain(http: ServerHttpSecurity): SecurityWebFilterChain {
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    return http {
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        // ...
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        headers {
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            contentTypeOptions {
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                disable()
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								----
							 
						 
					
						
							
								
									
										
										
										
											2019-11-07 10:55:27 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								====
							 
						 
					
						
							
								
									
										
										
										
											2018-09-18 17:09:18 -05:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								[[webflux-headers-hsts]]
							 
						 
					
						
							
								
									
										
										
										
											2018-09-18 20:30:45 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								== HTTP Strict Transport Security (HSTS)
							 
						 
					
						
							
								
									
										
										
										
											2021-08-10 15:21:42 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								Spring Security provides the xref:features/exploits/headers.adoc#headers-hsts[Strict Transport Security] header by default.
							 
						 
					
						
							
								
									
										
										
										
											2019-11-07 10:55:27 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								However, you can customize the results explicitly.
							 
						 
					
						
							
								
									
										
										
										
											2020-07-14 16:34:30 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								For example, the following is an example of explicitly providing HSTS:
							 
						 
					
						
							
								
									
										
										
										
											2018-09-18 17:09:18 -05:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2020-07-14 16:34:30 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								.Strict Transport Security
							 
						 
					
						
							
								
									
										
										
										
											2019-11-07 10:55:27 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								====
							 
						 
					
						
							
								
									
										
										
										
											2020-07-14 16:34:30 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								.Java
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								[source,java,role="primary"]
							 
						 
					
						
							
								
									
										
										
										
											2018-09-18 17:09:18 -05:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								----
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								@Bean
							 
						 
					
						
							
								
									
										
										
										
											2019-07-24 12:15:32 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								SecurityWebFilterChain springSecurityFilterChain(ServerHttpSecurity http) {
							 
						 
					
						
							
								
									
										
										
										
											2018-09-18 17:09:18 -05:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									http
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										// ...
							 
						 
					
						
							
								
									
										
										
										
											2020-01-10 13:10:36 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										.headers(headers -> headers
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											.hsts(hsts -> hsts
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												.includeSubdomains(true)
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												.preload(true)
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												.maxAge(Duration.ofDays(365))
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											)
							 
						 
					
						
							
								
									
										
										
										
											2019-07-22 09:31:10 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										);
							 
						 
					
						
							
								
									
										
										
										
											2018-09-18 17:09:18 -05:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									return http.build();
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								----
							 
						 
					
						
							
								
									
										
										
										
											2020-07-14 16:34:30 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								.Kotlin
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								[source,kotlin,role="secondary"]
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								----
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								@Bean
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								fun webFilterChain(http: ServerHttpSecurity): SecurityWebFilterChain {
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    return http {
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        // ...
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        headers {
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            hsts {
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                includeSubdomains = true
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                preload = true
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                maxAge = Duration.ofDays(365)
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								----
							 
						 
					
						
							
								
									
										
										
										
											2019-11-07 10:55:27 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								====
							 
						 
					
						
							
								
									
										
										
										
											2018-09-18 17:09:18 -05:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								[[webflux-headers-frame-options]]
							 
						 
					
						
							
								
									
										
										
										
											2018-09-18 20:30:45 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								== X-Frame-Options
							 
						 
					
						
							
								
									
										
										
										
											2021-08-10 15:21:42 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								By default, Spring Security disables rendering within an iframe using xref:features/exploits/headers.adoc#headers-frame-options[X-Frame-Options].
							 
						 
					
						
							
								
									
										
										
										
											2018-09-18 17:09:18 -05:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2020-07-14 16:34:30 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								You can customize frame options to use the same origin using the following:
							 
						 
					
						
							
								
									
										
										
										
											2018-09-18 17:09:18 -05:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-11-07 10:55:27 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								.X-Frame-Options: SAMEORIGIN
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								====
							 
						 
					
						
							
								
									
										
										
										
											2020-07-14 16:34:30 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								.Java
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								[source,java,role="primary"]
							 
						 
					
						
							
								
									
										
										
										
											2018-09-18 17:09:18 -05:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								----
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								@Bean
							 
						 
					
						
							
								
									
										
										
										
											2019-07-24 12:15:32 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								SecurityWebFilterChain springSecurityFilterChain(ServerHttpSecurity http) {
							 
						 
					
						
							
								
									
										
										
										
											2018-09-18 17:09:18 -05:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									http
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										// ...
							 
						 
					
						
							
								
									
										
										
										
											2020-01-10 13:10:36 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										.headers(headers -> headers
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											.frameOptions(frameOptions -> frameOptions
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												.mode(SAMEORIGIN)
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											)
							 
						 
					
						
							
								
									
										
										
										
											2019-07-22 09:31:10 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										);
							 
						 
					
						
							
								
									
										
										
										
											2018-09-18 17:09:18 -05:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									return http.build();
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								----
							 
						 
					
						
							
								
									
										
										
										
											2020-07-14 16:34:30 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								.Kotlin
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								[source,kotlin,role="secondary"]
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								----
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								@Bean
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								fun webFilterChain(http: ServerHttpSecurity): SecurityWebFilterChain {
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    return http {
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        // ...
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        headers {
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            frameOptions {
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                mode = SAMEORIGIN
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								----
							 
						 
					
						
							
								
									
										
										
										
											2019-11-07 10:55:27 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								====
							 
						 
					
						
							
								
									
										
										
										
											2018-09-18 17:09:18 -05:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								[[webflux-headers-xss-protection]]
							 
						 
					
						
							
								
									
										
										
										
											2018-09-18 20:30:45 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								== X-XSS-Protection
							 
						 
					
						
							
								
									
										
										
										
											2019-11-07 10:55:27 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								By default, Spring Security instructs browsers to block reflected XSS attacks using the <<headers-xss-protection,X-XSS-Protection header>.
							 
						 
					
						
							
								
									
										
										
										
											2020-07-14 16:34:30 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								You can disable `X-XSS-Protection` with the following Configuration:
							 
						 
					
						
							
								
									
										
										
										
											2018-09-18 17:09:18 -05:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-11-07 10:55:27 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								.X-XSS-Protection Customization
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								====
							 
						 
					
						
							
								
									
										
										
										
											2020-07-14 16:34:30 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								.Java
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								[source,java,role="primary"]
							 
						 
					
						
							
								
									
										
										
										
											2018-09-18 17:09:18 -05:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								----
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								@Bean
							 
						 
					
						
							
								
									
										
										
										
											2019-07-24 12:15:32 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								SecurityWebFilterChain springSecurityFilterChain(ServerHttpSecurity http) {
							 
						 
					
						
							
								
									
										
										
										
											2018-09-18 17:09:18 -05:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									http
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										// ...
							 
						 
					
						
							
								
									
										
										
										
											2020-01-10 13:10:36 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										.headers(headers -> headers
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											.xssProtection(xssProtection -> xssProtection.disable())
							 
						 
					
						
							
								
									
										
										
										
											2019-07-22 09:31:10 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										);
							 
						 
					
						
							
								
									
										
										
										
											2018-09-18 17:09:18 -05:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									return http.build();
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								----
							 
						 
					
						
							
								
									
										
										
										
											2020-07-14 16:34:30 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								.Kotlin
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								[source,kotlin,role="secondary"]
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								----
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								@Bean
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								fun webFilterChain(http: ServerHttpSecurity): SecurityWebFilterChain {
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    return http {
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        // ...
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        headers {
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            xssProtection {
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                disable()
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								----
							 
						 
					
						
							
								
									
										
										
										
											2019-11-07 10:55:27 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								====
							 
						 
					
						
							
								
									
										
										
										
											2018-09-18 17:09:18 -05:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								[[webflux-headers-csp]]
							 
						 
					
						
							
								
									
										
										
										
											2018-09-18 20:30:45 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								== Content Security Policy (CSP)
							 
						 
					
						
							
								
									
										
										
										
											2021-08-10 15:21:42 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								Spring Security does not add xref:features/exploits/headers.adoc#headers-csp[Content Security Policy] by default, because a reasonable default is impossible to know without context of the application.
							 
						 
					
						
							
								
									
										
										
										
											2018-09-18 17:09:18 -05:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								The web application author must declare the security policy(s) to enforce and/or monitor for the protected resources.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								For example, given the following security policy:
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-11-07 10:55:27 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								.Content Security Policy Example
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								====
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								[source,http]
							 
						 
					
						
							
								
									
										
										
										
											2018-09-18 17:09:18 -05:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								----
							 
						 
					
						
							
								
									
										
										
										
											2019-11-07 10:55:27 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								Content-Security-Policy: script-src 'self' https://trustedscripts.example.com; object-src https://trustedplugins.example.com; report-uri /csp-report-endpoint/
							 
						 
					
						
							
								
									
										
										
										
											2018-09-18 17:09:18 -05:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								----
							 
						 
					
						
							
								
									
										
										
										
											2019-11-07 10:55:27 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								====
							 
						 
					
						
							
								
									
										
										
										
											2018-09-18 17:09:18 -05:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2020-07-14 16:34:30 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								You can enable the CSP header as shown below:
							 
						 
					
						
							
								
									
										
										
										
											2018-09-18 17:09:18 -05:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-11-07 10:55:27 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								.Content Security Policy
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								====
							 
						 
					
						
							
								
									
										
										
										
											2020-07-14 16:34:30 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								.Java
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								[source,java,role="primary"]
							 
						 
					
						
							
								
									
										
										
										
											2018-09-18 17:09:18 -05:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								----
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								@Bean
							 
						 
					
						
							
								
									
										
										
										
											2019-07-24 12:15:32 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								SecurityWebFilterChain springSecurityFilterChain(ServerHttpSecurity http) {
							 
						 
					
						
							
								
									
										
										
										
											2018-09-18 17:09:18 -05:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									http
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										// ...
							 
						 
					
						
							
								
									
										
										
										
											2020-01-10 13:10:36 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										.headers(headers -> headers
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											.contentSecurityPolicy(policy -> policy
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												.policyDirectives("script-src 'self' https://trustedscripts.example.com; object-src https://trustedplugins.example.com; report-uri /csp-report-endpoint/")
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											)
							 
						 
					
						
							
								
									
										
										
										
											2019-07-22 09:31:10 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										);
							 
						 
					
						
							
								
									
										
										
										
											2018-09-18 17:09:18 -05:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									return http.build();
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								----
							 
						 
					
						
							
								
									
										
										
										
											2020-07-14 16:34:30 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								.Kotlin
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								[source,kotlin,role="secondary"]
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								----
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								@Bean
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								fun webFilterChain(http: ServerHttpSecurity): SecurityWebFilterChain {
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    return http {
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        // ...
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        headers {
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            contentSecurityPolicy {
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                policyDirectives = "script-src 'self' https://trustedscripts.example.com; object-src https://trustedplugins.example.com; report-uri /csp-report-endpoint/"
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								----
							 
						 
					
						
							
								
									
										
										
										
											2019-11-07 10:55:27 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								====
							 
						 
					
						
							
								
									
										
										
										
											2018-09-18 17:09:18 -05:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2020-07-14 16:34:30 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								To enable the CSP `report-only` header, provide the following configuration:
							 
						 
					
						
							
								
									
										
										
										
											2018-09-18 17:09:18 -05:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-11-07 10:55:27 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								.Content Security Policy Report Only
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								====
							 
						 
					
						
							
								
									
										
										
										
											2020-07-14 16:34:30 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								.Java
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								[source,java,role="primary"]
							 
						 
					
						
							
								
									
										
										
										
											2018-09-18 17:09:18 -05:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								----
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								@Bean
							 
						 
					
						
							
								
									
										
										
										
											2019-07-24 12:15:32 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								SecurityWebFilterChain springSecurityFilterChain(ServerHttpSecurity http) {
							 
						 
					
						
							
								
									
										
										
										
											2018-09-18 17:09:18 -05:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									http
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										// ...
							 
						 
					
						
							
								
									
										
										
										
											2020-01-10 13:10:36 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										.headers(headers -> headers
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											.contentSecurityPolicy(policy -> policy
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												.policyDirectives("script-src 'self' https://trustedscripts.example.com; object-src https://trustedplugins.example.com; report-uri /csp-report-endpoint/")
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												.reportOnly()
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											)
							 
						 
					
						
							
								
									
										
										
										
											2019-07-22 09:31:10 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										);
							 
						 
					
						
							
								
									
										
										
										
											2018-09-18 17:09:18 -05:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									return http.build();
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								----
							 
						 
					
						
							
								
									
										
										
										
											2020-07-14 16:34:30 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								.Kotlin
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								[source,kotlin,role="secondary"]
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								----
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								@Bean
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								fun webFilterChain(http: ServerHttpSecurity): SecurityWebFilterChain {
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    return http {
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        // ...
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        headers {
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            contentSecurityPolicy {
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                policyDirectives = "script-src 'self' https://trustedscripts.example.com; object-src https://trustedplugins.example.com; report-uri /csp-report-endpoint/"
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                reportOnly = true
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								----
							 
						 
					
						
							
								
									
										
										
										
											2019-11-07 10:55:27 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								====
							 
						 
					
						
							
								
									
										
										
										
											2018-09-18 17:09:18 -05:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								[[webflux-headers-referrer]]
							 
						 
					
						
							
								
									
										
										
										
											2018-09-18 20:30:45 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								== Referrer Policy
							 
						 
					
						
							
								
									
										
										
										
											2018-09-18 17:09:18 -05:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2021-08-10 15:21:42 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								Spring Security does not add xref:features/exploits/headers.adoc#headers-referrer[Referrer Policy] headers by default.
							 
						 
					
						
							
								
									
										
										
										
											2020-07-14 16:34:30 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								You can enable the Referrer Policy header using configuration as shown below:
							 
						 
					
						
							
								
									
										
										
										
											2018-09-18 17:09:18 -05:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2020-07-14 16:34:30 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								.Referrer Policy Configuration
							 
						 
					
						
							
								
									
										
										
										
											2019-11-07 10:55:27 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								====
							 
						 
					
						
							
								
									
										
										
										
											2020-07-14 16:34:30 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								.Java
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								[source,java,role="primary"]
							 
						 
					
						
							
								
									
										
										
										
											2018-09-18 17:09:18 -05:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								----
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								@Bean
							 
						 
					
						
							
								
									
										
										
										
											2019-07-24 12:15:32 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								SecurityWebFilterChain springSecurityFilterChain(ServerHttpSecurity http) {
							 
						 
					
						
							
								
									
										
										
										
											2018-09-18 17:09:18 -05:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									http
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										// ...
							 
						 
					
						
							
								
									
										
										
										
											2020-01-10 13:10:36 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										.headers(headers -> headers
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											.referrerPolicy(referrer -> referrer
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												.policy(ReferrerPolicy.SAME_ORIGIN)
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											)
							 
						 
					
						
							
								
									
										
										
										
											2019-07-22 09:31:10 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										);
							 
						 
					
						
							
								
									
										
										
										
											2018-09-18 17:09:18 -05:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									return http.build();
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								----
							 
						 
					
						
							
								
									
										
										
										
											2020-07-14 16:34:30 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								.Kotlin
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								[source,kotlin,role="secondary"]
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								----
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								@Bean
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								fun webFilterChain(http: ServerHttpSecurity): SecurityWebFilterChain {
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    return http {
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        // ...
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        headers {
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            referrerPolicy {
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                policy = ReferrerPolicy.SAME_ORIGIN
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								----
							 
						 
					
						
							
								
									
										
										
										
											2019-11-07 10:55:27 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								====
							 
						 
					
						
							
								
									
										
										
										
											2018-09-18 17:09:18 -05:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								[[webflux-headers-feature]]
							 
						 
					
						
							
								
									
										
										
										
											2018-09-18 20:30:45 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								== Feature Policy
							 
						 
					
						
							
								
									
										
										
										
											2018-09-18 17:09:18 -05:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2021-08-10 15:21:42 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								Spring Security does not add xref:features/exploits/headers.adoc#headers-feature[Feature Policy] headers by default.
							 
						 
					
						
							
								
									
										
										
										
											2019-11-07 10:55:27 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								The following `Feature-Policy` header:
							 
						 
					
						
							
								
									
										
										
										
											2018-09-18 17:09:18 -05:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-11-07 10:55:27 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								.Feature-Policy Example
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								====
							 
						 
					
						
							
								
									
										
										
										
											2018-09-18 17:09:18 -05:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								[source]
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								----
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								Feature-Policy: geolocation 'self'
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								----
							 
						 
					
						
							
								
									
										
										
										
											2019-11-07 10:55:27 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								====
							 
						 
					
						
							
								
									
										
										
										
											2018-09-18 17:09:18 -05:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2020-07-14 16:34:30 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								You can enable the Feature Policy header as shown below:
							 
						 
					
						
							
								
									
										
										
										
											2018-09-18 17:09:18 -05:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2020-07-14 16:34:30 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								.Feature-Policy Configuration
							 
						 
					
						
							
								
									
										
										
										
											2019-11-07 10:55:27 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								====
							 
						 
					
						
							
								
									
										
										
										
											2020-07-14 16:34:30 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								.Java
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								[source,java,role="primary"]
							 
						 
					
						
							
								
									
										
										
										
											2018-09-18 17:09:18 -05:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								----
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								@Bean
							 
						 
					
						
							
								
									
										
										
										
											2019-07-24 12:15:32 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								SecurityWebFilterChain springSecurityFilterChain(ServerHttpSecurity http) {
							 
						 
					
						
							
								
									
										
										
										
											2018-09-18 17:09:18 -05:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									http
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										// ...
							 
						 
					
						
							
								
									
										
										
										
											2020-01-10 13:10:36 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										.headers(headers -> headers
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											.featurePolicy("geolocation 'self'")
							 
						 
					
						
							
								
									
										
										
										
											2019-07-22 09:31:10 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										);
							 
						 
					
						
							
								
									
										
										
										
											2018-09-18 17:09:18 -05:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									return http.build();
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								----
							 
						 
					
						
							
								
									
										
										
										
											2020-07-14 16:34:30 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								.Kotlin
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								[source,kotlin,role="secondary"]
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								----
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								@Bean
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								fun webFilterChain(http: ServerHttpSecurity): SecurityWebFilterChain {
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    return http {
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        // ...
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        headers {
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            featurePolicy("geolocation 'self'")
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								----
							 
						 
					
						
							
								
									
										
										
										
											2019-11-07 10:55:27 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								====
							 
						 
					
						
							
								
									
										
										
										
											2019-09-20 13:02:06 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2020-12-04 23:00:09 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								[[webflux-headers-permissions]]
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								== Permissions Policy
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2021-08-10 15:21:42 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								Spring Security does not add xref:features/exploits/headers.adoc#headers-permissions[Permissions Policy] headers by default.
							 
						 
					
						
							
								
									
										
										
										
											2020-12-04 23:00:09 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								The following `Permissions-Policy` header:
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								.Permissions-Policy Example
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								====
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								[source]
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								----
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								Permissions-Policy: geolocation=(self)
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								----
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								====
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								You can enable the Permissions Policy header as shown below:
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								.Permissions-Policy Configuration
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								====
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								.Java
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								[source,java,role="primary"]
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								----
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								@Bean
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								SecurityWebFilterChain springSecurityFilterChain(ServerHttpSecurity http) {
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									http
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										// ...
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										.headers(headers -> headers
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											.permissionsPolicy(permissions -> permissions
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												.policy("geolocation=(self)")
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											)
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										);
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									return http.build();
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								----
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								.Kotlin
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								[source,kotlin,role="secondary"]
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								----
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								@Bean
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								fun webFilterChain(http: ServerHttpSecurity): SecurityWebFilterChain {
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    return http {
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        // ...
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        headers {
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            permissionsPolicy {
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                policy = "geolocation=(self)"
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								----
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								====
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-11-07 10:55:27 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								[[webflux-headers-clear-site-data]]
							 
						 
					
						
							
								
									
										
										
										
											2019-09-20 13:02:06 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								== Clear Site Data
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2021-08-10 15:21:42 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								Spring Security does not add xref:features/exploits/headers.adoc#headers-clear-site-data[Clear-Site-Data] headers by default.
							 
						 
					
						
							
								
									
										
										
										
											2019-11-07 10:55:27 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								The following Clear-Site-Data header:
							 
						 
					
						
							
								
									
										
										
										
											2019-09-20 13:02:06 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-11-07 10:55:27 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								.Clear-Site-Data Example
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								====
							 
						 
					
						
							
								
									
										
										
										
											2019-09-20 13:02:06 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								----
							 
						 
					
						
							
								
									
										
										
										
											2019-11-07 10:55:27 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								Clear-Site-Data: "cache", "cookies"
							 
						 
					
						
							
								
									
										
										
										
											2019-09-20 13:02:06 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								----
							 
						 
					
						
							
								
									
										
										
										
											2019-11-07 10:55:27 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								====
							 
						 
					
						
							
								
									
										
										
										
											2019-09-20 13:02:06 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-11-07 10:55:27 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								can be sent on log out with the following configuration:
							 
						 
					
						
							
								
									
										
										
										
											2019-09-20 13:02:06 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2020-07-14 16:34:30 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								.Clear-Site-Data Configuration
							 
						 
					
						
							
								
									
										
										
										
											2019-11-07 10:55:27 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								====
							 
						 
					
						
							
								
									
										
										
										
											2020-07-14 16:34:30 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								.Java
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								[source,java,role="primary"]
							 
						 
					
						
							
								
									
										
										
										
											2019-09-20 13:02:06 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								----
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								@Bean
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								SecurityWebFilterChain springSecurityFilterChain(ServerHttpSecurity http) {
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									ServerLogoutHandler securityContext = new SecurityContextServerLogoutHandler();
							 
						 
					
						
							
								
									
										
										
										
											2019-11-07 10:55:27 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									ClearSiteDataServerHttpHeadersWriter writer = new ClearSiteDataServerHttpHeadersWriter(CACHE, COOKIES);
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									ServerLogoutHandler clearSiteData = new HeaderWriterServerLogoutHandler(writer);
							 
						 
					
						
							
								
									
										
										
										
											2019-09-20 13:02:06 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									DelegatingServerLogoutHandler logoutHandler = new DelegatingServerLogoutHandler(securityContext, clearSiteData);
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									http
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										// ...
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										.logout()
							 
						 
					
						
							
								
									
										
										
										
											2019-11-07 10:55:27 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											.logoutHandler(logoutHandler);
							 
						 
					
						
							
								
									
										
										
										
											2019-09-20 13:02:06 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									return http.build();
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								----
							 
						 
					
						
							
								
									
										
										
										
											2020-07-14 16:34:30 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								.Kotlin
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								[source,kotlin,role="secondary"]
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								----
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								@Bean
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								fun webFilterChain(http: ServerHttpSecurity): SecurityWebFilterChain {
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    val securityContext: ServerLogoutHandler = SecurityContextServerLogoutHandler()
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    val writer = ClearSiteDataServerHttpHeadersWriter(CACHE, COOKIES)
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    val clearSiteData: ServerLogoutHandler = HeaderWriterServerLogoutHandler(writer)
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    val customLogoutHandler = DelegatingServerLogoutHandler(securityContext, clearSiteData)
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    return http {
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        // ...
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        logout {
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            logoutHandler = customLogoutHandler
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								----
							 
						 
					
						
							
								
									
										
										
										
											2019-11-07 10:55:27 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								====
							 
						 
					
						
							
								
									
										
										
										
											2021-12-03 16:47:21 -03:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								[[webflux-headers-cross-origin-policies]]
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								== Cross-Origin Policies
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								Spring Security provides built-in support for adding some Cross-Origin policies headers, those headers are:
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								[source]
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								----
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								Cross-Origin-Opener-Policy
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								Cross-Origin-Embedder-Policy
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								Cross-Origin-Resource-Policy
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								----
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								Spring Security does not add <<headers-cross-origin-policies,Cross-Origin Policies>> headers by default.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								The headers can be added with the following configuration:
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								.Cross-Origin Policies
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								====
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								.Java
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								[source,java,role="primary"]
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								----
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								@EnableWebFluxSecurity
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								@EnableWebFlux
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								public class WebSecurityConfig {
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    @Bean
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    SecurityWebFilterChain securityFilterChain(ServerHttpSecurity http) {
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        http.headers((headers) -> headers
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                .crossOriginOpenerPolicy(CrossOriginOpenerPolicy.SAME_ORIGIN)
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                .crossOriginEmbedderPolicy(CrossOriginEmbedderPolicy.REQUIRE_CORP)
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                .crossOriginResourcePolicy(CrossOriginResourcePolicy.SAME_ORIGIN));
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        return http.build();
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								----
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								.Kotlin
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								[source,kotlin,role="secondary"]
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								----
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								@EnableWebFluxSecurity
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								@EnableWebFlux
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								open class CrossOriginPoliciesCustomConfig {
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    @Bean
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    open fun springWebFilterChain(http: ServerHttpSecurity): SecurityWebFilterChain {
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        return http {
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            headers {
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                crossOriginOpenerPolicy(CrossOriginOpenerPolicy.SAME_ORIGIN)
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                crossOriginEmbedderPolicy(CrossOriginEmbedderPolicy.REQUIRE_CORP)
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                crossOriginResourcePolicy(CrossOriginResourcePolicy.SAME_ORIGIN)
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								----
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								====
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								This configuration will write the headers with the values provided:
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								[source]
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								----
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								Cross-Origin-Opener-Policy: same-origin
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								Cross-Origin-Embedder-Policy: require-corp
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								Cross-Origin-Resource-Policy: same-origin
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								----