cloudflare-rails 1.1.0 → 2.2.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: 6060b63792255ed6aebab33986d27092b1866052db8fcf496942692f1c51508d
4
- data.tar.gz: 40d72f9bfefac5cf2f64c681d8833efb807ce20b314cd0433e9e07c03917b7ae
3
+ metadata.gz: 84dc9aec556073a4d870a4784e841e63f8a047ade776f55646617d90ae57a350
4
+ data.tar.gz: b2d3411fae45afc2e4f9586dc3c9fddd966c2dab028fdef278a2e57e2fb11cca
5
5
  SHA512:
6
- metadata.gz: 3a0ac66d56d0a62957c73b564e9bc5586bb9328e146598e2b342de74bcd75e1a24541ae4b22fbd17f502a5a9a40c57a0e07bcd3b348950843d17b9cee0cc8d59
7
- data.tar.gz: f175720c6f4f109a3ea1bc34c1e62bf1661a60df5e83c132e3677b078c6064359ca0c5afd98c26b8962e38c5692c876094146e1de586e8461ba1dc7c25854a11
6
+ metadata.gz: 77da9de7361192e828223e3ee2da7213e8f502971b2bb503f8454e14210233bbabab107dce472d8477b0ef123bb389a8fc31b07fe0bc54d41ccbd5f0312fd474
7
+ data.tar.gz: 5581a9d55303a8ec303e2e95497d87c20a973ae451f0a38bee98310dffb0d5b408d43b773808c7258acd7ad2c7a657638e874fb67a1d2c1df2bafd54a910eb72
data/.circleci/config.yml CHANGED
@@ -7,7 +7,7 @@ jobs:
7
7
  build:
8
8
  docker:
9
9
  # specify the version you desire here
10
- - image: circleci/ruby:2.7.0
10
+ - image: circleci/ruby:2.7.3
11
11
 
12
12
  working_directory: ~/repo
13
13
 
@@ -21,6 +21,11 @@ jobs:
21
21
  # fallback to using the latest cache if no exact match is found
22
22
  - v1-dependencies-
23
23
 
24
+ - run:
25
+ name: install bundler
26
+ command: |
27
+ gem install bundler -v $(grep bundler cloudflare-rails.gemspec |awk {'print $4'}|sed 's/"//g')
28
+
24
29
  - run:
25
30
  name: install dependencies
26
31
  command: |
data/Appraisals CHANGED
@@ -1,11 +1,3 @@
1
- appraise "rails-5.0" do
2
- gem "rails", "~> 5.0.0"
3
- end
4
-
5
- appraise "rails-5.1" do
6
- gem "rails", "~> 5.1.0"
7
- end
8
-
9
1
  appraise "rails-5.2" do
10
2
  gem "rails", "~> 5.2.0"
11
3
  end
@@ -17,3 +9,7 @@ end
17
9
  appraise "rails-6.1" do
18
10
  gem "rails", "~> 6.1.0"
19
11
  end
12
+
13
+ appraise "rails-7.0" do
14
+ gem "rails", git: "https://github.com/rails/rails", branch: "main"
15
+ end
data/CHANGELOG.md CHANGED
@@ -4,7 +4,20 @@ All notable changes to this project will be documented in this file.
4
4
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
5
5
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
6
6
 
