跳至內容 跳至搜尋

Action View CSP 幫手

方法
C

執行個體公共方法

csp_meta_tag(**options)

傳回包含用於允許內嵌<script>標籤的每個工作階段唯一定義值的金鑰字元串「csp-nonce」元標籤。

<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