diff --git a/app/controllers/webhook_secret_controller.rb b/app/controllers/webhook_secret_controller.rb index b9b8a3f2..94a659e4 100644 --- a/app/controllers/webhook_secret_controller.rb +++ b/app/controllers/webhook_secret_controller.rb @@ -3,11 +3,19 @@ class WebhookSecretController < ApplicationController load_and_authorize_resource :webhook_url, parent: false + HEADER_NAME_REGEXP = /\A[\w-]+\z/ + def show; end def update + key = webhook_secret_params[:key] + + if key.present? && !HEADER_NAME_REGEXP.match?(key) + return redirect_back(fallback_location: settings_webhook_path(@webhook_url), alert: I18n.t('unable_to_save')) + end + @webhook_url.update!(secret: { - webhook_secret_params[:key] => webhook_secret_params[:value] + key => webhook_secret_params[:value] }.compact_blank) redirect_back(fallback_location: settings_webhook_path(@webhook_url),