Commit graph

83 commits

Author SHA1 Message Date
Gonzalo Rodriguez
8fafa7602b
style: fix Style/BlockDelimiters cop check 2019-08-02 15:24:17 -03:00
Gonzalo Rodriguez
c0328707b1
style: enable Style/ParallelAssignment cop checks 2019-08-02 13:47:54 -03:00
Gonzalo Rodriguez
c8021da91c
style: avoid compact class/module definitions 2019-08-02 11:17:41 -03:00
Gonzalo Rodriguez
6541634fb0
style: enable Style/Semicolon rubocop 2019-03-01 22:25:27 -03:00
Gonzalo Rodriguez
fcb89a6c12
refactor: avoid unnecessary nil argument passing 2019-03-01 22:22:11 -03:00
Gonzalo Rodriguez
0e8dff4c88
refactor: make Throttle.new consistent with Blocklist/Safelist.new 2019-03-01 22:12:32 -03:00
Gonzalo Rodriguez
3639afc196
refactor: remove unnecessary block local variable 2019-03-01 22:01:17 -03:00
Gonzalo Rodriguez
5a42fd3ac7
style: enable Style/OptionalArguments rubocop 2019-03-01 21:51:15 -03:00
Gonzalo Rodriguez
92bc56b7b7
style: enable Style/RedundantSelf rubocop 2019-03-01 21:15:50 -03:00
Gonzalo Rodriguez
a0259fb14a
style: enable Style/SingleLineMethods rubocop 2019-03-01 21:14:47 -03:00
Gonzalo Rodriguez
f772d0b3cd
Merge pull request #406 from grzuy/optional_name
Make blocklist/safelist name argument optional
2019-02-28 21:01:55 -03:00
Gonzalo Rodriguez
9a726bd29b
refactor: remove repeated initialization of anonymous_blocklists/safelists 2019-02-25 20:29:07 -03:00
Gonzalo Rodriguez
6addaa11d0
feat: make blocklist/safelist name argument optional 2019-02-24 21:04:51 -03:00
Gonzalo Rodriguez
6c6dfb06e3
feat: match ActiveSupport Instrumentation event name format spec 2019-02-24 20:19:38 -03:00
Gonzalo Rodriguez
91dbb52235
Remove unwrapping 2018-09-30 13:32:08 -03:00
Gonzalo Rodriguez
55411e5e82
Remove MemCacheProxy which existed only for now obsolete memcache-client 2018-09-03 18:24:21 -03:00
Jonathan del Strother
5cdc15b35a Add a proxy to deal with ActiveSupport::Cache::MemCacheStore
If connection pooling is used with AS::Cache::MemCacheStore,
unwrap_active_support_stores wouldn't return the underlying dalli instance(s),
and so Rack::Attack.store would be the bare unproxied MemCacheStore instance.

Calling write then increment would silently fail because :raw wasn't used.

