Skip to content

Commit 7bcee19

Browse files
Add MDN links for security headers [ci-skip]
1 parent 589bc96 commit 7bcee19

File tree

1 file changed

+26
-18
lines changed

1 file changed

+26
-18
lines changed

guides/source/security.md

Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1073,12 +1073,14 @@ application returns these headers for every HTTP response.
10731073

10741074
#### `X-Frame-Options`
10751075

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>`,
10771077
`<iframe>`, `<embed>` or `<object>` tag. This header is set to `SAMEORIGIN` by
10781078
default to allow framing on the same domain only. Set it to `DENY` to deny
10791079
framing at all, or remove this header completely if you want to allow framing on
10801080
all domains.
10811081

1082+
[`X-Frame-Options`]: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-Frame-Options
1083+
10821084
#### `X-XSS-Protection`
10831085

10841086
A [deprecated legacy
@@ -1087,8 +1089,10 @@ header](https://owasp.org/www-project-secure-headers/#x-xss-protection), set to
10871089

10881090
#### `X-Content-Type-Options`
10891091

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
10921096

10931097
#### `X-Permitted-Cross-Domain-Policies`
10941098

@@ -1097,11 +1101,13 @@ PDF clients from embedding your page on other domains.
10971101

10981102
#### `Referrer-Policy`
10991103

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.
11011105
For cross-origin requests, this only sends the origin in the Referer header. This
11021106
prevents leaks of private data that may be accessible from other parts of the
11031107
full URL, such as the path and query string.
11041108

1109+
[`Referrer-Policy`]: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Referrer-Policy
1110+
11051111
#### Configuring the Default Headers
11061112

11071113
These headers are configured by default as follows:
@@ -1131,23 +1137,22 @@ config.action_dispatch.default_headers.clear
11311137

11321138
### `Strict-Transport-Security` Header
11331139

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.
11381142

11391143
The header is added to the response when enabling the `force_ssl` option:
11401144

11411145
```ruby
11421146
config.force_ssl = true
11431147
```
11441148

1149+
[`Strict-Transport-Security`]: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Strict-Transport-Security
1150+
11451151
### `Content-Security-Policy` Header
11461152

11471153
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.
11511156

11521157
Define the security policy in the appropriate initializer:
11531158

@@ -1195,11 +1200,11 @@ class PostsController < ApplicationController
11951200
end
11961201
```
11971202

1203+
[`Content-Security-Policy`]: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy
1204+
11981205
#### Reporting Violations
11991206

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:
12031208

12041209
```ruby
12051210
Rails.application.config.content_security_policy do |policy|
@@ -1208,8 +1213,7 @@ end
12081213
```
12091214

12101215
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`][]
12131217
response header to only report violations:
12141218

12151219
```ruby
@@ -1224,6 +1228,9 @@ class PostsController < ApplicationController
12241228
end
12251229
```
12261230

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+
12271234
#### Adding a Nonce
12281235

12291236
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
12991306
middleware in the future, we use the new name for the middleware but
13001307
keep the old header name and implementation for now.
13011308

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`][]
13041310
response header for your application. Rails provides a DSL that allows you to
13051311
configure the header.
13061312

@@ -1328,6 +1334,8 @@ class PagesController < ApplicationController
13281334
end
13291335
```
13301336

1337+
[`Feature-Policy`]: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Feature-Policy
1338+
13311339
Environmental Security
13321340
----------------------
13331341

0 commit comments

Comments
 (0)