Skip to content

Commit f66a5ba

Browse files
committed
Merge branch '5.8.x' into 6.0.x
Closes gh-13406
2 parents be0c2bd + 7da99ac commit f66a5ba

File tree

116 files changed

+4826
-3206
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

116 files changed

+4826
-3206
lines changed

docs/modules/ROOT/pages/features/authentication/password-storage.adoc

Lines changed: 83 additions & 61 deletions
Large diffs are not rendered by default.

docs/modules/ROOT/pages/features/exploits/csrf.adoc

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ Assume that your bank's website provides a form that allows transferring money f
2525
For example, the transfer form might look like:
2626

2727
.Transfer form
28-
====
2928
[source,html]
3029
----
3130
<form method="post"
@@ -40,12 +39,10 @@ For example, the transfer form might look like:
4039
value="Transfer"/>
4140
</form>
4241
----
43-
====
4442

4543
The corresponding HTTP request might look like:
4644

4745
.Transfer HTTP request
48-
====
4946
[source]
5047
----
5148
POST /transfer HTTP/1.1
@@ -55,13 +52,11 @@ Content-Type: application/x-www-form-urlencoded
5552
5653
amount=100.00&routingNumber=1234&account=9876
5754
----
58-
====
5955

6056
Now pretend you authenticate to your bank's website and then, without logging out, visit an evil website.
6157
The evil website contains an HTML page with the following form:
6258

6359
.Evil transfer form
64-
====
6560
[source,html]
6661
----
6762
<form method="post"
@@ -79,7 +74,6 @@ The evil website contains an HTML page with the following form:
7974
value="Win Money!"/>
8075
</form>
8176
----
82-
====
8377

