如何解决Rails CSP中间件是否可以支持在同一响应中同时具有Content-Security-Policy和Content-Security-Policy-Report-Only标头?
我希望在我的应用程序中实现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 举报,一经查实,本站将立刻删除。