Skip to content

Commit d9dcaf7

Browse files
authored
Merge pull request rails#44512 from p8/guides/add-permission-policy-guide
Add Permissions-Policy header to the security guide [ci-skip]
2 parents fec53a1 + 448b65a commit d9dcaf7

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

guides/source/security.md

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1201,6 +1201,43 @@ for allowing inline `<script>` tags.
12011201
This is used by the Rails UJS helper to create dynamically
12021202
loaded inline `<script>` elements.
12031203

1204+
### Feature-Policy Header
1205+
1206+
NOTE: The Feature-Policy header has been renamed to Permissions-Policy.
1207+
The Permissions-Policy requires a different implementation and isn't
1208+
yet supported by all browsers. To avoid having to rename this
1209+
middleware in the future we use the new name for the middleware but
1210+
keep the old header name and implementation for now.
1211+
1212+
To allow or block the use of browser features you can define a
1213+
[Feature-Policy](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Feature-Policy)
1214+
response header for you application. Rails provides a DSL that allows you to
1215+
configure the header.
1216+
1217+
Define the policy in the appropriate initializer:
1218+
1219+
```ruby
1220+
# config/initializers/permissions_policy.rb
1221+
Rails.application.config.permissions_policy do |policy|
1222+
policy.camera :none
1223+
policy.gyroscope :none
1224+
policy.microphone :none
1225+
policy.usb :none
1226+
policy.fullscreen :self
1227+
policy.payment :self, "https://secure.example.com"
1228+
end
1229+
```
1230+
1231+
The globally configured policy can be overridden on a per-resource basis:
1232+
1233+
```ruby
1234+
class PagesController < ApplicationController
1235+
permissions_policy do |policy|
1236+
policy.geolocation "https://example.com"
1237+
end
1238+
end
1239+
```
1240+
12041241
Environmental Security
12051242
----------------------
12061243

0 commit comments

Comments
 (0)