Disable Rack Attack throttling if admin disables it in config file

This commit is contained in:
Stan Hu 2016-04-25 17:12:03 -07:00
parent e7f6ab503a
commit 631511f80e
1 changed files with 2 additions and 1 deletions

View File

@ -20,8 +20,9 @@ paths_to_be_protected = [
# Create one big regular expression that matches strings starting with any of
# the paths_to_be_protected.
paths_regex = Regexp.union(paths_to_be_protected.map { |path| /\A#{Regexp.escape(path)}/ })
rack_attack_enabled = Gitlab.config.rack_attack.git_basic_auth['enabled']
unless Rails.env.test?
unless Rails.env.test? || !rack_attack_enabled?
Rack::Attack.throttle('protected paths', limit: <%= @rate_limit_requests_per_period %>, period: <%= @rate_limit_period %>.seconds) do |req|
if req.post? && req.path =~ paths_regex
req.ip