Skip to content

A platform for community discussion. Free, open, simple.

DEV: uses constant time to validate mailgun signature (#37754)

Joffrey JAFFEUX8f0ee77a65d7
diff --git a/app/controllers/webhooks_controller.rb b/app/controllers/webhooks_controller.rb
index 6495cc13640..acd118650e8 100644
--- a/app/controllers/webhooks_controller.rb
+++ b/app/controllers/webhooks_controller.rb
@@ -222,8 +222,10 @@ class WebhooksController < ActionController::Base
return false if (Time.at(timestamp.to_i) - Time.now).abs > 12.hours.to_i
# check the signature
- signature ==
- OpenSSL::HMAC.hexdigest("SHA256", SiteSetting.mailgun_api_key, "#{timestamp}#{token}")
+ ActiveSupport::SecurityUtils.secure_compare(
+ signature,
+ OpenSSL::HMAC.hexdigest("SHA256", SiteSetting.mailgun_api_key, "#{timestamp}#{token}"),
+ )
end
def handle_mailgun_legacy(params)