With this commit, we no longer try to unwrap AS::Cache::MemCacheStore instances.
2018-09-03 12:00:02 +01:00
Gonzalo Rodriguez
6fbb6c8b1c
Merge branch 'master' into support-redis-gem 2018-06-29 15:40:45 -03:00
Gonzalo Rodriguez
19e17562c1
Merge pull request #372 from grzuy/drop_deprecated_methods
Remove previously deprecated public methods
2018-06-28 19:12:41 -03:00
Gonzalo Rodriguez
1c1ee918e1
Remove previously deprecated public methods 2018-06-28 17:16:33 -03:00
Gonzalo Rodriguez
8315a1e7e1
Remove support for unmaintained ruby 2.2 2018-06-28 17:08:15 -03:00
Gonzalo Rodriguez
8802ebfbaf
Merge branch '255-correct-object-for-instrumentation' 2018-06-28 16:40:08 -03:00
Gonzalo Rodriguez
08861f8d17
Attempt to improve code legibility/clarity/semantics (#357)
* attempt to improve semantics for legibility

* Attempt to improve legibility by simplifying

* Make it more clear that we're calling procs/blocks here

* Enable rubocop Style/BlockDelimiters cop

* Prefer 'request' over 'req' abbreviation for legibility/clarity

* Instances of Track named 'track' not 'tracker'
2018-06-21 14:33:24 -03:00
Gonzalo Rodriguez
e6854bcb02
Enable rubocop Naming cops 2018-06-19 17:57:26 -03:00
Brian Kephart
4cc8d7d854
Support ActiveSupport::RedisCacheStore 2018-06-19 13:39:43 -03:00
Gonzalo Rodriguez
a99722bf4b
Avoid user confusion by renaming .clear! to .clear_configuration 2018-05-18 18:23:59 -03:00
Gonzalo Rodriguez
52ec80692d
Enable Lint rubocop cops 2018-04-17 16:27:56 -04:00
Lucas Mansur
11e9557ccb [Fixes #302] Initial style guide adoption (#330)
* Initial Rubocop configuration

* Fix Rubocop layout offenses for lib

* Fix some spec offenses

* Fix leftover layout offenses
2018-03-30 16:08:00 -03:00
Gonzalo Rodriguez
62aca946b5
Require ipaddr so it works on ruby < 2.5 2018-03-26 18:53:32 -03:00
Gonzalo Rodriguez
e907cc6b83
Provide shorthand to safelist an entire IP subnet 2018-03-26 18:00:02 -03:00
Gonzalo Rodriguez
27aab72d49
Provide shorthand to safelist an IP 2018-03-26 17:51:40 -03:00
Gonzalo Rodriguez
aec03047c5
Provide shorthand to blocklist an entire IP subnet 2018-03-26 17:35:41 -03:00
Gonzalo Rodriguez
dccce4ee3d
Provide shorthand to blocklist an IP 2018-03-26 17:33:58 -03:00
Gonzalo Rodriguez
0fe30e3a3d
Don't autoload when it's barely valuable to do so
Rack::Attack::PathNormalizer and Rack::Attack::Request are both
used in #call method, which is going to be used by every rack-attack
user as long as they insert the middleware in their app.
2018-03-23 10:58:51 -03:00
Domenoth
5004b04ac7 Change object type yielded to ActiveSupport::Subscribers
https://github.com/kickstarter/rack-attack/issues/255

Change the object type from instances of type Rack::Attack::Request to
instances of type Hash. (`req` becomes `request: req`).
2018-03-21 11:32:09 -07:00
Brad Lindsay
0f6ef47683 Add a seperate cache-store proxy for the redis gem
While a cache-store proxy exists for the redis-store gem, no such proxy
existed for using the redis gem itself. This fills that gap by adding
such a proxy.

Resolves kickstarter/rack-attack#190
2018-02-06 09:33:02 -06:00
Gonzalo Rodriguez
7bb7a05987 Help users understand more clearly when the store is misconfigured 2018-02-01 10:06:39 -03:00
Gonzalo Rodriguez
b7eb7851cf Cleanup unnecessary self references 2018-01-25 15:52:20 -03:00
Eric Garside
5a7114e126 Fixing whitespace issue 2018-01-05 17:38:19 -05:00
Mattias Lundell
c37b477d15 Fix alignment of columns 2017-10-11 13:55:19 +02:00
Aaron Suggs
ebfa081e6d Fix args to deprecated methods
Fixes #197
2016-08-11 13:39:22 -04:00
Aaron Suggs
f5f08d56e5 More safelist/blocklist refactoring
- Add Rack::Attack namespace to deprecation warning.
- Add deprecated Rack::Attack.blacklisted_response attr methods.
2016-07-04 21:42:41 -04:00
Renée Hendricksen
e1a0c804e1 suggesting changing whitelist/blacklist language to less controversial safelist/blocklist language
add deprication warnings

fix the method signatures
2016-07-01 21:44:45 -04:00
Vincent Boisard
c34bace773 style: remove extraneous whitespace 2016-01-07 22:45:11 +01:00
Vincent Boisard
297ef4a2ae Merge branch 'master' of github.com:kickstarter/rack-attack 2015-12-29 10:10:36 +01:00
Aaron Suggs
76c2e31430 Normalize request paths when using Rails' ActionDispatch
The issue
---

When using rack-attack with a rails app, developers expect the request
path to be normalized. In particular, trailing slashes are stripped so
a request path "/login/" becomes "/login" by the time you're in
ActionController.

Since Rack::Attack runs before ActionDispatch, the request path is not
yet normalized. This can cause throttles and blacklists to not work as
expected.

E.g., a throttle:

    throttle('logins', ...) {|req| req.path == "/login" }

would not match a request to '/login/', though Rails would route
'/login/' to the same '/login' action.

The solution
---

This patch looks if ActionDispatch's request normalization is loaded,
and if so, uses it to normalize the path before processing throttles,
blacklists, etc.

If it's not loaded, the request path is not modified.

Credit
---
Thanks to Andres Riancho at Include Security for reporting this issue.
2015-12-18 11:12:11 -05:00
Vincent Boisard
d880bd88e0 fix: workaround MemCacheClient + MemCache backend by using a dedicated proxy 2015-12-16 16:57:54 +01:00
Aaron Suggs
e7efe1cf5f Merge pull request #91 from gsamokovarov/call-responses
Invoke Rack:::{blacklisted,throttled}_response with #call
2014-10-02 14:25:42 -04:00
Genadi Samokovarov
a161176142 Invoke {blacklisted,throttled}_response with #call
I have a response which is a class. While I can still have my class
implement `#[]`, it does look a bit off. On the other side, having
objects, responding to #call, that are not procs is pretty common.

So I propose to invoke the responses with `#call` to let users override
it with response objects, that respond to `#call` instead of `#[]`.
2014-09-25 23:21:02 +02:00
Genadi Samokovarov
f737dbb78c Avoid rescue nil in the default throttled response
It has a couple of cons:

1. If we slip a typo in the whole line, we won't easily catch it.  Can
   you guys spot the problem problem in the following line? Chasing such
   issues is quite tricky.

```ruby
retry_after = evn['rack.attack.match_data'][:period] rescue nil
```

2. Throwing and catching an exception is quite slower than a new hash
   allocation, so there is a speed benefit too.

We are guaranteed from Rack that env is a `Hash`, so we can even use
`Hash#fetch`.

```ruby
retry_after = env.fetch('rack.attack.match_data', {})[:period]
```

This reads better, but always allocates the default value hash, when the
other version allocates it only when needed. If you prefer `Hash#fetch`,
I'm fine with that, as long as we avoid `rescue nil`.
2014-09-25 18:35:53 +02:00