@@ -1073,12 +1073,14 @@ application returns these headers for every HTTP response.
1073
1073
1074
1074
#### ` X-Frame-Options `
1075
1075
1076
- This header indicates if a browser can render the page in a ` <frame> ` ,
1076
+ The [ ` X-Frame-Options ` ] [ ] header indicates if a browser can render the page in a ` <frame> ` ,
1077
1077
` <iframe> ` , ` <embed> ` or ` <object> ` tag. This header is set to ` SAMEORIGIN ` by
1078
1078
default to allow framing on the same domain only. Set it to ` DENY ` to deny
1079
1079
framing at all, or remove this header completely if you want to allow framing on
1080
1080
all domains.
1081
1081
1082
+ [ `X-Frame-Options` ] : https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-Frame-Options
1083
+
1082
1084
#### ` X-XSS-Protection `
1083
1085
1084
1086
A [ deprecated legacy
@@ -1087,8 +1089,10 @@ header](https://owasp.org/www-project-secure-headers/#x-xss-protection), set to
1087
1089
1088
1090
#### ` X-Content-Type-Options `
1089
1091
1090
- This header is set to ` nosniff ` in Rails by default. It stops the browser from
1091
- guessing the MIME type of a file.
1092
+ The [ ` X-Content-Type-Options ` ] [ ] header is set to ` nosniff ` in Rails by default.
1093
+ It stops the browser from guessing the MIME type of a file.
1094
+
1095
+ [ `X-Content-Type-Options` ] : https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-Content-Type-Options
1092
1096
1093
1097
#### ` X-Permitted-Cross-Domain-Policies `
1094
1098
@@ -1097,11 +1101,13 @@ PDF clients from embedding your page on other domains.
1097
1101
1098
1102
#### ` Referrer-Policy `
1099
1103
1100
- This header is set to ` strict-origin-when-cross-origin ` in Rails by default.
1104
+ The [ ` Referrer-Policy ` ] [ ] header is set to ` strict-origin-when-cross-origin ` in Rails by default.
1101
1105
For cross-origin requests, this only sends the origin in the Referer header. This
1102
1106
prevents leaks of private data that may be accessible from other parts of the
1103
1107
full URL, such as the path and query string.
1104
1108
1109
+ [ `Referrer-Policy` ] : https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Referrer-Policy
1110
+
1105
1111
#### Configuring the Default Headers
1106
1112
1107
1113
These headers are configured by default as follows:
@@ -1131,23 +1137,22 @@ config.action_dispatch.default_headers.clear
1131
1137
1132
1138
### ` Strict-Transport-Security ` Header
1133
1139
1134
- The HTTP
1135
- [ ` Strict-Transport-Security ` ] ( https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Strict-Transport-Security )
1136
- (HTST) response header makes sure the browser automatically upgrades to HTTPS
1137
- for current and future connections.
1140
+ The HTTP [ ` Strict-Transport-Security ` ] [ ] (HTST) response header makes sure the
1141
+ browser automatically upgrades to HTTPS for current and future connections.
1138
1142
1139
1143
The header is added to the response when enabling the ` force_ssl ` option:
1140
1144
1141
1145
``` ruby
1142
1146
config.force_ssl = true
1143
1147
```
1144
1148
1149
+ [ `Strict-Transport-Security` ] : https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Strict-Transport-Security
1150
+
1145
1151
### ` Content-Security-Policy ` Header
1146
1152
1147
1153
To help protect against XSS and injection attacks, it is recommended to define a
1148
- [ ` Content-Security-Policy ` ] ( https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy )
1149
- response header for your application. Rails provides a DSL that allows you to
1150
- configure the header.
1154
+ [ ` Content-Security-Policy ` ] [ ] response header for your application. Rails
1155
+ provides a DSL that allows you to configure the header.
1151
1156
1152
1157
Define the security policy in the appropriate initializer:
1153
1158
@@ -1195,11 +1200,11 @@ class PostsController < ApplicationController
1195
1200
end
1196
1201
```
1197
1202
1203
+ [ `Content-Security-Policy` ] : https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy
1204
+
1198
1205
#### Reporting Violations
1199
1206
1200
- Enable the
1201
- [ ` report-uri ` ] ( https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy/report-uri )
1202
- directive to report violations to the specified URI:
1207
+ Enable the [ ` report-uri ` ] [ ] directive to report violations to the specified URI:
1203
1208
1204
1209
``` ruby
1205
1210
Rails .application.config.content_security_policy do |policy |
@@ -1208,8 +1213,7 @@ end
1208
1213
```
1209
1214
1210
1215
When migrating legacy content, you might want to report violations without
1211
- enforcing the policy. Set the
1212
- [ ` Content-Security-Policy-Report-Only ` ] ( https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy-Report-Only )
1216
+ enforcing the policy. Set the [ ` Content-Security-Policy-Report-Only ` ] [ ]
1213
1217
response header to only report violations:
1214
1218
1215
1219
``` ruby
@@ -1224,6 +1228,9 @@ class PostsController < ApplicationController
1224
1228
end
1225
1229
```
1226
1230
1231
+ [ `Content-Security-Policy-Report-Only` ] : https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy-Report-Only
1232
+ [ `report-uri` ] : https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy/report-uri
1233
+
1227
1234
#### Adding a Nonce
1228
1235
1229
1236
If you are considering ` 'unsafe-inline' ` , consider using nonces instead. [ Nonces
@@ -1299,8 +1306,7 @@ yet supported by all browsers. To avoid having to rename this
1299
1306
middleware in the future, we use the new name for the middleware but
1300
1307
keep the old header name and implementation for now.
1301
1308
1302
- To allow or block the use of browser features, you can define a
1303
- [ ` Feature-Policy ` ] ( https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Feature-Policy )
1309
+ To allow or block the use of browser features, you can define a [ ` Feature-Policy ` ] [ ]
1304
1310
response header for your application. Rails provides a DSL that allows you to
1305
1311
configure the header.
1306
1312
@@ -1328,6 +1334,8 @@ class PagesController < ApplicationController
1328
1334
end
1329
1335
```
1330
1336
1337
+ [ `Feature-Policy` ] : https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Feature-Policy
1338
+
1331
1339
Environmental Security
1332
1340
----------------------
1333
1341
0 commit comments