rack-dedos 0.7.3 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1876d028a80926559978d4afff1d011227355de81868bc6a2bf78377199ca7e3
4
- data.tar.gz: 915be1922ba19ea3c4f64e4710994eee3e74a1a8ae383554dccd72ef4213775f
3
+ metadata.gz: a08f36618682f6ea88356457ae136dd78a470598e8254f537a56952435baf744
4
+ data.tar.gz: 4c24311d19a2bc7e8be8593b43022b35569a00ffe9a8293dd08df614afa50809
5
5
  SHA512:
6
- metadata.gz: f7452453fd2b4a36a02398fc32563e386f4ab42e35a50e082db295b2584a947b7bf36e8216ac331f8ac54a9d0ac5fe9c7d4e2e59192237142a535357abfb344c
7
- data.tar.gz: e8c5f2118f9eb86dba94ef777a1e6f6339367467051ace6740addb23152b4715b3d6ed59c624fe83ec4912d2fd6a80253b1112578ebc0d72ed85c76b193afd2b
6
+ metadata.gz: e4ffc6eaf1591ccd9359f5df317e72f67fbd08bcfd0df2c06389c468e4f41292afe922b4ed81e6b4fe2094a6931824b5baf8d982e1deafc79604d3d57a44931f
7
+ data.tar.gz: d15648fe182352df2979a8c0307ba9bcdf2c481e356e97e080fc892d870422aa8a9eedf974f25095db66026b534e167d6c8039bbabc0c374e5d8dc11d9dce20d
data/CHANGELOG.md CHANGED
@@ -1,7 +1,3 @@
1
- ## Main
2
-
3
- Nothing so far
4
-
5
1
  # Changelog
6
2
 
7
3
  All notable changes to this project will be documented in this file.
@@ -13,6 +9,12 @@ and this project adheres to [Break Versioning](https://www.taoensso.com/break-ve
13
9
 
14
10
  Nothing so far
15
11
 
12
+ ## [1.0.0] - 2026-11-22
13
+
14
+ ### Changed
15
+
16
+ - **Breaking:** Modify the real IP detection added in [0.2.0]: If the default `request.ip` reported by Rack doesn't return the real IP, either use `Rack::Request.ip_filter` to fix it or pass the real IP of the connecting party explicitly (see README). `CF-Connecting-IP` and `X-Forwarded-For` headers are no longer consulted to prevent bypassing the filters by forging those.
17
+
16
18
  ## [0.7.3] - 2026-06-26
17
19
 
18
20
  ### Changed
data/README.md CHANGED
@@ -92,9 +92,20 @@ end
92
92
 
93
93
  Given the drastic nature of the filters, you should use this middleware for production environments only and/or if an environment variable like `UNDER_ATTACK` is set to true.
94
94
 
95
+ ### Real IP
96
+
97
+ By default, `request.ip` provided by Rack is used to figure out the IP of the connecting client. Depending on the web framework you use or reverse proxies such as Cloudflare, this value might not contain the correct IP address.
98
+
99
+ However, it is possible to override this default behavior. Rails' Action Dispatch for instance determines `remote_ip` using its own mechanism. You can use this value instead with:
100
+
101
+ ```ruby
102
+ use Rack::Dedos,
103
+ ip: ->(request) { request.env['action_dispatch.remote_ip'].to_s }
104
+ ```
105
+
95
106
  ### Request
96
107
 
97
- By default, filters are applied to all request paths. You can norrow this to only certain matching request paths:
108
+ By default, filters are applied to all request paths. You can narrow this to only certain matching request paths:
98
109
 
99
110
  ```ruby
100
111
  use Rack::Dedos,
@@ -8,6 +8,7 @@ module Rack
8
8
  class Base
9
9
 
10
10
  DEFAULT_OPTIONS = {
11
+ ip: nil,
11
12
  logger: nil,
12
13
  cache_url: 'Hash',
13
14
  cache_key_prefix: nil,
@@ -61,22 +62,11 @@ module Rack
61
62
 
62
63
  # Get the real IP of the client
63
64
  #
64
- # If containers and/or proxies such as Cloudflare are in the mix, the
65
- # client IP reported by Rack may be wrong. Therefore, we determine the
66
- # real client IP using the following priorities:
67
- #
68
- # 1. Cf-Connecting-Ip header
69
- # 2. X-Forwarded-For header (also remove port number)
70
- # 3. IP reported by Rack
71
- #
72
65
  # @param request [Rack::Request]
73
- # @return [String] real client IP
66
+ # @return [String] IP
74
67
  def real_ip(request)
75
- case
76
- when ip = request.get_header('HTTP_CF_CONNECTING_IP')
77
- ip
78
- when forwarded_for = request.forwarded_for
79
- forwarded_for.split(/\s*,\s*/).first&.sub(/:\d+$/, '')
68
+ if (callable = @options[:ip]).respond_to? :call
69
+ callable.call(request)
80
70
  else
81
71
  request.ip
82
72
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Rack
4
4
  module Dedos
5
- VERSION = "0.7.3"
5
+ VERSION = "1.0.0"
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rack-dedos
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.3
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sven Schwyn
@@ -183,7 +183,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
183
183
  - !ruby/object:Gem::Version
184
184
  version: '0'
185
185
  requirements: []
186
- rubygems_version: 4.0.10
186
+ rubygems_version: 4.0.20
187
187
  specification_version: 4
188
188
  summary: Radical filters to block denial-of-service (DoS) requests.
189
189
  test_files: []