问题描述
我希望在我的应用程序中实现Content-Security-Policy,并通过将规则添加到Content-Security-Policy-Report-Only标头中来迭代策略,以便在测试新策略时可以保持现有安全性我的生产环境。
根据W3C CSP2 recommendation,这是Content-Security-Policy-Report-Only标头的预期用途。但是,当尝试配置Rails实现此目的时,您似乎可以将CSP置于report only
模式或“强制”模式:
Rails.application.config.content_security_policy_report_only = true
我尝试查看Rails源码,看是否有一种方法可以实现此目的,但是它似乎是出现的 :
ActionDispatch::ContentSecurityPolicy::Middleware#Line:40
def call(env)
...
return response if policy_present?(headers)
if policy = request.content_security_policy
...
headers[header_name(request)] = policy.build(context,nonce,nonce_directives)
end
response
end
...
def header_name(request)
if request.content_security_policy_report_only
POLICY_REPORT_ONLY
else
POLICY
end
end
def policy_present?(headers)
headers[POLICY] || headers[POLICY_REPORT_ONLY]
end
是否可以将Rails配置为在同一请求中处理两个标头?还是我必须在不使用Rails内置DSL的情况下手动设置标头?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)