【问题标题】:Ruby on Rails: Stripe JS & Elements causing Content Security Policy errorRuby on Rails:Stripe JS & Elements 导致内容安全策略错误
【发布时间】:2018-04-27 00:52:38
【问题描述】:

我正在开发一个 Ruby on Rails 应用程序,我计划在其中集成 Stripe 支付。我正在使用stripe gem。我打算使用 Elements,如described here

我包括这样的 Stripe js:

= javascript_include_tag 'https://js.stripe.com/v3/'

在我的charges.coffee 文件中,我有这个:

$(document).on 'turbolinks:load', ->
  stripe = Stripe("<%= Rails.application.secrets['STRIPE_PUBLISHABLE_KEY'] %>")
  elements = stripe.elements()

当我加载应用程序时,我目前在 Safari 中收到以下错误:

Refused to execute a script because its hash, its nonce, or 'unsafe-inline' does not appear in the script-src directive of the Content Security Policy.

有什么想法可以解决这个问题吗?

【问题讨论】:

标签: javascript ruby-on-rails ruby stripe-payments stripe.js


【解决方案1】:

我今天通过将 secure_headers gem 从 v3 升级到最新的 v5 解决了这个问题,我的不合逻辑的 CSP 错误消失了。

【讨论】:

    猜你喜欢
    • 2021-12-13
    • 1970-01-01
    • 1970-01-01
    • 2021-10-07
    • 2017-09-07
    • 2019-02-11
    • 1970-01-01
    • 2018-12-29
    • 2018-01-09
    相关资源
    最近更新 更多