Skip to content

Commit 451f40a

Browse files
pglombardoPeter Giacomo Lombardocursoragent
authored
Enable Permissions-Policy headers for browser feature restrictions. (#4621)
Addresses security scanner findings by denying unused browser APIs while preserving clipboard-write for copy-to-clipboard. Co-authored-by: Peter Giacomo Lombardo <pglombardo@apnotic.com> Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent acc4607 commit 451f40a

2 files changed

Lines changed: 71 additions & 10 deletions

File tree

Lines changed: 56 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,61 @@
11
# frozen_string_literal: true
22

33
# Be sure to restart your server when you modify this file.
4+
#
5+
# Password Pusher is a form-based app: copy-to-clipboard is the main browser
6+
# capability we rely on. Everything else is denied by default.
7+
#
8+
# Rails emits Feature-Policy (legacy). Scanners expect Permissions-Policy
9+
# (modern syntax), so both are configured here.
410

5-
# Define an application-wide HTTP permissions policy. For further
6-
# information see: https://developers.google.com/web/updates/2018/06/feature-policy
11+
Rails.application.configure do
12+
config.permissions_policy do |policy|
13+
policy.accelerometer :none
14+
policy.ambient_light_sensor :none
15+
policy.autoplay :none
16+
policy.camera :none
17+
policy.display_capture :none
18+
policy.encrypted_media :none
19+
policy.fullscreen :none
20+
policy.geolocation :none
21+
policy.gyroscope :none
22+
policy.hid :none
23+
policy.idle_detection :none
24+
policy.magnetometer :none
25+
policy.microphone :none
26+
policy.midi :none
27+
policy.payment :none
28+
policy.picture_in_picture :none
29+
policy.screen_wake_lock :none
30+
policy.serial :none
31+
policy.sync_xhr :none
32+
policy.usb :none
33+
policy.web_share :none
34+
end
735

8-
# Rails.application.config.permissions_policy do |policy|
9-
# policy.camera :none
10-
# policy.gyroscope :none
11-
# policy.microphone :none
12-
# policy.usb :none
13-
# policy.fullscreen :self
14-
# policy.payment :self, "https://secure.example.com"
15-
# end
36+
config.action_dispatch.default_headers["Permissions-Policy"] = [
37+
"accelerometer=()",
38+
"autoplay=()",
39+
"camera=()",
40+
"clipboard-write=(self)",
41+
"display-capture=()",
42+
"encrypted-media=()",
43+
"fullscreen=()",
44+
"geolocation=()",
45+
"gyroscope=()",
46+
"hid=()",
47+
"idle-detection=()",
48+
"magnetometer=()",
49+
"microphone=()",
50+
"midi=()",
51+
"payment=()",
52+
"picture-in-picture=()",
53+
"publickey-credentials-get=()",
54+
"screen-wake-lock=()",
55+
"serial=()",
56+
"sync-xhr=()",
57+
"usb=()",
58+
"web-share=()",
59+
"xr-spatial-tracking=()"
60+
].join(", ")
61+
end
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# frozen_string_literal: true
2+
3+
require "test_helper"
4+
5+
class PermissionsPolicyTest < ActionDispatch::IntegrationTest
6+
test "responses include permissions policy headers" do
7+
get root_path
8+
9+
assert_response :success
10+
assert response.headers["Permissions-Policy"].present?
11+
assert_includes response.headers["Permissions-Policy"], "camera=()"
12+
assert_includes response.headers["Permissions-Policy"], "clipboard-write=(self)"
13+
assert_includes response.headers["Feature-Policy"], "camera 'none'"
14+
end
15+
end

0 commit comments

Comments
 (0)