Skip to content

Commit b3d177f

Browse files
committed
Extract HTTPS Documentation
Fixes gh-7626
1 parent 7cbd166 commit b3d177f

File tree

8 files changed

+123
-41
lines changed

8 files changed

+123
-41
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
[[http]]
2+
= HTTP
3+
4+
All HTTP based communication, including https://www.troyhunt.com/heres-why-your-static-website-needs-https/[static resources], should be protected https://cheatsheetseries.owasp.org/cheatsheets/Transport_Layer_Protection_Cheat_Sheet.html[using TLS].
5+
6+
As a framework, Spring Security does not handle HTTP connections and thus does not provide support for HTTPS directly.
7+
However, it does provide a number of features that help with HTTPS usage.
8+
9+
[[http-redirect]]
10+
== Redirect to HTTPS
11+
12+
When a client uses HTTP, Spring Security can be configured to redirect to HTTPS both <<servlet-http-redirect,Servlet>> and <<webflux-http-redirect,WebFlux>> environments.
13+
14+
[[http-hsts]]
15+
== Strict Transport Security
16+
17+
Spring Security provides support for <<headers-hsts,Strict Transport Security>> and enables it by default.
18+
19+
[[http-proxy-server]]
20+
== Proxy Server Configuration
21+
22+
When using a proxy server it is important to ensure that you have configured your application properly.
23+
For example, many applications will have a load balancer that responds to request for https://example.com/ by forwarding the request to an application server at https://192.168.1:8080
24+
Without proper configuration, the application server will not know that the load balancer exists and treat the request as though https://192.168.1:8080 was requested by the client.
25+
26+
To fix this you can use https://tools.ietf.org/html/rfc7239[RFC 7239] to specify that a load balancer is being used.
27+
To make the application aware of this, you need to either configure your application server aware of the X-Forwarded headers.
28+
For example Tomcat uses the https://tomcat.apache.org/tomcat-8.0-doc/api/org/apache/catalina/valves/RemoteIpValve.html[RemoteIpValve] and Jetty uses https://download.eclipse.org/jetty/stable-9/apidocs/org/eclipse/jetty/server/ForwardedRequestCustomizer.html[ForwardedRequestCustomizer].
29+
Alternatively, Spring users can leverage https://github.com/spring-projects/spring-framework/blob/v4.3.3.RELEASE/spring-web/src/main/java/org/springframework/web/filter/ForwardedHeaderFilter.java[ForwardedHeaderFilter].
30+
31+
Spring Boot users may use the `server.use-forward-headers` property to configure the application.
32+
See the https://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#howto-use-tomcat-behind-a-proxy-server[Spring Boot documentation] for further details.

docs/manual/src/docs/asciidoc/_includes/about/exploits/index.adoc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,5 @@ Below you will find high level description of the various exploits that Spring S
88
include::csrf.adoc[leveloffset=+1]
99

1010
include::headers.adoc[leveloffset=+1]
11+
12+
include::http.adoc[leveloffset=+1]

docs/manual/src/docs/asciidoc/_includes/reactive/exploits/redirect-https.adoc renamed to docs/manual/src/docs/asciidoc/_includes/reactive/exploits/http.adoc

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,19 @@
1-
[[webflux-redirect-https]]
2-
= Redirect to HTTPS
1+
[[webflux-http]]
2+
= HTTP
33

4-
HTTPS is required to provide a secure application.
5-
Spring Security can be configured to perform a redirect to https using the following Java Configuration:
4+
All HTTP based communication should be protected <<http,using TLS>>.
65

6+
Below you can find details around WebFlux specific features that assist with HTTPS usage.
7+
8+
[[webflux-http-redirect]]
9+
== Redirect to HTTPS
10+
11+
If a client makes a request using HTTP rather than HTTPS, Spring Security can be configured to redirect to HTTPS.
12+
13+
For example, the following Java configuration will redirect any HTTP requests to HTTPS:
14+
15+
.Redirect to HTTPS
16+
====
717
[source,java]
818
----
919
@Bean
@@ -14,11 +24,14 @@ SecurityWebFilterChain springSecurityFilterChain(ServerHttpSecurity http) {
1424
return http.build();
1525
}
1626
----
27+
====
1728

