From e14bb160ac8756d663a1397de4482f02fd738e1e Mon Sep 17 00:00:00 2001 From: Brian Neel Date: Fri, 18 Nov 2016 13:45:52 -0500 Subject: [PATCH] Add logging for rack attack events --- changelogs/unreleased/rack_attack_logging.yml | 4 ++++ config/initializers/rack_attack_logging.rb | 7 +++++++ 2 files changed, 11 insertions(+) create mode 100644 changelogs/unreleased/rack_attack_logging.yml create mode 100644 config/initializers/rack_attack_logging.rb diff --git a/changelogs/unreleased/rack_attack_logging.yml b/changelogs/unreleased/rack_attack_logging.yml new file mode 100644 index 00000000000..c0d6c1fd12e --- /dev/null +++ b/changelogs/unreleased/rack_attack_logging.yml @@ -0,0 +1,4 @@ +--- +title: Add logging for rack attack events to production.log +merge_request: +author: diff --git a/config/initializers/rack_attack_logging.rb b/config/initializers/rack_attack_logging.rb new file mode 100644 index 00000000000..8bb9ea29c33 --- /dev/null +++ b/config/initializers/rack_attack_logging.rb @@ -0,0 +1,7 @@ +# Adds logging for all Rack Attack blocks and throttling events. + +ActiveSupport::Notifications.subscribe('rack.attack') do |name, start, finish, request_id, req| + if [:throttle, :blacklist].include? req.env['rack.attack.match_type'] + Rails.logger.info("Rack_Attack: #{req.env['rack.attack.match_type']} #{req.ip} #{req.request_method} #{req.fullpath}") + end +end -- GitLab