A platform for community discussion. Free, open, simple.
FIX: enforce the presence of webhook secret (#38097)
Joffrey JAFFEUX03ad8f019169
diff --git a/plugins/discourse-subscriptions/app/controllers/discourse_subscriptions/hooks_controller.rb b/plugins/discourse-subscriptions/app/controllers/discourse_subscriptions/hooks_controller.rbindex 3b36d4d5183..3025e26030b 100644--- a/plugins/discourse-subscriptions/app/controllers/discourse_subscriptions/hooks_controller.rb+++ b/plugins/discourse-subscriptions/app/controllers/discourse_subscriptions/hooks_controller.rb@@ -20,6 +20,8 @@ module DiscourseSubscriptionssig_header = request.env["HTTP_STRIPE_SIGNATURE"]webhook_secret = SiteSetting.discourse_subscriptions_webhook_secret+ return head :forbidden if webhook_secret.blank?+event = ::Stripe::Webhook.construct_event(payload, sig_header, webhook_secret)rescue JSON::ParserError => ereturn render_json_error e.messagediff --git a/plugins/discourse-subscriptions/spec/requests/hooks_controller_spec.rb b/plugins/discourse-subscriptions/spec/requests/hooks_controller_spec.rbindex 93b42df0960..da21da58e42 100644--- a/plugins/discourse-subscriptions/spec/requests/hooks_controller_spec.rb+++ b/plugins/discourse-subscriptions/spec/requests/hooks_controller_spec.rb@@ -6,6 +6,12 @@ RSpec.describe DiscourseSubscriptions::HooksController doSiteSetting.discourse_subscriptions_enabled = trueend+ it "rejects webhooks when webhook secret is blank" do+ SiteSetting.discourse_subscriptions_webhook_secret = ""+ post "/s/hooks.json", params: "{}", headers: { HTTP_STRIPE_SIGNATURE: "t=1,v1=abc" }+ expect(response.status).to eq 403+ end+it "constructs a webhook event" dopayload = "we-want-a-shrubbery"headers = { HTTP_STRIPE_SIGNATURE: "stripe-webhook-signature" }