validate webhook header

master^2
Pete Matsyburka 6 days ago
parent 9941122d90
commit 85fbae1813

@ -3,11 +3,19 @@
class WebhookSecretController < ApplicationController class WebhookSecretController < ApplicationController
load_and_authorize_resource :webhook_url, parent: false load_and_authorize_resource :webhook_url, parent: false
HEADER_NAME_REGEXP = /\A[\w-]+\z/
def show; end def show; end
def update 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_url.update!(secret: {
webhook_secret_params[:key] => webhook_secret_params[:value] key => webhook_secret_params[:value]
}.compact_blank) }.compact_blank)
redirect_back(fallback_location: settings_webhook_path(@webhook_url), redirect_back(fallback_location: settings_webhook_path(@webhook_url),

Loading…
Cancel
Save