rack-attack 6.3.1 → 6.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3735d065000def3fce68a51f86fd46eec60d8ce8aac80991bd4c1fd05cf2babd
4
- data.tar.gz: def7883dbc56f61163d54104e6a9b1aa87a93f47cdfefe60bb81880a7237aa8b
3
+ metadata.gz: e7d44de650fae1c83d5a3da49dc8f304e44280f72bd209d3f78643b90d573bd8
4
+ data.tar.gz: a39d0270489617a8c0a49e01868c24cc87311e80457fbc104c86e45d29978f51
5
5
  SHA512:
6
- metadata.gz: 4c40ef6a1a7f2c1692b5bf3c46cb4f7e25bec5f413c9f96ee8b37b62e67b9f2e31e3c8067c9ecf19af4be16bbc01e016a3921052ed08c42c8a72b8a7696653e1
7
- data.tar.gz: 3bb4d54e791d056a5e905e72b325a1eb733a6f3b660601f4d4ac39aa1b46cf480879bfae72575ce8ed8420961166ef3273cbe3590f60efa552946fbfb20cd7c2
6
+ metadata.gz: 7d9d965cc672bba8ab2b9f333746e32091363d6b65bf290104c248799a811f272ad8388e7f7b3d870d382e9c80a1003a300f9380c2d8082195972817146a281d
7
+ data.tar.gz: fbfa381116824ea4de492b66408d15bd708692a74275548c9b167868c0bee566f79a216046213c43a8eb3117b869e86ac99f989e5e4c045c30267db2981b2c6b
data/README.md CHANGED
@@ -1,5 +1,5 @@
1
1
  __Note__: You are viewing the development version README.
2
- For the README consistent with the latest released version see https://github.com/kickstarter/rack-attack/blob/6-stable/README.md.
2
+ For the README consistent with the latest released version see https://github.com/rack/rack-attack/blob/6-stable/README.md.
3
3
 
4
4
  # Rack::Attack
5
5
 
