【问题标题】:Ruby on Rails Telegram Notification. Is it secure?Ruby on Rails 电报通知。它安全吗?
【发布时间】:2017-10-27 07:57:55
【问题描述】:

我正在尝试使用 tele_notify gem: Tele Notify

这个 Gem 使用 Webhook,所以我用 Telegram 设置它:

https://api.telegram.org/bot<TOKEN>/setWebHook?url=https://<EXAMPLE.COM>/<TOKEN>
{"ok":true,"result":true,"description":"Webhook was set"}

然后在应用程序控制器中:

#app/controllers/application_controller.rb
class ApplicationController < ActionController::Base
  protect_from_forgery with: :exception

  #IMPORTANT! THESE TWO LINES MUST COME AFTER protect_from_forgery!
  skip_before_filter :verify_authenticity_token, :only => :webhook
  include TeleNotify::Controller

  #other code...
end

最后是路线:

#config/routes.rb
Rails.application.routes.draw do
  post '/<your token>' => 'application#webhook'
end

这段代码安全吗?有人用过这个宝石吗?

跳过真实性令牌有问题吗?

skip_before_filter :verify_authenticity_token, :only => :webhook

非常感谢!

【问题讨论】:

    标签: ruby-on-rails ruby model-view-controller rubygems telegram


    【解决方案1】:

    是的,它非常安全。有意无意,但你似乎在关注official recommendations

    如果您想确保 Webhook 请求来自 Telegram,我们建议在 URL 中使用秘密路径,例如https://www.example.com/&lt;token&gt;。由于没有其他人知道您的机器人的令牌,因此您可以确定是我们。

    至于跳过真实性令牌检查,它必须完成,因为电报服务器无法知道令牌。 (这正是令牌和检查背后的想法:不知道令牌的远程服务器无法发出请求。但是在这里您希望它们能够访问这个特定的端点)。

    【讨论】:

      猜你喜欢
      • 2011-04-01
      • 2011-04-01
      • 1970-01-01
      • 1970-01-01
      • 2012-12-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多