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 (将#修改为@)

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...