@@ -10,7 +10,7 @@ Protect your Rails and Rack apps from bad clients. Rack::Attack lets you easily
10
10
  See the [Backing & Hacking blog post](https://www.kickstarter.com/backing-and-hacking/rack-attack-protection-from-abusive-clients) introducing Rack::Attack.
11
11
 
12
12
  [![Gem Version](https://badge.fury.io/rb/rack-attack.svg)](https://badge.fury.io/rb/rack-attack)
13
- [![Build Status](https://travis-ci.org/kickstarter/rack-attack.svg?branch=master)](https://travis-ci.org/kickstarter/rack-attack)
13
+ [![Build Status](https://travis-ci.org/rack/rack-attack.svg?branch=master)](https://travis-ci.org/rack/rack-attack)
14
14
  [![Code Climate](https://codeclimate.com/github/kickstarter/rack-attack.svg)](https://codeclimate.com/github/kickstarter/rack-attack)
15
15
  [![Join the chat at https://gitter.im/rack-attack/rack-attack](https://badges.gitter.im/rack-attack/rack-attack.svg)](https://gitter.im/rack-attack/rack-attack)
16
16
 
@@ -40,7 +40,6 @@ See the [Backing & Hacking blog post](https://www.kickstarter.com/backing-and-ha
40
40
  - [Testing](#testing)
41
41
  - [How it works](#how-it-works)
42
42
  - [About Tracks](#about-tracks)
43
- - [Testing](#testing)
44
43
  - [Performance](#performance)
45
44
  - [Motivation](#motivation)
46
45
  - [Contributing](#contributing)
@@ -141,7 +140,7 @@ E.g.
141
140
  # Provided that trusted users use an HTTP request header named APIKey
142
141
  Rack::Attack.safelist("mark any authenticated access safe") do |request|
143
142
  # Requests are allowed if the return value is truthy
144
- request.env["APIKey"] == "secret-string"
143
+ request.env["HTTP_APIKEY"] == "secret-string"
145
144
  end
146
145
 
147
146
  # Always allow requests from localhost
@@ -264,10 +263,12 @@ Rack::Attack.throttle("requests by ip", limit: 5, period: 2) do |request|
264
263
  end
265
264
 
266
265
  # Throttle login attempts for a given email parameter to 6 reqs/minute
267
- # Return the email as a discriminator on POST /login requests
266
+ # Return the *normalized* email as a discriminator on POST /login requests
268
267
  Rack::Attack.throttle('limit logins per email', limit: 6, period: 60) do |req|
269
268
  if req.path == '/login' && req.post?
270
- req.params['email']
269
+ # Normalize the email, using the same logic as your authentication process, to
270
+ # protect against rate limit bypasses.
271
+ req.params['email'].to_s.downcase.gsub(/\s+/, "")
271
272
  end
272
273
  end
273
274
 
@@ -343,7 +344,7 @@ end
343
344
  While Rack::Attack's primary focus is minimizing harm from abusive clients, it
344
345
  can also be used to return rate limit data that's helpful for well-behaved clients.
345
346
 
346
- If you want to return to user how many seconds to wait until he can start sending requests again, this can be done through enabling `Retry-After` header:
347
+ If you want to return to user how many seconds to wait until they can start sending requests again, this can be done through enabling `Retry-After` header:
347
348
  ```ruby
348
349
  Rack::Attack.throttled_response_retry_after_header = true
349
350
  ```
@@ -378,7 +379,7 @@ Rack::Attack uses the [ActiveSupport::Notifications](http://api.rubyonrails.org/
378
379
 
379
380
  You can subscribe to `rack_attack` events and log it, graph it, etc.
380
381
 
381
- To get notified about specific type of events, subscribe to the event name followed by the `rack_attack` namesapce.
382
+ To get notified about specific type of events, subscribe to the event name followed by the `rack_attack` namespace.
382
383
  E.g. for throttles use:
383
384
 
384
385
  ```ruby
@@ -401,6 +402,10 @@ end
401
402
 
402
403
  ## Testing
403
404
 
405
+ A note on developing and testing apps using Rack::Attack - if you are using throttling in particular, you will
406
+ need to enable the cache in your development environment. See [Caching with Rails](http://guides.rubyonrails.org/caching_with_rails.html)
407
+ for more on how to do this.
408
+
404
409
  ### Disabling
405
410
 
406
411
  `Rack::Attack.enabled = false` can be used to either completely disable Rack::Attack in your tests, or to disable/enable for specific test cases only.
@@ -445,13 +450,6 @@ can cleanly monkey patch helper methods onto the
445
450
 
446
451
  `Rack::Attack.track` doesn't affect request processing. Tracks are an easy way to log and measure requests matching arbitrary attributes.
447
452
 
448
-
449
- ## Testing
450
-
451
- A note on developing and testing apps using Rack::Attack - if you are using throttling in particular, you will
452
- need to enable the cache in your development environment. See [Caching with Rails](http://guides.rubyonrails.org/caching_with_rails.html)
453
- for more on how to do this.
454
-
455
453
  ## Performance
456
454
 
457
455
  The overhead of running Rack::Attack is typically negligible (a few milliseconds per request),
@@ -12,6 +12,7 @@ module Rack
12
12
  end
13
13
 
14
14
  attr_reader :store
15
+
15
16
  def store=(store)
16
17
  @store = StoreProxy.build(store)
17
18
  end
@@ -4,6 +4,7 @@ module Rack
4
4
  class Attack
5
5
  class Check
6
6
  attr_reader :name, :block, :type
7
+
7
8
  def initialize(name, options = {}, &block)
8
9
  @name = name
9
10
  @block = block
@@ -10,7 +10,7 @@ module Rack
10
10
  store.class.name == "ActiveSupport::Cache::RedisCacheStore"
11
11
  end
12
12
 
13
- def increment(name, amount = 1, options = {})
13
+ def increment(name, amount = 1, **options)
14
14
  # RedisCacheStore#increment ignores options[:expires_in].
15
15
  #
16
16
  # So in order to workaround this we use RedisCacheStore#write (which sets expiration) to initialize
@@ -6,6 +6,7 @@ module Rack
6
6
  MANDATORY_OPTIONS = [:limit, :period].freeze
7
7
 
8
8
  attr_reader :name, :limit, :period, :block, :type
9
+
9
10
  def initialize(name, options, &block)
10
11
  @name = name
11
12
  @block = block
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Rack
4
4
  class Attack
5
- VERSION = '6.3.1'
5
+ VERSION = '6.4.0'
6
6
  end
7
7
  end
@@ -21,6 +21,6 @@ if should_run
21
21
  Rack::Attack.cache.store.clear
22
22
  end
23
23
 
24
- it_works_for_cache_backed_features(fetch_from_store: ->(key) { Rack::Attack.cache.store.fetch(key) })
24
+ it_works_for_cache_backed_features(fetch_from_store: ->(key) { Rack::Attack.cache.store.read(key) })
25
25
  end
26
26
  end
@@ -20,6 +20,6 @@ if should_run
20
20
  Rack::Attack.cache.store.clear
21
21
  end
22
22
 
23
- it_works_for_cache_backed_features(fetch_from_store: ->(key) { Rack::Attack.cache.store.fetch(key) })
23
+ it_works_for_cache_backed_features(fetch_from_store: ->(key) { Rack::Attack.cache.store.read(key) })
24
24
  end
25
25
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rack-attack
3
3
  version: !ruby/object:Gem::Version
4
- version: 6.3.1
4
+ version: 6.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Aaron Suggs
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-05-21 00:00:00.000000000 Z
11
+ date: 2021-01-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rack
@@ -126,14 +126,14 @@ dependencies:
126
126
  requirements:
127
127
  - - '='
128
128
  - !ruby/object:Gem::Version
129
- version: 0.78.0
129
+ version: 0.89.1
130
130
  type: :development
131
131
  prerelease: false
132
132
  version_requirements: !ruby/object:Gem::Requirement
133
133
  requirements:
134
134
  - - '='
135
135
  - !ruby/object:Gem::Version
136
- version: 0.78.0
136
+ version: 0.89.1
137
137
  - !ruby/object:Gem::Dependency
138
138
  name: rubocop-performance
139
139
  requirement: !ruby/object:Gem::Requirement
@@ -185,7 +185,7 @@ dependencies:
185
185
  version: '4.2'
186
186
  - - "<"
187
187
  - !ruby/object:Gem::Version
188
- version: '6.1'
188
+ version: '6.2'
189
189
  type: :development
190
190
  prerelease: false
191
191
  version_requirements: !ruby/object:Gem::Requirement
@@ -195,7 +195,7 @@ dependencies:
195
195
  version: '4.2'
196
196
  - - "<"
197
197
  - !ruby/object:Gem::Version
198
- version: '6.1'
198
+ version: '6.2'
199
199
  description: A rack middleware for throttling and blocking abusive requests
200
200
  email: aaron@ktheory.com
201
201
  executables: []
@@ -204,7 +204,6 @@ extra_rdoc_files: []
204
204
  files:
205
205
  - README.md
206
206
  - Rakefile
207
- - bin/setup
208
207
  - lib/rack/attack.rb
209
208
  - lib/rack/attack/allow2ban.rb
210
209
  - lib/rack/attack/blocklist.rb
@@ -268,13 +267,13 @@ files:
268
267
  - spec/rack_attack_track_spec.rb
269
268
  - spec/spec_helper.rb
270
269
  - spec/support/cache_store_helper.rb
271
- homepage: https://github.com/kickstarter/rack-attack
270
+ homepage: https://github.com/rack/rack-attack
272
271
  licenses:
273
272
  - MIT
274
273
  metadata:
275
- bug_tracker_uri: https://github.com/kickstarter/rack-attack/issues
276
- changelog_uri: https://github.com/kickstarter/rack-attack/blob/master/CHANGELOG.md
277
- source_code_uri: https://github.com/kickstarter/rack-attack
274
+ bug_tracker_uri: https://github.com/rack/rack-attack/issues
275
+ changelog_uri: https://github.com/rack/rack-attack/blob/master/CHANGELOG.md
276
+ source_code_uri: https://github.com/rack/rack-attack
278
277
  post_install_message:
279
278
  rdoc_options:
280
279
  - "--charset=UTF-8"
@@ -284,57 +283,57 @@ required_ruby_version: !ruby/object:Gem::Requirement
284
283
  requirements:
285
284
  - - ">="
286
285
  - !ruby/object:Gem::Version
287
- version: '2.3'
286
+ version: '2.4'
288
287
  required_rubygems_version: !ruby/object:Gem::Requirement
289
288
  requirements:
290
289
  - - ">="
291
290
  - !ruby/object:Gem::Version
292
291
  version: '0'
293
292
  requirements: []
294
- rubygems_version: 3.1.3
293
+ rubygems_version: 3.2.6
295
294
  signing_key:
296
295
  specification_version: 4
297
296
  summary: Block & throttle abusive requests
298
297
  test_files:
299
- - spec/integration/offline_spec.rb
300
- - spec/rack_attack_path_normalizer_spec.rb
301
- - spec/acceptance/safelisting_subnet_spec.rb
302
- - spec/acceptance/rails_middleware_spec.rb
303
- - spec/acceptance/track_throttle_spec.rb
304
- - spec/acceptance/cache_store_config_for_fail2ban_spec.rb
305
- - spec/acceptance/cache_store_config_with_rails_spec.rb
306
- - spec/acceptance/cache_store_config_for_allow2ban_spec.rb
307
- - spec/acceptance/safelisting_ip_spec.rb
308
- - spec/acceptance/track_spec.rb
309
- - spec/acceptance/blocking_subnet_spec.rb
310
- - spec/acceptance/blocking_ip_spec.rb
311
298
  - spec/acceptance/allow2ban_spec.rb
312
- - spec/acceptance/throttling_spec.rb
299
+ - spec/acceptance/blocking_ip_spec.rb
313
300
  - spec/acceptance/blocking_spec.rb
301
+ - spec/acceptance/blocking_subnet_spec.rb
302
+ - spec/acceptance/cache_store_config_for_allow2ban_spec.rb
303
+ - spec/acceptance/cache_store_config_for_fail2ban_spec.rb
304
+ - spec/acceptance/cache_store_config_for_throttle_spec.rb
305
+ - spec/acceptance/cache_store_config_with_rails_spec.rb
306
+ - spec/acceptance/customizing_blocked_response_spec.rb
314
307
  - spec/acceptance/customizing_throttled_response_spec.rb
315
308
  - spec/acceptance/extending_request_object_spec.rb
316
- - spec/acceptance/safelisting_spec.rb
317
- - spec/acceptance/cache_store_config_for_throttle_spec.rb
318
309
  - spec/acceptance/fail2ban_spec.rb
310
+ - spec/acceptance/rails_middleware_spec.rb
311
+ - spec/acceptance/safelisting_ip_spec.rb
312
+ - spec/acceptance/safelisting_spec.rb
313
+ - spec/acceptance/safelisting_subnet_spec.rb
314
+ - spec/acceptance/stores/active_support_dalli_store_spec.rb
319
315
  - spec/acceptance/stores/active_support_mem_cache_store_pooled_spec.rb
320
- - spec/acceptance/stores/active_support_redis_cache_store_spec.rb
321
- - spec/acceptance/stores/active_support_memory_store_spec.rb
322
- - spec/acceptance/stores/active_support_redis_store_spec.rb
323
316
  - spec/acceptance/stores/active_support_mem_cache_store_spec.rb
317
+ - spec/acceptance/stores/active_support_memory_store_spec.rb
324
318
  - spec/acceptance/stores/active_support_redis_cache_store_pooled_spec.rb
319
+ - spec/acceptance/stores/active_support_redis_cache_store_spec.rb
320
+ - spec/acceptance/stores/active_support_redis_store_spec.rb
325
321
  - spec/acceptance/stores/connection_pool_dalli_client_spec.rb
326
- - spec/acceptance/stores/active_support_dalli_store_spec.rb
327
- - spec/acceptance/stores/redis_store_spec.rb
328
322
  - spec/acceptance/stores/dalli_client_spec.rb
329
323
  - spec/acceptance/stores/redis_spec.rb
330
- - spec/acceptance/customizing_blocked_response_spec.rb
331
- - spec/spec_helper.rb
324
+ - spec/acceptance/stores/redis_store_spec.rb
325
+ - spec/acceptance/throttling_spec.rb
326
+ - spec/acceptance/track_spec.rb
327
+ - spec/acceptance/track_throttle_spec.rb
332
328
  - spec/allow2ban_spec.rb
333
- - spec/rack_attack_instrumentation_spec.rb
329
+ - spec/fail2ban_spec.rb
330
+ - spec/integration/offline_spec.rb
334
331
  - spec/rack_attack_dalli_proxy_spec.rb
332
+ - spec/rack_attack_instrumentation_spec.rb
333
+ - spec/rack_attack_path_normalizer_spec.rb
334
+ - spec/rack_attack_request_spec.rb
335
335
  - spec/rack_attack_spec.rb
336
336
  - spec/rack_attack_throttle_spec.rb
337
- - spec/rack_attack_request_spec.rb
338
- - spec/fail2ban_spec.rb
339
337
  - spec/rack_attack_track_spec.rb
338
+ - spec/spec_helper.rb
340
339
  - spec/support/cache_store_helper.rb
data/bin/setup DELETED
@@ -1,8 +0,0 @@
1
- #!/usr/bin/env bash
2
- set -euo pipefail
3
- IFS=$'\n\t'
4
- set -vx
5
-
6
- bundle install
7
-
8
- # Do any other automated setup that you need to do here