Skip to content

Commit 35858f1

Browse files
fresh-eggstenderlove
authored andcommitted
include the HTTP Permissions-Policy on non-HTML Content-Types
[CVE-2024-28103] The application configurable Permissions-Policy is only served on responses with an HTML related Content-Type. This change allows all Content-Types to serve the configured Permissions-Policy as there are many non-HTML Content-Types that would benefit from this header. (examples include image/svg+xml and application/xml)
1 parent f008c31 commit 35858f1

File tree

2 files changed

+2
-9
lines changed

2 files changed

+2
-9
lines changed

actionpack/lib/action_dispatch/http/permissions_policy.rb

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ def initialize(app)
3737
def call(env)
3838
_, headers, _ = response = @app.call(env)
3939

40-
return response unless html_response?(headers)
4140
return response if policy_present?(headers)
4241

4342
request = ActionDispatch::Request.new(env)
@@ -54,12 +53,6 @@ def call(env)
5453
end
5554

5655
private
57-
def html_response?(headers)
58-
if content_type = headers[Rack::CONTENT_TYPE]
59-
content_type.include?("html")
60-
end
61-
end
62-
6356
def policy_present?(headers)
6457
headers[ActionDispatch::Constants::FEATURE_POLICY]
6558
end

actionpack/test/dispatch/permissions_policy_test.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,12 +69,12 @@ def call(env)
6969
assert_equal "gyroscope 'self'", response.headers[ActionDispatch::Constants::FEATURE_POLICY]
7070
end
7171

72-
test "non-html requests will not set a policy" do
72+
test "non-html requests will set a policy" do
7373
@app = build_app(->(env) { [200, { Rack::CONTENT_TYPE => "application/json" }, []] })
7474

7575
get "/index"
7676

77-
assert_nil response.headers[ActionDispatch::Constants::FEATURE_POLICY]
77+
assert_equal "gyroscope 'self'", response.headers[ActionDispatch::Constants::FEATURE_POLICY]
7878
end
7979

8080
test "existing policies will not be overwritten" do

0 commit comments

Comments
 (0)