1829
The configuration can easily be wrapped around an if statement to only be turned on in production.
1930
Alternatively, it can be enabled by looking for a property about the request that only happens in production.
2031
For example, if the production environment adds a header named `X-Forwarded-Proto` the following Java Configuration could be used:
2132

33+
.Redirect to HTTPS when X-Forwarded
34+
====
2235
[source,java]
2336
----
2437
@Bean
@@ -32,3 +45,14 @@ SecurityWebFilterChain springSecurityFilterChain(ServerHttpSecurity http) {
3245
return http.build();
3346
}
3447
----
48+
====
49+
50+
[[webflux-hsts]]
51+
== Strict Transport Security
52+
53+
Spring Security provides support for <<servlet-headers-hsts,Strict Transport Security>> and enables it by default.
54+
55+
[[webflux-http-proxy-server]]
56+
== Proxy Server Configuration
57+
58+
Spring Security <<http-proxy-servers,integrates with proxy servers>>.

docs/manual/src/docs/asciidoc/_includes/reactive/exploits/index.adoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@ include::csrf.adoc[leveloffset=+1]
44

55
include::headers.adoc[leveloffset=+1]
66

7-
include::redirect-https.adoc[leveloffset=+1]
7+
include::http.adoc[leveloffset=+1]

docs/manual/src/docs/asciidoc/_includes/servlet/appendix/index.adoc

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,4 @@ include::namespace.adoc[]
77

88
include::dependencies.adoc[]
99

10-
include::proxy-server.adoc[]
11-
1210
include::faq.adoc[]

docs/manual/src/docs/asciidoc/_includes/servlet/exploits/channel.adoc

Lines changed: 0 additions & 33 deletions
This file was deleted.
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
[[servlet-http]]
2+
= HTTP
3+
4+
All HTTP based communication should be protected <<http,using TLS>>.
5+
6+
Below you can find details around Servlet specific features that assist with HTTPS usage.
7+
8+
[[servlet-http-redirect]]
9+
== Redirect to HTTPS
10+
11+
If a client makes a request using HTTP rather than HTTPS, Spring Security can be configured to redirect to HTTPS.
12+
13+
For example, the following Java configuration will redirect any HTTP requests to HTTPS:
14+
15+
.Redirect to HTTPS with Java Configuration
16+
====
17+
[source,java]
18+
----
19+
@Configuration
20+
@EnableWebSecurity
21+
public class WebSecurityConfig extends
22+
WebSecurityConfigurerAdapter {
23+
24+
@Override
25+
protected void configure(HttpSecurity http) {
26+
http
27+
// ...
28+
.requiresChannel(channel ->
29+
channel
30+
.anyRequest().requiresSecure()
31+
);
32+
}
33+
}
34+
----
35+
====
36+
37+
The following XML configuration will redirect all HTTP requests to HTTPS
38+
39+
.Redirect to HTTPS with XML Configuration
40+
====
41+
[source,xml]
42+
----
43+
<http>
44+
<intercept-url pattern="/**" access="ROLE_USER" requires-channel="https"/>
45+
...
46+
</http>
47+
----
48+
====
49+
50+
51+
[[servlet-hsts]]
52+
== Strict Transport Security
53+
54+
Spring Security provides support for <<servlet-headers-hsts,Strict Transport Security>> and enables it by default.
55+
56+
[[servlet-http-proxy-server]]
57+
== Proxy Server Configuration
58+
59+
Spring Security <<http-proxy-servers,integrates with proxy servers>>.

docs/manual/src/docs/asciidoc/_includes/servlet/exploits/index.adoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@ include::csrf.adoc[leveloffset=+1]
44

55
include::headers.adoc[leveloffset=+1]
66

7-
include::channel.adoc[leveloffset=+1]
7+
include::http.adoc[leveloffset=+1]

0 commit comments

Comments
 (0)