未验证 提交 a150a026 编写于 作者: A Andrew White

Use request object for context if there's no controller

There is no controller instance when using a redirect route or a
mounted rack application so pass the request object as the context
when resolving dynamic CSP sources in this scenario.

Fixes #34200.
上级 ed91b75c
* Use request object for context if there's no controller
There is no controller instance when using a redirect route or a
mounted rack application so pass the request object as the context
when resolving dynamic CSP sources in this scenario.
Fixes #34200.
*Andrew White*
* Apply mapping to symbols returned from dynamic CSP sources
Previously if a dynamic source returned a symbol such as :self it
......
......@@ -22,7 +22,8 @@ def call(env)
if policy = request.content_security_policy
nonce = request.content_security_policy_nonce
headers[header_name(request)] = policy.build(request.controller_instance, nonce)
context = request.controller_instance || request
headers[header_name(request)] = policy.build(context, nonce)
end
response
......
......@@ -260,6 +260,7 @@ def index
ROUTES.draw do
scope module: "default_content_security_policy_integration_test" do
get "/", to: "policy#index"
get "/redirect", to: redirect("/")
end
end
......@@ -295,14 +296,19 @@ def app
def test_adds_nonce_to_script_src_content_security_policy_only_once
get "/"
get "/"
assert_response :success
assert_policy "default-src 'self'; script-src https: 'nonce-iyhD0Yc0W+c='"
end
def test_redirect_works_with_dynamic_sources
get "/redirect"
assert_response :redirect
assert_policy "default-src 'self'; script-src https: 'nonce-iyhD0Yc0W+c='"
end
private
def assert_policy(expected, report_only: false)
assert_response :success
if report_only
expected_header = "Content-Security-Policy-Report-Only"
unexpected_header = "Content-Security-Policy"
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册