Skip to content

Commit 0cf95db

Browse files
committed
Merge branch '5.6.x' into 5.7.x
Closes gh-13404
2 parents 0a022a3 + 39c4315 commit 0cf95db

File tree

96 files changed

+4418
-2667
lines changed

Some content is hidden

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

96 files changed

+4418
-2667
lines changed

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

+83-55
Large diffs are not rendered by default.

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

-20
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 the actual CSRF token is required to be in an HTTP parameter named `_csrf
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, 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 JSO
245233
For example, a malicious user can create a http://blog.opensecurityresearch.com/2012/02/json-csrf-with-parameter-padding.html[CSRF with JSON 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 will produce the following JSON structure
261247

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

274258
If an application were not validating the Content-Type, then 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 shown below:
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
@@ -393,7 +375,6 @@ In some applications a form parameter can be used to override the HTTP method.
393375
For example, the form below could be used to treat the HTTP method as a `delete` rather than a `post`.
394376

395377
.CSRF Hidden HTTP Method Form
396-
====
397378
[source,html]
398379
----
399380
<form action="/process"
@@ -404,7 +385,6 @@ For example, the form below could be used to treat the HTTP method as a `delete`
404385
value="delete"/>
405386
</form>
406387
----
407-
====
408388

409389

410390
Overriding the HTTP method occurs in a filter.

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

-20
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: 1; mode=block
3736
----
38-
====
3937

4038
NOTE: Strict-Transport-Security is only added on HTTPS requests
4139

@@ -62,14 +60,12 @@ If a user authenticates to view sensitive information and then logs out, we don'
6260
The cache control headers that are sent by default are:
6361

6462
.Default Cache Control HTTP Response Headers
65-
====
6663
[source]
6764
----
6865
Cache-Control: no-cache, no-store, max-age=0, must-revalidate
6966
Pragma: no-cache
7067
Expires: 0
7168
----
72-
====
7369

7470
In order to be secure by default, Spring Security adds these headers by default.
7571
However, if your application provides its own cache control headers Spring Security will back out of the way.
@@ -102,12 +98,10 @@ A malicious user might create a http://webblaze.cs.berkeley.edu/papers/barth-cab
10298
Spring Security disables content sniffing by default by adding the following header to HTTP responses:
10399

104100
.nosniff HTTP Response Header
105-
====
106101
[source,http]
107102
----
108103
X-Content-Type-Options: nosniff
109104
----
110-
====
111105

112106
[[headers-hsts]]
113107
== HTTP Strict Transport Security (HSTS)
@@ -137,12 +131,10 @@ For example, Spring Security's default behavior is to add the following header w
137131

138132

139133
.Strict Transport Security HTTP Response Header
140-
====
141134
[source]
142135
----
143136
Strict-Transport-Security: max-age=31536000 ; includeSubDomains ; preload
144137
----
145-
====
146138

147139
The optional `includeSubDomains` directive instructs the browser that subdomains (e.g. secure.mybank.example.com) should also be treated as an HSTS domain.
148140

@@ -247,25 +239,21 @@ A security policy contains a set of security policy directives, each responsible
247239
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:
248240

249241
.Content Security Policy Example
250-
====
251242
[source]
252243
----
253244
Content-Security-Policy: script-src https://trustedscripts.example.com
254245
----
255-
====
256246

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

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

262252
.Content Security Policy with report-uri
263-
====
264253
[source]
265254
----
266255
Content-Security-Policy: script-src https://trustedscripts.example.com; report-uri /csp-report-endpoint/
267256
----
268-
====
269257

270258
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.com/.
271259

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

278266
.Content Security Policy Report Only
279-
====
280267
[source]
281268
----
282269
Content-Security-Policy-Report-Only: script-src 'self' https://trustedscripts.example.com; report-uri /csp-report-endpoint/
283270
----
284-
====
285271

286272
If the site violates this policy, by attempting to load a script from _evil.com_, the user-agent will send a violation report to the declared URL specified by the _report-uri_ directive, but still allow the violating resource to load nevertheless.
287273

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

310296
.Referrer Policy Example
311-
====
312297
[source]
313298
----
314299
Referrer-Policy: same-origin
315300
----
316-
====
317301

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

@@ -328,12 +312,10 @@ Refer to the relevant sections to see how to configure both xref:servlet/exploit
328312
https://wicg.github.io/feature-policy/[Feature Policy] is a mechanism that allows web developers to selectively enable, disable, and modify the behavior of certain APIs and web features in the browser.
329313

330314
.Feature Policy Example
331-
====
332315
[source]
333316
----
334317
Feature-Policy: geolocation 'self'
335318
----
336-
====
337319

338320
With Feature Policy, developers can opt-in to a set of "policies" for the browser to enforce on specific features used throughout your site.
339321
These policies restrict what APIs the site can access or modify the browser's default behavior for certain features.
@@ -350,12 +332,10 @@ Refer to the relevant sections to see how to configure both xref:servlet/exploit
350332
https://w3c.github.io/webappsec-permissions-policy/[Permissions Policy] is a mechanism that allows web developers to selectively enable, disable, and modify the behavior of certain APIs and web features in the browser.
351333

352334
.Permissions Policy Example
353-
====
354335
[source]
355336
----
356337
Permissions-Policy: geolocation=(self)
357338
----
358-
====
359339

360340
With Permissions Policy, developers can opt-in to a set of "policies" for the browser to enforce on specific features used throughout your site.
361341
These policies restrict what APIs the site can access or modify the browser's default behavior for certain features.

0 commit comments

Comments
 (0)