8478
You like to win money, so you click on the submit button.
8579
In the process, you have unintentionally transferred $100 to a malicious user.
@@ -134,7 +128,6 @@ Assume that the actual CSRF token is required to be in an HTTP parameter named `
134128
Our application's transfer form would look like:
135129

136130
.Synchronizer Token Form
137-
====
138131
[source,html]
139132
----
140133
<form method="post"
@@ -152,15 +145,13 @@ Our application's transfer form would look like:
152145
value="Transfer"/>
153146
</form>
154147
----
155-
====
156148

157149
The form now contains a hidden input with the value of the CSRF token.
158150
External sites cannot read the CSRF token since the same origin policy ensures the evil site cannot read the response.
159151

160152
The corresponding HTTP request to transfer money would look like this:
161153

162154
.Synchronizer Token request
163-
====
164155
[source]
165156
----
166157
POST /transfer HTTP/1.1
@@ -170,7 +161,6 @@ Content-Type: application/x-www-form-urlencoded
170161
171162
amount=100.00&routingNumber=1234&account=9876&_csrf=4bfd1575-3ad1-4d21-96c7-4ef2d9f86721
172163
----
173-
====
174164

175165

176166
You will notice that the HTTP request now contains the `_csrf` parameter with a secure random value.
@@ -191,12 +181,10 @@ Spring Framework's https://docs.spring.io/spring-framework/docs/current/javadoc-
191181
An example, of an HTTP response header with the `SameSite` attribute might look like:
192182

193183
.SameSite HTTP response
194-
====
195184
[source]
196185
----
197186
Set-Cookie: JSESSIONID=randomid; Domain=bank.example.com; Secure; HttpOnly; SameSite=Lax
198187
----
199-
====
200188

201189
Valid values for the `SameSite` attribute are:
202190

@@ -245,7 +233,6 @@ However, you must be very careful, as there are CSRF exploits that can impact JS
245233
For example, a malicious user can create a http://blog.opensecurityresearch.com/2012/02/json-csrf-with-parameter-padding.html[CSRF with JSON by using the following form]:
246234

247235
.CSRF with JSON form
248-
====
249236
[source,html]
250237
----
251238
<form action="https://bank.example.com/transfer" method="post" enctype="text/plain">
@@ -254,13 +241,11 @@ For example, a malicious user can create a http://blog.opensecurityresearch.com/
254241
value="Win Money!"/>
255242
</form>
256243
----
257-
====
258244

259245

260246
This produces the following JSON structure
261247

262248
.CSRF with JSON request
263-
====
264249
[source,javascript]
265250
----
266251
{ "amount": 100,
@@ -269,13 +254,11 @@ This produces the following JSON structure
269254
"ignore_me": "=test"
270255
}
271256
----
272-
====
273257

274258
If an application were not validating the `Content-Type` header, it would be exposed to this exploit.
275259
Depending on the setup, a Spring MVC application that validates the Content-Type could still be exploited by updating the URL suffix to end with `.json`, as follows:
276260

277261
.CSRF with JSON Spring MVC form
278-
====
279262
[source,html]
280263
----
281264
<form action="https://bank.example.com/transfer.json" method="post" enctype="text/plain">
@@ -284,7 +267,6 @@ Depending on the setup, a Spring MVC application that validates the Content-Type
284267
value="Win Money!"/>
285268
</form>
286269
----
287-
====
288270

289271
[[csrf-when-stateless]]
290272
=== CSRF and Stateless Browser Applications
@@ -394,7 +376,6 @@ Some applications can use a form parameter to override the HTTP method.
394376
For example, the following form can treat the HTTP method as a `delete` rather than a `post`.
395377

396378
.CSRF Hidden HTTP Method Form
397-
====
398379
[source,html]
399380
----
400381
<form action="/process"
@@ -405,7 +386,6 @@ For example, the following form can treat the HTTP method as a `delete` rather t
405386
value="delete"/>
406387
</form>
407388
----
408-
====
409389

410390

411391
Overriding the HTTP method occurs in a filter.

docs/modules/ROOT/pages/features/exploits/headers.adoc

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ Spring Security provides a default set of security related HTTP response headers
2424
The default for Spring Security is to include the following headers:
2525

2626
.Default Security HTTP Response Headers
27-
====
2827
[source,http]
2928
----
3029
Cache-Control: no-cache, no-store, max-age=0, must-revalidate
@@ -35,7 +34,6 @@ Strict-Transport-Security: max-age=31536000 ; includeSubDomains
3534
X-Frame-Options: DENY
3635
X-XSS-Protection: 0
3736
----
38-
====
3937

4038
[NOTE]
4139
====
@@ -65,14 +63,12 @@ If a user authenticates to view sensitive information and then logs out, we do n
6563
The cache control headers that are sent by default are:
6664

6765
.Default Cache Control HTTP Response Headers
68-
====
6966
[source]
7067
----
7168
Cache-Control: no-cache, no-store, max-age=0, must-revalidate
7269
Pragma: no-cache
7370
Expires: 0
7471
----
75-
====
7672

7773
To be secure by default, Spring Security adds these headers by default.
7874
However, if your application provides its own cache control headers, Spring Security backs out of the way.
@@ -105,12 +101,10 @@ A malicious user might create a http://webblaze.cs.berkeley.edu/papers/barth-cab
105101
By default, Spring Security disables content sniffing by adding the following header to HTTP responses:
106102

107103
.nosniff HTTP Response Header
108-
====
109104
[source,http]
110105
----
111106
X-Content-Type-Options: nosniff
112107
----
113-
====
114108

115109
[[headers-hsts]]
116110
== HTTP Strict Transport Security (HSTS)
@@ -140,12 +134,10 @@ For example, Spring Security's default behavior is to add the following header,
140134

141135

142136
.Strict Transport Security HTTP Response Header
143-
====
144137
[source]
145138
----
146139
Strict-Transport-Security: max-age=31536000 ; includeSubDomains ; preload
147140
----
148-
====
149141

150142
The optional `includeSubDomains` directive instructs the browser that subdomains (such as `secure.mybank.example.com`) should also be treated as an HSTS domain.
151143

@@ -193,12 +185,10 @@ While not perfect, the frame breaking code is the best you can do for the legacy
193185
A more modern approach to address clickjacking is to use https://developer.mozilla.org/en-US/docs/HTTP/X-Frame-Options[X-Frame-Options] header.
194186
By default, Spring Security disables rendering pages within an iframe by using with the following header:
195187

196-
====
197188
[source]
198189
----
199190
X-Frame-Options: DENY
200191
----
201-
====
202192

203193
[[headers-xss-protection]]
204194
== X-XSS-Protection
@@ -213,12 +203,10 @@ The filter has been deprecated in major browsers, and https://cheatsheetseries.o
213203

214204
By default, Spring Security blocks the content by using the following header:
215205

216-
====
217206
[source]
218207
----
219208
X-XSS-Protection: 0
220209
----
221-
====
222210

223211

224212
[[headers-csp]]
@@ -250,25 +238,21 @@ A security policy contains a set of security policy directives, each responsible
250238
For example, a web application can declare that it expects to load scripts from specific, trusted sources by including the following header in the response:
251239

252240
.Content Security Policy Example
253-
====
254241
[source]
255242
----
256243
Content-Security-Policy: script-src https://trustedscripts.example.com
257244
----
258-
====
259245

260246
An attempt to load a script from another source other than what is declared in the `script-src` directive is blocked by the user-agent.
261247
Additionally, if the https://www.w3.org/TR/CSP2/#directive-report-uri[report-uri] directive is declared in the security policy, the violation will be reported by the user-agent to the declared URL.
262248

263249
For example, if a web application violates the declared security policy, the following response header instructs the user-agent to send violation reports to the URL specified in the policy's `report-uri` directive.
264250

265251
.Content Security Policy with report-uri
266-
====
267252
[source]
268253
----
269254
Content-Security-Policy: script-src https://trustedscripts.example.com; report-uri /csp-report-endpoint/
270255
----
271-
====
272256

273257
https://www.w3.org/TR/CSP2/#violation-reports[Violation reports] are standard JSON structures that can be captured either by the web application's own API or by a publicly hosted CSP violation reporting service, such as https://report-uri.io/.
274258

@@ -279,12 +263,10 @@ When a policy is deemed effective, it can be enforced by using the `Content-Secu
279263
Given the following response header, the policy declares that scripts can be loaded from one of two possible sources.
280264

