You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/manual/src/docs/asciidoc/_includes/about/authentication/password-storage.adoc
+10-6Lines changed: 10 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -146,15 +146,15 @@ All of the original passwords are `password`.
146
146
----
147
147
====
148
148
149
-
<1> The first password has a `PasswordEncoder` id of `bcrypt` and an encoded password value of `$2a$10$dXJ3SW6G7P50lGmMkkmwe.20cQQubK3.HZWzG3YB1tlRy.fqvM/BG`.
149
+
<1> The first password has a `PasswordEncoder` id of `bcrypt` and an `encodedPassword` value of `$2a$10$dXJ3SW6G7P50lGmMkkmwe.20cQQubK3.HZWzG3YB1tlRy.fqvM/BG`.
150
150
When matching, it would delegate to `BCryptPasswordEncoder`
151
-
<2> The second password has a `PasswordEncoder` id of `noop` and encoded password value of `password`.
151
+
<2> The second password has a `PasswordEncoder` id of `noop` and `encodedPassword` value of `password`.
152
152
When matching, it would delegate to `NoOpPasswordEncoder`
153
-
<3> The third password has a `PasswordEncoder` id of `pbkdf2` and encoded password value of `5d923b44a6d129f3ddf3e3c8d29412723dcbde72445e8ef6bf3b508fbf17fa4ed4d6b99ca763d8dc`.
153
+
<3> The third password has a `PasswordEncoder` id of `pbkdf2` and `encodedPassword` value of `5d923b44a6d129f3ddf3e3c8d29412723dcbde72445e8ef6bf3b508fbf17fa4ed4d6b99ca763d8dc`.
154
154
When matching, it would delegate to `Pbkdf2PasswordEncoder`
155
-
<4> The fourth password has a `PasswordEncoder` id of `scrypt` and encoded password value of `$e0801$8bWJaSu2IKSn9Z9kM+TPXfOc/9bdYSrN1oD9qfVThWEwdRTnO7re7Ei+fUZRJ68k9lTyuTeUp4of4g24hHnazw==$OAOec05+bXxvuu/1qZ6NUR+xQYvYv7BeL1QxwRpY5Pc=`
155
+
<4> The fourth password has a `PasswordEncoder` id of `scrypt` and `encodedPassword` value of `$e0801$8bWJaSu2IKSn9Z9kM+TPXfOc/9bdYSrN1oD9qfVThWEwdRTnO7re7Ei+fUZRJ68k9lTyuTeUp4of4g24hHnazw==$OAOec05+bXxvuu/1qZ6NUR+xQYvYv7BeL1QxwRpY5Pc=`
156
156
When matching, it would delegate to `SCryptPasswordEncoder`
157
-
<5> The final password has a `PasswordEncoder` id of `sha256` and encoded password value of `97cde38028ad898ebc02e690819fa220e88c62e0699403e94fff291cfffaf8410849f27605abcbc0`.
157
+
<5> The final password has a `PasswordEncoder` id of `sha256` and `encodedPassword` value of `97cde38028ad898ebc02e690819fa220e88c62e0699403e94fff291cfffaf8410849f27605abcbc0`.
158
158
When matching, it would delegate to `StandardPasswordEncoder`
159
159
160
160
[NOTE]
@@ -487,4 +487,8 @@ fun passwordEncoder(): PasswordEncoder {
487
487
----
488
488
====
489
489
490
-
NOTE: XML Configuration requires the `NoOpPasswordEncoder` bean name to be `passwordEncoder`.
490
+
491
+
[NOTE]
492
+
====
493
+
XML Configuration requires the `NoOpPasswordEncoder` bean name to be `passwordEncoder`.
Copy file name to clipboardExpand all lines: docs/manual/src/docs/asciidoc/_includes/about/exploits/csrf.adoc
+20-5Lines changed: 20 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -8,8 +8,11 @@ In the following sections, we explore:
8
8
* <<csrf-protection>>
9
9
* <<csrf-considerations>>
10
10
11
-
NOTE: This portion of the documentation discusses the general topic of CSRF protection.
11
+
[NOTE]
12
+
====
13
+
This portion of the documentation discusses the general topic of CSRF protection.
12
14
See the relevant sections for specific information on CSRF protection for <<servlet-csrf,servlet>>- and <<webflux-csrf,WebFlux>>-based applications.
15
+
====
13
16
14
17
[[csrf-explained]]
15
18
== What is a CSRF Attack?
@@ -95,7 +98,10 @@ Spring provides two mechanisms to protect against CSRF attacks:
95
98
* The <<Synchronizer Token Pattern>>
96
99
* Specifying the <<SameSite Attribute>> on your session cookie
97
100
98
-
NOTE: Both protections require that <<csrf-protection-idempotent,Safe Methods be Idempotent>>.
101
+
[NOTE]
102
+
====
103
+
Both protections require that <<csrf-protection-idempotent,Safe Methods be Idempotent>>.
104
+
====
99
105
100
106
[[csrf-protection-idempotent]]
101
107
=== Safe Methods Must be Idempotent
@@ -172,9 +178,12 @@ The evil website cannot provide the correct value for the `_csrf` parameter (whi
172
178
An emerging way to protect against <<csrf,CSRF Attacks>> is to specify the https://tools.ietf.org/html/draft-west-first-party-cookies[SameSite Attribute] on cookies.
173
179
A server can specify the `SameSite` attribute when setting a cookie to indicate that the cookie should not be sent when coming from external sites.
174
180
175
-
NOTE: Spring Security does not directly control the creation of the session cookie, so it does not provide support for the SameSite attribute.
181
+
[NOTE]
182
+
====
183
+
Spring Security does not directly control the creation of the session cookie, so it does not provide support for the SameSite attribute.
176
184
https://spring.io/projects/spring-session[Spring Session] provides support for the `SameSite` attribute in servlet-based applications.
177
185
Spring Framework's https://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/web/server/session/CookieWebSessionIdResolver.html[`CookieWebSessionIdResolver`] provides support for the `SameSite` attribute in WebFlux-based applications.
186
+
====
178
187
179
188
An example of an HTTP response header with the `SameSite` attribute might look like:
180
189
@@ -207,7 +216,10 @@ The user receives an email at https://email.example.org that includes a link to
207
216
If the user clicks on the link, they would rightfully expect to be authenticated to the social media site.
208
217
However, if the `SameSite` attribute is `Strict`, the cookie would not be sent and the user would not be authenticated.
209
218
210
-
NOTE: We could improve the protection and usability of `SameSite` protection against CSRF attacks by implementing https://github.com/spring-projects/spring-security/issues/7537[gh-7537].
219
+
[NOTE]
220
+
====
221
+
We could improve the protection and usability of `SameSite` protection against CSRF attacks by implementing https://github.com/spring-projects/spring-security/issues/7537[gh-7537].
222
+
====
211
223
212
224
Another obvious consideration is that, in order for the `SameSite` attribute to protect users, the browser must support the `SameSite` attribute.
213
225
Most modern browsers do https://developer.mozilla.org/en-US/docs/Web/HTTP/headers/Set-Cookie#Browser_compatibility[support the SameSite attribute].
@@ -351,8 +363,11 @@ There are two options to using CSRF protection with multipart/form-data:
351
363
352
364
Each option has its trade-offs.
353
365
354
-
NOTE: Before you integrate Spring Security's CSRF protection with multipart file upload, you should first ensure that you can upload without the CSRF protection.
366
+
[NOTE]
367
+
====
368
+
Before you integrate Spring Security's CSRF protection with multipart file upload, you should first ensure that you can upload without the CSRF protection.
355
369
More information about using multipart forms with Spring, see the https://docs.spring.io/spring/docs/5.2.x/spring-framework-reference/web.html#mvc-multipart[1.1.11. Multipart Resolver] section of the Spring reference and the https://docs.spring.io/spring/docs/5.2.x/javadoc-api/org/springframework/web/multipart/support/MultipartFilter.html[`MultipartFilter` Javadoc].
Copy file name to clipboardExpand all lines: docs/manual/src/docs/asciidoc/_includes/about/exploits/headers.adoc
+76-19Lines changed: 76 additions & 19 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,8 +1,11 @@
1
1
[[headers]]
2
2
= Security HTTP Response Headers
3
3
4
-
NOTE: This portion of the documentation discusses the general topic of Security HTTP Response Headers.
4
+
[NOTE]
5
+
====
6
+
This portion of the documentation discusses the general topic of Security HTTP Response Headers.
5
7
See the relevant sections for specific information on Security HTTP Response Headers in <<servlet-headers,servlet>>- and <<webflux-headers,WebFlux>>-based applications.
8
+
====
6
9
7
10
You can use https://www.owasp.org/index.php/OWASP_Secure_Headers_Project#tab=Headers[HTTP response headers] in many ways to increase the security of web applications.
8
11
This section is dedicated to the various HTTP response headers for which Spring Security provides explicit support.
@@ -11,7 +14,10 @@ If necessary, you can also configure Spring Security to provide <<headers-custom
11
14
[[headers-default]]
12
15
== Default Security Headers
13
16
14
-
NOTE: See the relevant sections for how to customize the defaults for both <<servlet-headers-default,servlet>>- and <<webflux-headers-default,webflux>>-based applications.
17
+
[NOTE]
18
+
====
19
+
See the relevant sections for how to customize the defaults for both <<servlet-headers-default,servlet>>- and <<webflux-headers-default,webflux>>-based applications.
20
+
====
15
21
16
22
Spring Security provides a default set of security related HTTP response headers to provide secure defaults.
NOTE: Strict-Transport-Security is added only on HTTPS requests
40
+
[NOTE]
41
+
====
42
+
Strict-Transport-Security is added only on HTTPS requests
43
+
====
35
44
36
45
If the defaults do not meet your needs, you can easily remove, modify, or add headers from these defaults.
37
46
For additional details on each of these headers, see the corresponding sections:
@@ -45,7 +54,10 @@ For additional details on each of these headers, see the corresponding sections:
45
54
[[headers-cache-control]]
46
55
== Cache Control
47
56
48
-
NOTE: See the relevant sections for how to customize the defaults for both <<servlet-headers-cache-control,servlet>>- and <<webflux-headers-cache-control,webflux>>-based applications.
57
+
[NOTE]
58
+
====
59
+
See the relevant sections for how to customize the defaults for both <<servlet-headers-cache-control,servlet>>- and <<webflux-headers-cache-control,webflux>>-based applications.
60
+
====
49
61
50
62
Spring Security's default is to disable caching to protect the user's content.
51
63
@@ -70,15 +82,21 @@ This allows for applications to ensure that static resources (such as CSS and Ja
70
82
[[headers-content-type-options]]
71
83
== Content Type Options
72
84
73
-
NOTE: See the relevant sections for how to customize the defaults for both <<servlet-headers-content-type-options,servlet>>- and <<webflux-headers-content-type-options,webflux>>-based applications.
85
+
[NOTE]
86
+
====
87
+
See the relevant sections for how to customize the defaults for both <<servlet-headers-content-type-options,servlet>>- and <<webflux-headers-content-type-options,webflux>>-based applications.
88
+
====
74
89
75
90
Historically, browsers, including Internet Explorer, would try to guess the content type of a request by using https://en.wikipedia.org/wiki/Content_sniffing[content sniffing].
76
91
This let browsers improve the user experience by guessing the content type on resources that had not specified the content type.
77
92
For example, if a browser encountered a JavaScript file that did not have the content type specified, it would be able to guess the content type and then run it.
78
93
79
-
NOTE: There are many additional things one should do (such as only display the document in a distinct domain, ensure Content-Type header is set, sanitize the document, and others) when allowing content to be uploaded.
94
+
[NOTE]
95
+
====
96
+
There are many additional things one should do (such as only display the document in a distinct domain, ensure Content-Type header is set, sanitize the document, and others) when allowing content to be uploaded.
80
97
However, these measures are out of the scope of what Spring Security provides.
81
98
It is also important to point out that, when disabling content sniffing, you must specify the content type in order for things to work properly.
99
+
====
82
100
83
101
The problem with content sniffing is that this allowed malicious users to use polyglots (that is, a file that is valid as multiple content types) to perform XSS attacks.
84
102
For example, some sites may allow users to submit a valid postscript document to a website and view it.
NOTE: Refer to the relevant sections to see how to customize the defaults for both <<servlet-headers-hsts,servlet>> and <<webflux-headers-hsts,webflux>> based applications.
118
+
[NOTE]
119
+
====
120
+
Refer to the relevant sections to see how to customize the defaults for both <<servlet-headers-hsts,servlet>> and <<webflux-headers-hsts,webflux>> based applications.
121
+
====
101
122
102
123
When you type in your bank's website, do you enter `mybank.example.com` or do you enter `https://mybank.example.com`?
103
124
If you omit the `https` protocol, you are potentially vulnerable to https://en.wikipedia.org/wiki/Man-in-the-middle_attack[Man-in-the-Middle attacks].
@@ -107,8 +128,11 @@ Many users omit the `https` protocol, and this is why https://tools.ietf.org/htm
107
128
Once `mybank.example.com` is added as a https://tools.ietf.org/html/rfc6797#section-5.1[HSTS host], a browser can know ahead of time that any request to mybank.example.com should be interpreted as https://mybank.example.com.
108
129
This greatly reduces the possibility of a Man-in-the-Middle attack occurring.
109
130
110
-
NOTE: In accordance with https://tools.ietf.org/html/rfc6797#section-7.2[RFC6797], the HSTS header is injected only into HTTPS responses.
131
+
[NOTE]
132
+
====
133
+
In accordance with https://tools.ietf.org/html/rfc6797#section-7.2[RFC6797], the HSTS header is injected only into HTTPS responses.
111
134
For the browser to acknowledge the header, the browser must first trust the CA that signed the SSL certificate used to make the connection (not just the SSL certificate).
135
+
====
112
136
113
137
One way for a site to be marked as a HSTS host is to have the host preloaded into the browser.
114
138
Another way is to add the `Strict-Transport-Security` header to the response.
@@ -131,7 +155,10 @@ For more details on HSTS preload, see https://hstspreload.org.
131
155
[[headers-hpkp]]
132
156
== HTTP Public Key Pinning (HPKP)
133
157
134
-
NOTE: To remain passive, Spring Security still provides <<servlet-headers-hpkp,support for HPKP in servlet environments>>. However, for the reasons listed earlier, HPKP is no longer recommended by the Spring Security team.
158
+
[NOTE]
159
+
====
160
+
To remain passive, Spring Security still provides <<servlet-headers-hpkp,support for HPKP in servlet environments>>. However, for the reasons listed earlier, HPKP is no longer recommended by the Spring Security team.
161
+
====
135
162
136
163
https://developer.mozilla.org/en-US/docs/Web/HTTP/Public_Key_Pinning[HTTP Public Key Pinning (HPKP)] specifies to a web client which public key to use with a certain web server to prevent Man-in-the-Middle (MITM) attacks with forged certificates.
137
164
When used correctly, HPKP could add additional layers of protection against compromised certificates.
@@ -143,14 +170,20 @@ For additional details around why HPKP is no longer recommended, read https://bl
143
170
[[headers-frame-options]]
144
171
== X-Frame-Options
145
172
146
-
NOTE: See the relevant sections to see how to customize the defaults for both <<servlet-headers-frame-options,servlet>> and <<webflux-headers-frame-options,webflux>> based applications.
173
+
[NOTE]
174
+
====
175
+
See the relevant sections to see how to customize the defaults for both <<servlet-headers-frame-options,servlet>> and <<webflux-headers-frame-options,webflux>> based applications.
176
+
====
147
177
148
178
Letting your website be added to a frame can be a security issue.
149
179
For example, by using clever CSS styling, users could be tricked into clicking on something that they were not intending.
150
180
For example, a user that is logged into their bank might click a button that grants access to other users.
151
181
This sort of attack is known as https://en.wikipedia.org/wiki/Clickjacking[Clickjacking].
152
182
153
-
NOTE: Another modern approach to dealing with clickjacking is to use <<headers-csp>>.
183
+
[NOTE]
184
+
====
185
+
Another modern approach to dealing with clickjacking is to use <<headers-csp>>.
186
+
====
154
187
155
188
There are a number ways to mitigate clickjacking attacks.
156
189
For example, to protect legacy browsers from clickjacking attacks, you can use https://www.owasp.org/index.php/Clickjacking_Defense_Cheat_Sheet#Best-for-now_Legacy_Browser_Frame_Breaking_Script[frame breaking code].
@@ -169,7 +202,10 @@ X-Frame-Options: DENY
169
202
[[headers-xss-protection]]
170
203
== X-XSS-Protection
171
204
172
-
NOTE: See the relevant sections to see how to customize the defaults for both <<servlet-headers-xss-protection,servlet>>- and <<webflux-headers-xss-protection,webflux>>-based applications.
205
+
[NOTE]
206
+
====
207
+
See the relevant sections to see how to customize the defaults for both <<servlet-headers-xss-protection,servlet>>- and <<webflux-headers-xss-protection,webflux>>-based applications.
208
+
====
173
209
174
210
Some browsers have built-in support for filtering out https://www.owasp.org/index.php/Testing_for_Reflected_Cross_site_scripting_(OWASP-DV-001)[reflected XSS attacks].
175
211
This is by no means foolproof but does assist in XSS protection.
NOTE: See the relevant sections to see how to configure both <<servlet-headers-csp,servlet>>- and <<webflux-headers-csp,webflux>>-based applications.
229
+
[NOTE]
230
+
====
231
+
See the relevant sections to see how to configure both <<servlet-headers-csp,servlet>>- and <<webflux-headers-csp,webflux>>-based applications.
232
+
====
194
233
195
234
https://www.w3.org/TR/CSP2/[Content Security Policy (CSP)] is a mechanism that web applications can use to mitigate content injection vulnerabilities, such as cross-site scripting (XSS).
196
235
CSP is a declarative policy that provides a facility for web application authors to declare and ultimately inform the client (user-agent) about the sources from which the web application expects to load resources.
197
236
198
-
NOTE: Content Security Policy is not intended to solve all content injection vulnerabilities.
237
+
[NOTE]
238
+
====
239
+
Content Security Policy is not intended to solve all content injection vulnerabilities.
199
240
Instead, you can use CSP to help reduce the harm caused by content injection attacks.
200
241
As a first line of defense, web application authors should validate their input and encode their output.
242
+
====
201
243
202
244
A web application can use CSP by including one of the following HTTP headers in the response:
NOTE: See the relevant sections to see how to configure both <<servlet-headers-referrer,servlet>>- and <<webflux-headers-referrer,webflux>>-based applications.
305
+
[NOTE]
306
+
====
307
+
See the relevant sections to see how to configure both <<servlet-headers-referrer,servlet>>- and <<webflux-headers-referrer,webflux>>-based applications.
308
+
====
264
309
265
310
https://www.w3.org/TR/referrer-policy[Referrer Policy] is a mechanism that web applications can use to manage the referrer field, which contains the last
266
311
page the user was on.
@@ -280,7 +325,10 @@ The Referrer-Policy response header instructs the browser to let the destination
280
325
[[headers-feature]]
281
326
== Feature Policy
282
327
283
-
NOTE: See the relevant sections to see how to configure both <<servlet-headers-feature,servlet>>- and <<webflux-headers-feature,webflux>>-based applications.
328
+
[NOTE]
329
+
====
330
+
See the relevant sections to see how to configure both <<servlet-headers-feature,servlet>>- and <<webflux-headers-feature,webflux>>-based applications.
331
+
====
284
332
285
333
https://wicg.github.io/feature-policy/[Feature Policy] is a mechanism that lets web developers selectively enable, disable, and modify the behavior of certain APIs and web features in the browser.
286
334
@@ -299,7 +347,10 @@ These policies restrict what APIs the site can access or modify the browser's de
299
347
[[headers-permissions]]
300
348
== Permissions Policy
301
349
302
-
NOTE: See the relevant sections to see how to configure both <<servlet-headers-permissions,servlet>>- and <<webflux-headers-permissions,webflux>>-based applications.
350
+
[NOTE]
351
+
====
352
+
See the relevant sections to see how to configure both <<servlet-headers-permissions,servlet>>- and <<webflux-headers-permissions,webflux>>-based applications.
353
+
====
303
354
304
355
https://w3c.github.io/webappsec-permissions-policy/[Permissions Policy] is a mechanism that lets web developers selectively enable, disable, and modify the behavior of certain APIs and web features in the browser.
305
356
@@ -318,7 +369,10 @@ These policies restrict what APIs the site can access or modify the browser's de
318
369
[[headers-clear-site-data]]
319
370
== Clear Site Data
320
371
321
-
NOTE: See the relevant sections to see how to configure both <<servlet-headers-clear-site-data,servlet>> and <<webflux-headers-clear-site-data,webflux>> based applications.
372
+
[NOTE]
373
+
====
374
+
See the relevant sections to see how to configure both <<servlet-headers-clear-site-data,servlet>> and <<webflux-headers-clear-site-data,webflux>> based applications.
375
+
====
322
376
323
377
https://www.w3.org/TR/clear-site-data/[Clear Site Data] is a mechanism by which any browser-side data (cookies, local storage, and the like) can be removed when an HTTP response contains this header:
324
378
@@ -335,7 +389,10 @@ This is a nice clean-up action to perform on logout.
335
389
[[headers-custom]]
336
390
== Custom Headers
337
391
338
-
NOTE: See the relevant sections to see how to configure both <<servlet-headers-custom,servlet>> based applications.
392
+
[NOTE]
393
+
====
394
+
See the relevant sections to see how to configure both <<servlet-headers-custom,servlet>> based applications.
395
+
====
339
396
340
397
Spring Security has mechanisms to make it convenient to add the more common security headers to your application.
341
398
However, it also provides hooks to enable adding custom headers.
0 commit comments