跳至内容 跳至搜索

Action View CSP 帮助器

方法
C

实例公共方法

csp_meta_tag(**options)

返回一个元标记“csp-nonce”,其中包含允许内联 <script> 标记的每个会话随机数。

<head>
  <%= csp_meta_tag %>
</head>

Rails UJS 帮助器使用它来创建动态加载的内联 <script> 元素。

# File actionview/lib/action_view/helpers/csp_helper.rb, line 17
def csp_meta_tag(**options)
  if content_security_policy?
    options[:name] = "csp-nonce"
    options[:content] = content_security_policy_nonce
    tag("meta", options)
  end
end