7
- ## [Unreleased]
7
+ ## [2.2.0] - 2021-06-11
8
+ - Fix typo in `actionpack` dependency
9
+
10
+ ## [2.1.0] - 2021-06-11
11
+ ### Breaking Changes
12
+ - Drop support for unsupported `rails` versions (`5.0.x` and `5.1.x`)
13
+
14
+ ### Added
15
+ - use Net::HTTP instead of httparty ([pr](https://github.com/modosc/cloudflare-rails/pull/44))
16
+ - Add `rails 7.0.0.alpha` support
17
+
18
+ ## [2.0.0] - 2021-02-17
19
+ ### Breaking Changes
20
+ - Removed broad dependency on `rails`, replaced with explicit dependencies for `railties`, `activesupport`, and `actionpack` ( [issue](https://github.com/modosc/cloudflare-rails/issues/34) and [pr](https://github.com/modosc/cloudflare-rails/pull/35))
8
21
 
9
22
  ## [1.0.0] - 2020-09-29
10
23
  ### Added
data/Gemfile CHANGED
@@ -2,3 +2,7 @@ source 'https://rubygems.org'
2
2
 
3
3
  # Specify your gem's dependencies in cloudflare-rails.gemspec
4
4
  gemspec
5
+
6
+ group :development do
7
+ gem "rspec-isolation", git: "https://github.com/modosc/rspec-isolation"
8
+ end
data/README.md CHANGED
@@ -3,7 +3,11 @@ This gem correctly configures Rails for [CloudFlare](https://www.cloudflare.com)
3
3
 
4
4
  ## Rails Compatibility
5
5
 
6
- This gem requires Rails >= 5. The last version that supports Rails 4.2 is `0.1.x`.
6
+ This gem requires `railties`, `activesupport`, and `actionpack` >= `5.2`.
7
+
8
+ For Rails `5.0` and `5.1` use `2.0.0`.
9
+
10
+ For Rails `4.2` use `0.1.x`.
7
11
 
8
12
  ## Installation
9
13
 
@@ -25,7 +29,7 @@ And then execute:
25
29
 
26
30
  Using Cloudflare means it's hard to identify the IP address of incoming requests since all requests are proxied through Cloudflare's infrastructure. Cloudflare provides a [CF-Connecting-IP](https://support.cloudflare.com/hc/en-us/articles/200170986-How-does-Cloudflare-handle-HTTP-Request-headers-) header which can be used to identify the originating IP address of a request. However, this header alone doesn't verify a request is legitimate. If an attacker has found the actual IP address of your server they could spoof this header and masquerade as legitimate traffic.
27
31
 
28
- `cloudflare-rails` mitigates this attack by checking that the originating ip address of any incoming connecting is from one of Cloudflare's ip address ranges. If so, the incoming `X-Forwarded-For` header is trusted and used as the ip address provided to `rack` and `rails` (via `request.ip` and `request.remote_ip`). If the incoming connection does not originate from a Cloudflare server then the `X-Forwarded-For` header is ignored and the actual remote ip address is used.
32
+ `cloudflare-rails` mitigates this attack by checking that the originating ip address of any incoming connection is from one of Cloudflare's ip address ranges. If so, the incoming `X-Forwarded-For` header is trusted and used as the ip address provided to `rack` and `rails` (via `request.ip` and `request.remote_ip`). If the incoming connection does not originate from a Cloudflare server then the `X-Forwarded-For` header is ignored and the actual remote ip address is used.
29
33
 
30
34
  ## Usage
31
35
  This code will fetch CloudFlare's current [IPv4](https://www.cloudflare.com/ips-v4) and [IPv6](https://www.cloudflare.com/ips-v6) lists, store them in `Rails.cache`, and add them to `config.cloudflare.ips`. The `X-Forwarded-For` header will then be trusted only from those ip addresses.
@@ -20,19 +20,20 @@ Gem::Specification.new do |spec|
20
20
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
21
21
  spec.require_paths = ["lib"]
22
22
 
23
- spec.add_development_dependency "bundler", "~> 2.1.2"
23
+ spec.add_development_dependency "bundler", ">= 2.1.2"
24
24
  spec.add_development_dependency "rake", "~> 13.0.1"
25
25
  spec.add_development_dependency "rspec_junit_formatter", "~> 0.4.1"
26
- spec.add_development_dependency "rspec-rails", "~> 4.0.0"
26
+ spec.add_development_dependency "rspec-rails", "~> 5.0.1"
27
27
  spec.add_development_dependency "rspec", "~> 3.10.0"
28
28
  spec.add_development_dependency "rubocop-airbnb", "~> 3.0.2"
29
- spec.add_development_dependency "webmock", "~> 3.10.0"
30
- spec.add_development_dependency "rack-attack", "~> 6.3.0"
29
+ spec.add_development_dependency "webmock", "~> 3.13.0"
30
+ spec.add_development_dependency "rack-attack", "~> 6.5.0"
31
31
  spec.add_development_dependency "pry-byebug"
32
32
  spec.add_development_dependency "appraisal"
33
33
 
34
- spec.add_dependency "httparty"
35
- spec.add_dependency "rails", ">= 5.0", "< 6.2.0"
34
+ spec.add_dependency "railties", ">= 5.2", "< 7.1.0"
35
+ spec.add_dependency "activesupport", ">= 5.2", "< 7.1.0"
36
+ spec.add_dependency "actionpack", ">= 5.2", "< 7.1.0"
36
37
 
37
38
  # we need Module#prepend
38
39
  spec.required_ruby_version = '>= 2.0'
@@ -4,4 +4,8 @@ source "https://rubygems.org"
4
4
 
5
5
  gem "rails", "~> 5.2.0"
6
6
 
7
+ group :development do
8
+ gem "rspec-isolation", git: "https://github.com/modosc/rspec-isolation"
9
+ end
10
+
7
11
  gemspec path: "../"
@@ -4,4 +4,8 @@ source "https://rubygems.org"
4
4
 
5
5
  gem "rails", "~> 6.0.0"
6
6
 
7
+ group :development do
8
+ gem "rspec-isolation", git: "https://github.com/modosc/rspec-isolation"
9
+ end
10
+
7
11
  gemspec path: "../"
@@ -4,4 +4,8 @@ source "https://rubygems.org"
4
4
 
5
5
  gem "rails", "~> 6.1.0"
6
6
 
7
+ group :development do
8
+ gem "rspec-isolation", git: "https://github.com/modosc/rspec-isolation"
9
+ end
10
+
7
11
  gemspec path: "../"
@@ -0,0 +1,11 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "rails", git: "https://github.com/rails/rails", branch: "main"
6
+
7
+ group :development do
8
+ gem "rspec-isolation", git: "https://github.com/modosc/rspec-isolation"
9
+ end
10
+
11
+ gemspec path: "../"
@@ -1,4 +1,4 @@
1
- require "httparty"
1
+ require "active_support/core_ext/integer/time"
2
2
 
3
3
  module Cloudflare
4
4
  module Rails
@@ -20,13 +20,23 @@ module Cloudflare
20
20
  end
21
21
 
22
22
  class Importer
23
- include HTTParty
24
- base_uri 'https://www.cloudflare.com'
25
- follow_redirects true
26
- default_options.update(verify: true)
23
+ # Exceptions contain the Net::HTTP
24
+ # response object accessible via the {#response} method.
25
+ class ResponseError < StandardError
26
+ # Returns the response of the last request
27
+ # @return [Net::HTTPResponse] A subclass of Net::HTTPResponse, e.g.
28
+ # Net::HTTPOK
29
+ attr_reader :response
27
30
 
28
- class ResponseError < HTTParty::ResponseError; end
31
+ # Instantiate an instance of ResponseError with a Net::HTTPResponse object
32
+ # @param [Net::HTTPResponse]
33
+ def initialize(response)
34
+ @response = response
35
+ super(response)
36
+ end
37
+ end
29
38
 
39
+ BASE_URL = 'https://www.cloudflare.com'.freeze
30
40
  IPS_V4_URL = '/ips-v4'.freeze
31
41
  IPS_V6_URL = '/ips-v6'.freeze
32
42
 
@@ -40,11 +50,21 @@ module Cloudflare
40
50
  end
41
51
 
42
52
  def fetch(url)
43
- resp = get url, timeout: ::Rails.application.config.cloudflare.timeout
44
- if resp.success?
53
+ uri = URI("#{BASE_URL}#{url}")
54
+
55
+ resp = Net::HTTP.start(uri.host,
56
+ uri.port,
57
+ use_ssl: true,
58
+ read_timeout: ::Rails.application.config.cloudflare.timeout) do |http|
59
+ req = Net::HTTP::Get.new(uri)
60
+
61
+ http.request(req)
62
+ end
63
+
64
+ if resp.is_a?(Net::HTTPSuccess)
45
65
  resp.body.split("\n").reject(&:blank?).map { |ip| IPAddr.new ip }
46
66
  else
47
- raise ResponseError, resp.response
67
+ raise ResponseError, resp
48
68
  end
49
69
  end
50
70
 
@@ -1,5 +1,5 @@
1
1
  module Cloudflare
2
2
  module Rails
3
- VERSION = "1.1.0".freeze
3
+ VERSION = "2.2.0".freeze
4
4
  end
5
5
  end
@@ -1,5 +1,6 @@
1
1
  require "cloudflare/rails/version"
2
- require "httparty"
2
+ require 'net/http'
3
+ require 'uri'
3
4
 
4
5
  module Cloudflare
5
6
  module Rails
metadata CHANGED
@@ -1,27 +1,27 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cloudflare-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 2.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - jonathan schatz
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-12-09 00:00:00.000000000 Z
11
+ date: 2021-06-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: 2.1.2
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - "~>"
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: 2.1.2
27
27
  - !ruby/object:Gem::Dependency
@@ -58,14 +58,14 @@ dependencies:
58
58
  requirements:
59
59
  - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: 4.0.0
61
+ version: 5.0.1
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: 4.0.0
68
+ version: 5.0.1
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: rspec
71
71
  requirement: !ruby/object:Gem::Requirement
@@ -100,28 +100,28 @@ dependencies:
100
100
  requirements:
101
101
  - - "~>"
102
102
  - !ruby/object:Gem::Version
103
- version: 3.10.0
103
+ version: 3.13.0
104
104
  type: :development
105
105
  prerelease: false
106
106
  version_requirements: !ruby/object:Gem::Requirement
107
107
  requirements:
108
108
  - - "~>"
109
109
  - !ruby/object:Gem::Version
110
- version: 3.10.0
110
+ version: 3.13.0
111
111
  - !ruby/object:Gem::Dependency
112
112
  name: rack-attack
113
113
  requirement: !ruby/object:Gem::Requirement
114
114
  requirements:
115
115
  - - "~>"
116
116
  - !ruby/object:Gem::Version
117
- version: 6.3.0
117
+ version: 6.5.0
118
118
  type: :development
119
119
  prerelease: false
120
120
  version_requirements: !ruby/object:Gem::Requirement
121
121
  requirements:
122
122
  - - "~>"
123
123
  - !ruby/object:Gem::Version
124
- version: 6.3.0
124
+ version: 6.5.0
125
125
  - !ruby/object:Gem::Dependency
126
126
  name: pry-byebug
127
127
  requirement: !ruby/object:Gem::Requirement
@@ -151,39 +151,65 @@ dependencies:
151
151
  - !ruby/object:Gem::Version
152
152
  version: '0'
153
153
  - !ruby/object:Gem::Dependency
154
- name: httparty
154
+ name: railties
155
155
  requirement: !ruby/object:Gem::Requirement
156
156
  requirements:
157
157
  - - ">="
158
158
  - !ruby/object:Gem::Version
159
- version: '0'
159
+ version: '5.2'
160
+ - - "<"
161
+ - !ruby/object:Gem::Version
162
+ version: 7.1.0
160
163
  type: :runtime
161
164
  prerelease: false
162
165
  version_requirements: !ruby/object:Gem::Requirement
163
166
  requirements:
164
167
  - - ">="
165
168
  - !ruby/object:Gem::Version
166
- version: '0'
169
+ version: '5.2'
170
+ - - "<"
171
+ - !ruby/object:Gem::Version
172
+ version: 7.1.0
173
+ - !ruby/object:Gem::Dependency
174
+ name: activesupport
175
+ requirement: !ruby/object:Gem::Requirement
176
+ requirements:
177
+ - - ">="
178
+ - !ruby/object:Gem::Version
179
+ version: '5.2'
180
+ - - "<"
181
+ - !ruby/object:Gem::Version
182
+ version: 7.1.0
183
+ type: :runtime
184
+ prerelease: false
185
+ version_requirements: !ruby/object:Gem::Requirement
186
+ requirements:
187
+ - - ">="
188
+ - !ruby/object:Gem::Version
189
+ version: '5.2'
190
+ - - "<"
191
+ - !ruby/object:Gem::Version
192
+ version: 7.1.0
167
193
  - !ruby/object:Gem::Dependency
168
- name: rails
194
+ name: actionpack
169
195
  requirement: !ruby/object:Gem::Requirement
170
196
  requirements:
171
197
  - - ">="
172
198
  - !ruby/object:Gem::Version
173
- version: '5.0'
199
+ version: '5.2'
174
200
  - - "<"
175
201
  - !ruby/object:Gem::Version
176
- version: 6.2.0
202
+ version: 7.1.0
177
203
  type: :runtime
178
204
  prerelease: false
179
205
  version_requirements: !ruby/object:Gem::Requirement
180
206
  requirements:
181
207
  - - ">="
182
208
  - !ruby/object:Gem::Version
183
- version: '5.0'
209
+ version: '5.2'
184
210
  - - "<"
185
211
  - !ruby/object:Gem::Version
186
- version: 6.2.0
212
+ version: 7.1.0
187
213
  description: ''
188
214
  email:
189
215
  - modosc@users.noreply.github.com
@@ -209,11 +235,10 @@ files:
209
235
  - bin/setup
210
236
  - cloudflare-rails.gemspec
211
237
  - gemfiles/.bundle/config
212
- - gemfiles/rails_5.0.gemfile
213
- - gemfiles/rails_5.1.gemfile
214
238
  - gemfiles/rails_5.2.gemfile
215
239
  - gemfiles/rails_6.0.gemfile
216
240
  - gemfiles/rails_6.1.gemfile
241
+ - gemfiles/rails_7.0.gemfile
217
242
  - lib/cloudflare/rails.rb
218
243
  - lib/cloudflare/rails/railtie.rb
219
244
  - lib/cloudflare/rails/version.rb
@@ -236,7 +261,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
236
261
  - !ruby/object:Gem::Version
237
262
  version: '0'
238
263
  requirements: []
239
- rubygems_version: 3.1.2
264
+ rubygems_version: 3.2.18
240
265
  signing_key:
241
266
  specification_version: 4
242
267
  summary: This gem configures Rails for CloudFlare so that request.ip and request.remote_ip
@@ -1,7 +0,0 @@
1
- # This file was generated by Appraisal
2
-
3
- source "https://rubygems.org"
4
-
5
- gem "rails", "~> 5.0.0"
6
-
7
- gemspec path: "../"
@@ -1,7 +0,0 @@
1
- # This file was generated by Appraisal
2
-
3
- source "https://rubygems.org"
4
-
5
- gem "rails", "~> 5.1.0"
6
-
7
- gemspec path: "../"