better_rate_limit 0.1.7 → 0.1.10

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: 05720aabc13993c0e8fc708415d4464b6db86b9cdcffab16e9f32b6dabfaa935
4
- data.tar.gz: 4e2c18b7928c45e3276e92d87eb080d977bcde352abe3f55c482afa815806808
3
+ metadata.gz: 454211c4744fb1f5ade5342a54ac4817ae535c7e70ba523152315ca1c2bd0440
4
+ data.tar.gz: d3146d311894d5f6f0cc7d69738e7b1ab2c0794fbc681660ce368d0e798e90e1
5
5
  SHA512:
6
- metadata.gz: a081b16c393cc95387701e41eba68c5109aa8fcb574324042f55830828879d06f14c87a859f667b90b3df56108cb92b2e5d5954272e4169aa2e35d1517da69f8
7
- data.tar.gz: 0db7a65a4135753ebe34fc6c0f34126ede4f41360fb4a3cab4999b2934c244423f9d46cd23c2b31cd18412826399462d256ddc9d41abc89d0feaf64541a64f0c
6
+ metadata.gz: 1f3137c0c5c9b5f8f69eb6c8d7823d0b968597aef3cf0fe89c068b50196d9ea34b247d6988fb9666be23efcf8e43e83f7c19a919c659c7c07c36cb39ffab9bba
7
+ data.tar.gz: 122491394a2ca936a6d0b8f9d45964ce3a948086eebaef777b09121ac5032145d0f64288a5b1219a11f97d6da244112f7bf9782bb533061112fce27f6cbd2788
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- better_rate_limit (0.1.6)
4
+ better_rate_limit (0.1.10)
5
5
  actionpack (>= 5.0)
6
6
  redis (>= 3.3)
7
7
 
@@ -29,6 +29,7 @@ GEM
29
29
  builder (3.2.4)
30
30
  coderay (1.1.3)
31
31
  concurrent-ruby (1.1.9)
32
+ connection_pool (2.2.5)
32
33
  crass (1.0.6)
33
34
  erubi (1.10.0)
34
35
  i18n (1.9.1)
@@ -59,7 +60,10 @@ GEM
59
60
  rails-html-sanitizer (1.4.2)
60
61
  loofah (~> 2.3)
61
62
  rake (12.3.3)
62
- redis (4.3.1)
63
+ redis (5.0.4)
64
+ redis-client (>= 0.7.4)
65
+ redis-client (0.8.0)
66
+ connection_pool
63
67
  thread_safe (0.3.6)
64
68
  timecop (0.9.1)
65
69
  tzinfo (1.2.9)
@@ -9,15 +9,15 @@ module ActionController
9
9
  module ClassMethods
10
10
  def rate_limit(max, options)
11
11
  rate_limits << Limit.build(max, controller_path, {
12
- if: options[:if],
13
- unless: options[:unless],
14
- every: options[:every],
15
- name: options[:name] || controller_path,
16
- scope: options[:scope] || -> { real_ip },
17
- only: options[:only] || [],
18
- except: options[:except] || [],
19
- clear_if: options[:clear_if]
20
- })
12
+ if: options[:if],
13
+ unless: options[:unless],
14
+ every: options[:every],
15
+ name: options[:name] || controller_path,
16
+ scope: options[:scope] || -> { real_ip },
17
+ only: options[:only] || [],
18
+ except: options[:except] || [],
19
+ clear_if: options[:clear_if]
20
+ })
21
21
 
22
22
  before_action :perform_rate_limiting
23
23
  after_action :clear_keys
@@ -61,11 +61,12 @@ module ActionController
61
61
  private
62
62
 
63
63
  def json?
64
- request.xhr? || request.format === :json
64
+ request.xhr? || request.format == :json
65
65
  end
66
66
 
67
67
  def real_ip
68
- request.headers['X-Forwarded-For'].try(:split, ',').try(:[], -2..-2).try(:first).try(:strip)
68
+ request.headers['X-Forwarded-For'].try(:split, ',').try(:last,
69
+ ::BetterRateLimit.configuration.proxies_to_trust).try(:first).try(:strip)
69
70
  end
70
71
 
71
72
  def under_rate_limit?(limit)
@@ -2,7 +2,7 @@
2
2
 
3
3
  module BetterRateLimit
4
4
  class Configuration
5
- attr_accessor :ignore, :redis_client
5
+ attr_accessor :ignore, :redis_client, :proxies_to_trust
6
6
 
7
7
  def initialize
8
8
  @ignore = false
@@ -10,8 +10,8 @@ module BetterRateLimit
10
10
 
11
11
  class << self
12
12
  def throttle(key, limit:, time_window:)
13
- raise MissingRedisConfigError unless redis_client
14
13
  return true if BetterRateLimit.configuration.ignore
14
+ raise MissingRedisConfigError unless redis_client
15
15
 
16
16
  now = Time.now.utc
17
17
  timestamps_count = redis_client.llen key
@@ -35,7 +35,7 @@ module BetterRateLimit
35
35
  passing = first.to_time(:utc) < time_window.ago
36
36
 
37
37
  unless passing
38
- notify(key) unless redis_client.exists('failing-rate-limits:' + key)
38
+ notify(key) unless redis_client.exists?('failing-rate-limits:' + key)
39
39
  redis_client.setex('failing-rate-limits:' + key, time_window.to_i, '1')
40
40
  end
41
41
 
@@ -1,3 +1,3 @@
1
1
  module BetterRateLimit
2
- VERSION = "0.1.7"
2
+ VERSION = '0.1.10'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: better_rate_limit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.7
4
+ version: 0.1.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pablo Fonseca
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2022-07-15 00:00:00.000000000 Z
12
+ date: 2022-09-09 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: redis
@@ -84,7 +84,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
84
84
  - !ruby/object:Gem::Version
85
85
  version: '0'
86
86
  requirements: []
87
- rubygems_version: 3.2.22
87
+ rubygems_version: 3.1.4
88
88
  signing_key:
89
89
  specification_version: 4
90
90
  summary: Rate limit requests