vpndetection-rails 2.1.23 → 2.1.25
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 +4 -4
- data/README.md +10 -10
- data/lib/vpndetection/rails/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: d32eb7fab945784a513946647d35922a2149e3e8877b12611c3266b918c916dc
|
|
4
|
+
data.tar.gz: b32f52d52f36c8532a41c9dc1d67af768d88799a93a713ba59d56fb0fc45b1ea
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 4afe0a2650817d62e2300e47f3ee5fdac01901b5dbcce1898d70805f6826b35c3e1279b32ff1d4c2208bb7609000244f38bff1bcf7b2a04bf849dd340ad7f153
|
|
7
|
+
data.tar.gz: 763b5e626cc8c4e340173f856afeed657b7960bb36eda8173fca4cdf29e4c09b4ddd3c0d8eda6c50f05c733fef4bc1758d361b06a1020d79085fb6e236d62c25
|
data/README.md
CHANGED
|
@@ -3,9 +3,9 @@
|
|
|
3
3
|
[](https://rubygems.org/gems/vpndetection-rails)
|
|
4
4
|
[](LICENSE)
|
|
5
5
|
|
|
6
|
-
The official Rails middleware for the [VPNDetection](https://vpndetection.io) API.
|
|
6
|
+
The official Rails middleware for the [VPNDetection](https://vpndetection.io) API: it checks each visitor's IP for VPN, Tor and proxy use, and can block them with a 403.
|
|
7
7
|
|
|
8
|
-
It classifies the visitor behind each request
|
|
8
|
+
It classifies the visitor behind each request as VPN, residential proxy, Tor, hosting, CDN or relay, and hands the answer to your controllers. Blocking is opt-in.
|
|
9
9
|
|
|
10
10
|
It is Rack middleware, so it works in Sinatra, Hanami, Roda or a bare Rack app too; the Railtie is only what saves a Rails user from inserting it by hand.
|
|
11
11
|
|
|
@@ -15,9 +15,9 @@ It is Rack middleware, so it works in Sinatra, Hanami, Roda or a bare Rack app t
|
|
|
15
15
|
bundle add vpndetection-rails
|
|
16
16
|
```
|
|
17
17
|
|
|
18
|
-
Requires Ruby 3.3 or newer.
|
|
18
|
+
Requires Ruby 3.3 or newer, and libcurl at runtime, which the `curl` package brings on Debian and Alpine. The Dockerfile Rails generates already installs it.
|
|
19
19
|
|
|
20
|
-
|
|
20
|
+
No API key needed to start. Without one, a lookup is on Unlimited, the free plan, which answers VPN, Tor and relay detection with no daily or monthly cap. A paid plan's key adds the hosting, CDN and proxy flags and the provider behind each flag: create one in the [console](https://app.vpndetection.io). A free account tries every field.
|
|
21
21
|
|
|
22
22
|
```ruby
|
|
23
23
|
# config/application.rb
|
|
@@ -39,7 +39,7 @@ In a non-Rails Rack app, insert it yourself:
|
|
|
39
39
|
use VPNDetection::Rails::Middleware, api_key: ENV["VPNDETECTION_API_KEY"]
|
|
40
40
|
```
|
|
41
41
|
|
|
42
|
-
By default nothing is blocked. Every request gets an answer and your own code decides what
|
|
42
|
+
By default nothing is blocked. Every request gets an answer and your own code decides what to do with it, since whether a VPN visitor is a problem depends on what they're doing.
|
|
43
43
|
|
|
44
44
|
## Blocking
|
|
45
45
|
|
|
@@ -68,9 +68,9 @@ on_blocked: ->(request, lookup) { [303, { "location" => "/no-vpn" }, []] }
|
|
|
68
68
|
|
|
69
69
|
## Where the client address comes from
|
|
70
70
|
|
|
71
|
-
|
|
71
|
+
Get this setting right, or none of the above works.
|
|
72
72
|
|
|
73
|
-
**In Rails**, the default reads `env["action_dispatch.remote_ip"]
|
|
73
|
+
**In Rails**, the default reads `env["action_dispatch.remote_ip"]`, the answer `ActionDispatch::RemoteIp` computed from `X-Forwarded-For` minus your `config.action_dispatch.trusted_proxies`. That is the right fix behind a load balancer: tell Rails which proxies are yours and it resolves the visitor for you. `Rack::Request#ip` does *not* read that entry, so reading Rails' own is what makes your `trusted_proxies` mean anything here. **With nothing in front of the app server, that default can be forged**: `RemoteIp` believes `X-Forwarded-For` without checking that the connection came from a proxy, so any visitor picks the address that gets looked up. There, pass `ip_selector: ->(request) { request.ip }`. The middleware warns once when it sees that setup: a request carrying `X-Forwarded-For`, `Client-IP` or `Forwarded` from a public address outside `trusted_proxies`.
|
|
74
74
|
|
|
75
75
|
**In a bare Rack app** there is no such entry and the default falls back to `Rack::Request#ip`. Rack's `ip` returns the connecting address, `REMOTE_ADDR`, unless that is a trusted proxy, which by default means a loopback or private address. Only then does it read the forwarding headers, and it takes the right-most entry that is not a trusted proxy. The test suite pins both. Behind an edge on a public address, or one that appends rather than overwrites, name your edge's header instead:
|
|
76
76
|
|
|
@@ -78,7 +78,7 @@ This is the setting that decides whether any of the above works, and it is the o
|
|
|
78
78
|
ip_selector: VPNDetection::Rails.header_ip_selector("CF-Connecting-IP")
|
|
79
79
|
```
|
|
80
80
|
|
|
81
|
-
`VPNDetection::Rails.xff_ip_selector` reads `X-Forwarded-For` directly, and `xff_ip_selector(1)` counts one trusted hop from the right. Anything else, pass your own callable
|
|
81
|
+
`VPNDetection::Rails.xff_ip_selector` reads `X-Forwarded-For` directly, and `xff_ip_selector(1)` counts one trusted hop from the right. Anything else, pass your own callable: it receives the Rack request and returns an address.
|
|
82
82
|
|
|
83
83
|
**Behind a proxy that writes only `X-Forwarded-For`, a visitor's own `Forwarded` header names the address.** Rack 3 reads `Forwarded` first, for `Rack::Request#ip` and Rails' `remote_ip` alike, and nginx passes a visitor's copy through untouched, so a request sending `Forwarded: for=1.1.1.1` is looked up as `1.1.1.1`. Clear the header at the proxy, `proxy_set_header Forwarded "";` in nginx, or tell Rack to read `X-Forwarded-For` alone at the top of `config.ru`:
|
|
84
84
|
|
|
@@ -96,7 +96,7 @@ The request is let through, and the reason is on `lookup.error`. Our outage shou
|
|
|
96
96
|
|
|
97
97
|
## Cost and latency
|
|
98
98
|
|
|
99
|
-
Answers are cached for an hour, so a returning visitor costs nothing, and private addresses never leave the process. A cache miss is one request to our API, bounded at 2.5 seconds by default and not retried
|
|
99
|
+
Answers are cached for an hour, so a returning visitor costs nothing, and private addresses never leave the process. A cache miss is one request to our API, bounded at 2.5 seconds by default and not retried: on a request path, failing open fast beats holding a visitor while we retry.
|
|
100
100
|
|
|
101
101
|
Files in `public/`, compiled assets included, never reach the middleware: `ActionDispatch::Static` answers them first, so they cost no lookup. Skip the routes you do not care about:
|
|
102
102
|
|
|
@@ -108,7 +108,7 @@ Beyond a few million distinct visitors a day, stop calling the API per request:
|
|
|
108
108
|
|
|
109
109
|
## Absent is not false
|
|
110
110
|
|
|
111
|
-
Unlimited, with a key or without one, leaves out `is_hosting`, `is_cdn` and the four proxy flags, and of the detail behind each flag it answers only Tor's and relay's. A member your plan does not include is `nil`, which means "not in your plan" rather than "checked, and no"
|
|
111
|
+
Unlimited, with a key or without one, leaves out `is_hosting`, `is_cdn` and the four proxy flags, and of the detail behind each flag it answers only Tor's and relay's. A member your plan does not include is `nil`, which means "not in your plan" rather than "checked, and no". Ruby makes that easy to lose, since `nil` and `false` are both falsy.
|
|
112
112
|
|
|
113
113
|
```ruby
|
|
114
114
|
lookup.result.hosting? # true or false, never nil
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: vpndetection-rails
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 2.1.
|
|
4
|
+
version: 2.1.25
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Mslm Dev
|
|
@@ -29,7 +29,7 @@ dependencies:
|
|
|
29
29
|
requirements:
|
|
30
30
|
- - ">="
|
|
31
31
|
- !ruby/object:Gem::Version
|
|
32
|
-
version: 5.
|
|
32
|
+
version: 5.18.0
|
|
33
33
|
- - "<"
|
|
34
34
|
- !ruby/object:Gem::Version
|
|
35
35
|
version: '6'
|
|
@@ -39,7 +39,7 @@ dependencies:
|
|
|
39
39
|
requirements:
|
|
40
40
|
- - ">="
|
|
41
41
|
- !ruby/object:Gem::Version
|
|
42
|
-
version: 5.
|
|
42
|
+
version: 5.18.0
|
|
43
43
|
- - "<"
|
|
44
44
|
- !ruby/object:Gem::Version
|
|
45
45
|
version: '6'
|