281265
.Content Security Policy Report Only
282-
====
283266
[source]
284267
----
285268
Content-Security-Policy-Report-Only: script-src 'self' https://trustedscripts.example.com; report-uri /csp-report-endpoint/
286269
----
287-
====
288270

289271
If the site violates this policy, by attempting to load a script from `evil.example.com`, the user-agent sends a violation report to the declared URL specified by the `report-uri` directive but still lets the violating resource load.
290272

@@ -311,12 +293,10 @@ page the user was on.
311293
Spring Security's approach is to use the https://www.w3.org/TR/referrer-policy/[Referrer Policy] header, which provides different https://www.w3.org/TR/referrer-policy/#referrer-policies[policies]:
312294

313295
.Referrer Policy Example
314-
====
315296
[source]
316297
----
317298
Referrer-Policy: same-origin
318299
----
319-
====
320300

321301
The Referrer-Policy response header instructs the browser to let the destination knows the source where the user was previously.
322302

@@ -331,12 +311,10 @@ See the relevant sections to see how to configure both xref:servlet/exploits/hea
331311
https://wicg.github.io/feature-policy/[Feature Policy] is a mechanism that lets web developers to selectively enable, disable, and modify the behavior of certain APIs and web features in the browser.
332312

333313
.Feature Policy Example
334-
====
335314
[source]
336315
----
337316
Feature-Policy: geolocation 'self'
338317
----
339-
====
340318

341319
With Feature Policy, developers can opt-in to a set of "`policies`" for the browser to enforce on specific features used throughout your site.
342320
These policies restrict what APIs the site can access or modify the browser's default behavior for certain features.
@@ -353,12 +331,10 @@ See the relevant sections to see how to configure both xref:servlet/exploits/hea
353331
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.
354332

355333
.Permissions Policy Example
356-
====
357334
[source]
358335
----
359336
Permissions-Policy: geolocation=(self)
360337
----
361-
====
362338

363339
With Permissions Policy, developers can opt-in to a set of "policies" for the browser to enforce on specific features used throughout your site.
364340
These policies restrict what APIs the site can access or modify the browser's default behavior for certain features.
@@ -374,12 +350,10 @@ See the relevant sections to see how to configure both xref:servlet/exploits/hea
374350

375351
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:
376352

377-
====
378353
[source]
379354
----
380355
Clear-Site-Data: "cache", "cookies", "storage", "executionContexts"
381356
----
382-
====
383357

384358
This is a nice clean-up action to perform on logout.
385359

0 commit comments

Comments
 (0)