vpndetection 5.21.0 → 5.22.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.
Files changed (75) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +3 -3
  3. data/lib/vpndetection/api/account_wire_api.rb +2 -2
  4. data/lib/vpndetection/api/api_keys_wire_api.rb +2 -2
  5. data/lib/vpndetection/api/authorization_wire_api.rb +2 -2
  6. data/lib/vpndetection/api/database_wire_api.rb +2 -2
  7. data/lib/vpndetection/api/entitlement_wire_api.rb +2 -2
  8. data/lib/vpndetection/api/lookup_wire_api.rb +2 -2
  9. data/lib/vpndetection/api/organization_wire_api.rb +2 -2
  10. data/lib/vpndetection/api_client.rb +2 -2
  11. data/lib/vpndetection/api_error.rb +2 -2
  12. data/lib/vpndetection/api_model_base.rb +2 -2
  13. data/lib/vpndetection/configuration.rb +2 -2
  14. data/lib/vpndetection/middleware/core.rb +90 -17
  15. data/lib/vpndetection/middleware/crawlers.rb +74 -0
  16. data/lib/vpndetection/models/abuse_contact.rb +3 -3
  17. data/lib/vpndetection/models/account_create_apikey_request.rb +2 -2
  18. data/lib/vpndetection/models/account_created_apikey.rb +2 -2
  19. data/lib/vpndetection/models/account_org.rb +2 -2
  20. data/lib/vpndetection/models/account_org_ref.rb +2 -2
  21. data/lib/vpndetection/models/account_org_wrap.rb +2 -2
  22. data/lib/vpndetection/models/account_rc.rb +2 -2
  23. data/lib/vpndetection/models/account_revealed_apikey.rb +2 -2
  24. data/lib/vpndetection/models/account_user.rb +2 -2
  25. data/lib/vpndetection/models/apikey_detail.rb +2 -2
  26. data/lib/vpndetection/models/apikey_list.rb +2 -2
  27. data/lib/vpndetection/models/asn.rb +2 -2
  28. data/lib/vpndetection/models/batch_lookup_error.rb +2 -2
  29. data/lib/vpndetection/models/batch_lookup_request.rb +2 -2
  30. data/lib/vpndetection/models/batch_lookup_response.rb +2 -2
  31. data/lib/vpndetection/models/bit_torrent_detail.rb +2 -2
  32. data/lib/vpndetection/models/bot_detail.rb +2 -2
  33. data/lib/vpndetection/models/carrier_detail.rb +2 -2
  34. data/lib/vpndetection/models/class_detail.rb +2 -2
  35. data/lib/vpndetection/models/client_registration.rb +2 -2
  36. data/lib/vpndetection/models/client_registration_request.rb +2 -2
  37. data/lib/vpndetection/models/company.rb +3 -3
  38. data/lib/vpndetection/models/database.rb +2 -2
  39. data/lib/vpndetection/models/database_checksums_response.rb +2 -2
  40. data/lib/vpndetection/models/database_format.rb +2 -2
  41. data/lib/vpndetection/models/database_format_size.rb +2 -2
  42. data/lib/vpndetection/models/database_list.rb +2 -2
  43. data/lib/vpndetection/models/database_metadata.rb +2 -2
  44. data/lib/vpndetection/models/database_metadata_column.rb +2 -2
  45. data/lib/vpndetection/models/database_version.rb +2 -2
  46. data/lib/vpndetection/models/db_checksums.rb +2 -2
  47. data/lib/vpndetection/models/device_authorization.rb +2 -2
  48. data/lib/vpndetection/models/dns_resolver_detail.rb +2 -2
  49. data/lib/vpndetection/models/download.rb +2 -2
  50. data/lib/vpndetection/models/download_list.rb +2 -2
  51. data/lib/vpndetection/models/entitlement.rb +2 -2
  52. data/lib/vpndetection/models/entitlement_apikey.rb +2 -2
  53. data/lib/vpndetection/models/entitlement_error.rb +2 -2
  54. data/lib/vpndetection/models/entitlement_plan.rb +3 -3
  55. data/lib/vpndetection/models/entitlement_usage.rb +4 -4
  56. data/lib/vpndetection/models/error_envelope.rb +2 -2
  57. data/lib/vpndetection/models/identity.rb +2 -2
  58. data/lib/vpndetection/models/location.rb +12 -12
  59. data/lib/vpndetection/models/lookup_error.rb +2 -2
  60. data/lib/vpndetection/models/lookup_response.rb +30 -30
  61. data/lib/vpndetection/models/oauth_error.rb +2 -2
  62. data/lib/vpndetection/models/oauth_metadata.rb +2 -2
  63. data/lib/vpndetection/models/proxy_detail.rb +2 -2
  64. data/lib/vpndetection/models/pubproxy_detail.rb +2 -2
  65. data/lib/vpndetection/models/satellite_detail.rb +2 -2
  66. data/lib/vpndetection/models/smtp_detail.rb +2 -2
  67. data/lib/vpndetection/models/ssh_detail.rb +2 -2
  68. data/lib/vpndetection/models/standing.rb +2 -2
  69. data/lib/vpndetection/models/token_response.rb +2 -2
  70. data/lib/vpndetection/models/user_agent_verdict.rb +2 -2
  71. data/lib/vpndetection/models/vpn_detail.rb +2 -2
  72. data/lib/vpndetection/models/web_detail.rb +2 -2
  73. data/lib/vpndetection/result.rb +31 -31
  74. data/lib/vpndetection/version.rb +1 -1
  75. metadata +2 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6fa3bf8879a5ca2b75c4723b1fbae1fab3e6c9d2364ae3f698c5ab14a2a298b4
4
- data.tar.gz: d4c91265a5556b14d2ddc7f2adbea510bbcf965e18074e7522ed2c5bb3b82532
3
+ metadata.gz: 1c158a3f311984225a01173fe299a0d24a410e857ce63c1bbb0537aaaa97c7e6
4
+ data.tar.gz: febea3b0b3665774985825d2012eefe3b1940f881c978e80d354c21c6d30878a
5
5
  SHA512:
6
- metadata.gz: 949cc07141631b8a5d81d742effc103be59e58957c19373598a130a6a50382b08e12d428f010515603cd27a49ef55734951c7dae74f437dfb091c3bf465e868b
7
- data.tar.gz: 454fe612a10c57b5ba861ab6b51bb3475b2ddfdd7056d6e65f6eef2628776e9794cba6a3e3a95fbfc5e397fd78ebfd95e10ae975fb3b7d268e1aeb8f802b62e5
6
+ metadata.gz: 593d2fc397c7edb94ac7b8df2aae18adb462eb338d9f390139560635ff7e097a8b2a6009124e05cafdaa29c592dd0710b7e1038cc9bafdcf11b0a00eaa88b8f5
7
+ data.tar.gz: 6cc95f71d88da71662ccd04ed0fb2cf10e46be2c069574d1432b1544d17ac5a280e09b05a34485ac21c4cd105432fd5ad105cf9d786d2f99e1cea021a541890d
data/README.md CHANGED
@@ -38,7 +38,7 @@ result.asn['name'] # who runs the announcing network
38
38
 
39
39
  ### With an API key
40
40
 
41
- Every paid plan answers every field: `is_hosting`, `is_cdn` and the four proxy flags as well, the carrier and satellite flags, the five service flags (SSH, SMTP, web, DNS resolver and BitTorrent), city-level `location`, the `company` and the `abuse` contact, `bot` (whose bot uses the address, what it does and whether its operator vouches for the address), and the provider (its ID and its name), confidence and last-seen detail behind each flag. The plans differ only in how many lookups they include, and a free account tries every field. Create a key in the [console](https://app.vpndetection.io), then pass it in:
41
+ A paid plan answers every field: `is_hosting`, `is_cdn` and the four proxy flags as well, the carrier and satellite flags, the five service flags (SSH, SMTP, web, DNS resolver and BitTorrent), city-level `location`, the `company` and the `abuse` contact, `bot` (whose bot uses the address, what it does and whether its operator vouches for the address), and the provider (its ID and its name), confidence and last-seen detail behind each flag. Its quotas differ only in how many lookups they include, and a free account tries every field. Create a key in the [console](https://app.vpndetection.io), then pass it in:
42
42
 
43
43
  ```ruby
44
44
  client = VPNDetection::Client.new(api_key: ENV['VPNDETECTION_API_KEY'])
@@ -62,8 +62,8 @@ Same answer `lookup` would give for that address, and the same cost against your
62
62
 
63
63
  ```ruby
64
64
  acct = client.my_entitlement
65
- acct.plan.name # => "Max", what to show
66
- acct.plan.key # => "max", what to compare against
65
+ acct.plan.name # => "Data", what to show
66
+ acct.plan.key # => "data_4", what to compare against
67
67
  acct.usage.requests # => 580
68
68
  acct.usage.window_end # => when the allowance resets
69
69
  ```
@@ -1,9 +1,9 @@
1
1
  =begin
2
2
  #VPNDetection API
3
3
 
4
- #The VPNDetection API: classify any IP address, and download the databases behind the answers. Lookups need no API key: Unlimited, the free plan, answers any address with no daily or monthly cap, with a key or without one. Every paid plan answers every field, and a free account tries them. Unlimited's answers may be used commercially, but not redistributed or used in a competing service (https://vpndetection.io/terms#no-key). See https://docs.vpndetection.io for guides and https://github.com/vpndetection-io for the official client libraries.
4
+ #The VPNDetection API: classify any IP address, and download the databases behind the answers. Lookups need no API key: Unlimited, the free plan, answers any address with no daily or monthly cap, with a key or without one. The Data plan answers every field, and a free account tries them. Unlimited's answers may be used commercially, but not redistributed or used in a competing service (https://vpndetection.io/terms#no-key). See https://docs.vpndetection.io for guides and https://github.com/vpndetection-io for the official client libraries.
5
5
 
6
- The version of the OpenAPI document: 2026.11.23
6
+ The version of the OpenAPI document: 2026.11.25
7
7
  Contact: support@vpndetection.io
8
8
  Generated by: https://openapi-generator.tech
9
9
  Generator version: 7.25.0
@@ -1,9 +1,9 @@
1
1
  =begin
2
2
  #VPNDetection API
3
3
 
4
- #The VPNDetection API: classify any IP address, and download the databases behind the answers. Lookups need no API key: Unlimited, the free plan, answers any address with no daily or monthly cap, with a key or without one. Every paid plan answers every field, and a free account tries them. Unlimited's answers may be used commercially, but not redistributed or used in a competing service (https://vpndetection.io/terms#no-key). See https://docs.vpndetection.io for guides and https://github.com/vpndetection-io for the official client libraries.
4
+ #The VPNDetection API: classify any IP address, and download the databases behind the answers. Lookups need no API key: Unlimited, the free plan, answers any address with no daily or monthly cap, with a key or without one. The Data plan answers every field, and a free account tries them. Unlimited's answers may be used commercially, but not redistributed or used in a competing service (https://vpndetection.io/terms#no-key). See https://docs.vpndetection.io for guides and https://github.com/vpndetection-io for the official client libraries.
5
5
 
6
- The version of the OpenAPI document: 2026.11.23
6
+ The version of the OpenAPI document: 2026.11.25
7
7
  Contact: support@vpndetection.io
8
8
  Generated by: https://openapi-generator.tech
9
9
  Generator version: 7.25.0
@@ -1,9 +1,9 @@
1
1
  =begin
2
2
  #VPNDetection API
3
3
 
4
- #The VPNDetection API: classify any IP address, and download the databases behind the answers. Lookups need no API key: Unlimited, the free plan, answers any address with no daily or monthly cap, with a key or without one. Every paid plan answers every field, and a free account tries them. Unlimited's answers may be used commercially, but not redistributed or used in a competing service (https://vpndetection.io/terms#no-key). See https://docs.vpndetection.io for guides and https://github.com/vpndetection-io for the official client libraries.
4
+ #The VPNDetection API: classify any IP address, and download the databases behind the answers. Lookups need no API key: Unlimited, the free plan, answers any address with no daily or monthly cap, with a key or without one. The Data plan answers every field, and a free account tries them. Unlimited's answers may be used commercially, but not redistributed or used in a competing service (https://vpndetection.io/terms#no-key). See https://docs.vpndetection.io for guides and https://github.com/vpndetection-io for the official client libraries.
5
5
 
6
- The version of the OpenAPI document: 2026.11.23
6
+ The version of the OpenAPI document: 2026.11.25
7
7
  Contact: support@vpndetection.io
8
8
  Generated by: https://openapi-generator.tech
9
9
  Generator version: 7.25.0
@@ -1,9 +1,9 @@
1
1
  =begin
2
2
  #VPNDetection API
3
3
 
4
- #The VPNDetection API: classify any IP address, and download the databases behind the answers. Lookups need no API key: Unlimited, the free plan, answers any address with no daily or monthly cap, with a key or without one. Every paid plan answers every field, and a free account tries them. Unlimited's answers may be used commercially, but not redistributed or used in a competing service (https://vpndetection.io/terms#no-key). See https://docs.vpndetection.io for guides and https://github.com/vpndetection-io for the official client libraries.
4
+ #The VPNDetection API: classify any IP address, and download the databases behind the answers. Lookups need no API key: Unlimited, the free plan, answers any address with no daily or monthly cap, with a key or without one. The Data plan answers every field, and a free account tries them. Unlimited's answers may be used commercially, but not redistributed or used in a competing service (https://vpndetection.io/terms#no-key). See https://docs.vpndetection.io for guides and https://github.com/vpndetection-io for the official client libraries.
5
5
 
6
- The version of the OpenAPI document: 2026.11.23
6
+ The version of the OpenAPI document: 2026.11.25
7
7
  Contact: support@vpndetection.io
8
8
  Generated by: https://openapi-generator.tech
9
9
  Generator version: 7.25.0
@@ -1,9 +1,9 @@
1
1
  =begin
2
2
  #VPNDetection API
3
3
 
4
- #The VPNDetection API: classify any IP address, and download the databases behind the answers. Lookups need no API key: Unlimited, the free plan, answers any address with no daily or monthly cap, with a key or without one. Every paid plan answers every field, and a free account tries them. Unlimited's answers may be used commercially, but not redistributed or used in a competing service (https://vpndetection.io/terms#no-key). See https://docs.vpndetection.io for guides and https://github.com/vpndetection-io for the official client libraries.
4
+ #The VPNDetection API: classify any IP address, and download the databases behind the answers. Lookups need no API key: Unlimited, the free plan, answers any address with no daily or monthly cap, with a key or without one. The Data plan answers every field, and a free account tries them. Unlimited's answers may be used commercially, but not redistributed or used in a competing service (https://vpndetection.io/terms#no-key). See https://docs.vpndetection.io for guides and https://github.com/vpndetection-io for the official client libraries.
5
5
 
6
- The version of the OpenAPI document: 2026.11.23
6
+ The version of the OpenAPI document: 2026.11.25
7
7
  Contact: support@vpndetection.io
8
8
  Generated by: https://openapi-generator.tech
9
9
  Generator version: 7.25.0
@@ -1,9 +1,9 @@
1
1
  =begin
2
2
  #VPNDetection API
3
3
 
4
- #The VPNDetection API: classify any IP address, and download the databases behind the answers. Lookups need no API key: Unlimited, the free plan, answers any address with no daily or monthly cap, with a key or without one. Every paid plan answers every field, and a free account tries them. Unlimited's answers may be used commercially, but not redistributed or used in a competing service (https://vpndetection.io/terms#no-key). See https://docs.vpndetection.io for guides and https://github.com/vpndetection-io for the official client libraries.
4
+ #The VPNDetection API: classify any IP address, and download the databases behind the answers. Lookups need no API key: Unlimited, the free plan, answers any address with no daily or monthly cap, with a key or without one. The Data plan answers every field, and a free account tries them. Unlimited's answers may be used commercially, but not redistributed or used in a competing service (https://vpndetection.io/terms#no-key). See https://docs.vpndetection.io for guides and https://github.com/vpndetection-io for the official client libraries.
5
5
 
6
- The version of the OpenAPI document: 2026.11.23
6
+ The version of the OpenAPI document: 2026.11.25
7
7
  Contact: support@vpndetection.io
8
8
  Generated by: https://openapi-generator.tech
9
9
  Generator version: 7.25.0
@@ -1,9 +1,9 @@
1
1
  =begin
2
2
  #VPNDetection API
3
3
 
4
- #The VPNDetection API: classify any IP address, and download the databases behind the answers. Lookups need no API key: Unlimited, the free plan, answers any address with no daily or monthly cap, with a key or without one. Every paid plan answers every field, and a free account tries them. Unlimited's answers may be used commercially, but not redistributed or used in a competing service (https://vpndetection.io/terms#no-key). See https://docs.vpndetection.io for guides and https://github.com/vpndetection-io for the official client libraries.
4
+ #The VPNDetection API: classify any IP address, and download the databases behind the answers. Lookups need no API key: Unlimited, the free plan, answers any address with no daily or monthly cap, with a key or without one. The Data plan answers every field, and a free account tries them. Unlimited's answers may be used commercially, but not redistributed or used in a competing service (https://vpndetection.io/terms#no-key). See https://docs.vpndetection.io for guides and https://github.com/vpndetection-io for the official client libraries.
5
5
 
6
- The version of the OpenAPI document: 2026.11.23
6
+ The version of the OpenAPI document: 2026.11.25
7
7
  Contact: support@vpndetection.io
8
8
  Generated by: https://openapi-generator.tech
9
9
  Generator version: 7.25.0
@@ -1,9 +1,9 @@
1
1
  =begin
2
2
  #VPNDetection API
3
3
 
4
- #The VPNDetection API: classify any IP address, and download the databases behind the answers. Lookups need no API key: Unlimited, the free plan, answers any address with no daily or monthly cap, with a key or without one. Every paid plan answers every field, and a free account tries them. Unlimited's answers may be used commercially, but not redistributed or used in a competing service (https://vpndetection.io/terms#no-key). See https://docs.vpndetection.io for guides and https://github.com/vpndetection-io for the official client libraries.
4
+ #The VPNDetection API: classify any IP address, and download the databases behind the answers. Lookups need no API key: Unlimited, the free plan, answers any address with no daily or monthly cap, with a key or without one. The Data plan answers every field, and a free account tries them. Unlimited's answers may be used commercially, but not redistributed or used in a competing service (https://vpndetection.io/terms#no-key). See https://docs.vpndetection.io for guides and https://github.com/vpndetection-io for the official client libraries.
5
5
 
6
- The version of the OpenAPI document: 2026.11.23
6
+ The version of the OpenAPI document: 2026.11.25
7
7
  Contact: support@vpndetection.io
8
8
  Generated by: https://openapi-generator.tech
9
9
  Generator version: 7.25.0
@@ -1,9 +1,9 @@
1
1
  =begin
2
2
  #VPNDetection API
3
3
 
4
- #The VPNDetection API: classify any IP address, and download the databases behind the answers. Lookups need no API key: Unlimited, the free plan, answers any address with no daily or monthly cap, with a key or without one. Every paid plan answers every field, and a free account tries them. Unlimited's answers may be used commercially, but not redistributed or used in a competing service (https://vpndetection.io/terms#no-key). See https://docs.vpndetection.io for guides and https://github.com/vpndetection-io for the official client libraries.
4
+ #The VPNDetection API: classify any IP address, and download the databases behind the answers. Lookups need no API key: Unlimited, the free plan, answers any address with no daily or monthly cap, with a key or without one. The Data plan answers every field, and a free account tries them. Unlimited's answers may be used commercially, but not redistributed or used in a competing service (https://vpndetection.io/terms#no-key). See https://docs.vpndetection.io for guides and https://github.com/vpndetection-io for the official client libraries.
5
5
 
6
- The version of the OpenAPI document: 2026.11.23
6
+ The version of the OpenAPI document: 2026.11.25
7
7
  Contact: support@vpndetection.io
8
8
  Generated by: https://openapi-generator.tech
9
9
  Generator version: 7.25.0
@@ -1,9 +1,9 @@
1
1
  =begin
2
2
  #VPNDetection API
3
3
 
4
- #The VPNDetection API: classify any IP address, and download the databases behind the answers. Lookups need no API key: Unlimited, the free plan, answers any address with no daily or monthly cap, with a key or without one. Every paid plan answers every field, and a free account tries them. Unlimited's answers may be used commercially, but not redistributed or used in a competing service (https://vpndetection.io/terms#no-key). See https://docs.vpndetection.io for guides and https://github.com/vpndetection-io for the official client libraries.
4
+ #The VPNDetection API: classify any IP address, and download the databases behind the answers. Lookups need no API key: Unlimited, the free plan, answers any address with no daily or monthly cap, with a key or without one. The Data plan answers every field, and a free account tries them. Unlimited's answers may be used commercially, but not redistributed or used in a competing service (https://vpndetection.io/terms#no-key). See https://docs.vpndetection.io for guides and https://github.com/vpndetection-io for the official client libraries.
5
5
 
6
- The version of the OpenAPI document: 2026.11.23
6
+ The version of the OpenAPI document: 2026.11.25
7
7
  Contact: support@vpndetection.io
8
8
  Generated by: https://openapi-generator.tech
9
9
  Generator version: 7.25.0
@@ -1,9 +1,9 @@
1
1
  =begin
2
2
  #VPNDetection API
3
3
 
4
- #The VPNDetection API: classify any IP address, and download the databases behind the answers. Lookups need no API key: Unlimited, the free plan, answers any address with no daily or monthly cap, with a key or without one. Every paid plan answers every field, and a free account tries them. Unlimited's answers may be used commercially, but not redistributed or used in a competing service (https://vpndetection.io/terms#no-key). See https://docs.vpndetection.io for guides and https://github.com/vpndetection-io for the official client libraries.
4
+ #The VPNDetection API: classify any IP address, and download the databases behind the answers. Lookups need no API key: Unlimited, the free plan, answers any address with no daily or monthly cap, with a key or without one. The Data plan answers every field, and a free account tries them. Unlimited's answers may be used commercially, but not redistributed or used in a competing service (https://vpndetection.io/terms#no-key). See https://docs.vpndetection.io for guides and https://github.com/vpndetection-io for the official client libraries.
5
5
 
6
- The version of the OpenAPI document: 2026.11.23
6
+ The version of the OpenAPI document: 2026.11.25
7
7
  Contact: support@vpndetection.io
8
8
  Generated by: https://openapi-generator.tech
9
9
  Generator version: 7.25.0
@@ -1,6 +1,10 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'digest'
4
+ require 'lru_redux'
5
+
3
6
  require_relative 'condition'
7
+ require_relative 'crawlers'
4
8
 
5
9
  module VPNDetection
6
10
  # The framework-agnostic half of a web middleware: resolve a client address,
@@ -27,6 +31,25 @@ module VPNDetection
27
31
  DEFAULT_TIMEOUT = 2.5
28
32
  DEFAULT_RETRIES = 0
29
33
 
34
+ # The most crawler agents one address is looked up with while it is remembered.
35
+ MAX_AGENTS_PER_ADDRESS = 4
36
+
37
+ # How long an address's crawler agents are remembered, from its first one: the
38
+ # client's default cache TTL.
39
+ AGENTS_TTL = 60 * 60
40
+
41
+ # How many addresses' agents are remembered at once.
42
+ AGENTS_MAX_ADDRESSES = 10_000
43
+ private_constant :AGENTS_TTL, :AGENTS_MAX_ADDRESSES
44
+
45
+ # Whether a `User-Agent` names a crawler, the only kind of agent whose verdict
46
+ # can be `verified` or `spoofed`. It errs toward a match, which costs a lookup.
47
+ # Case is folded for A to Z alone, as the corpus's terms are written.
48
+ def self.names_crawler?(agent)
49
+ lower = agent.b.downcase(:ascii)
50
+ Crawlers::TERMS.any? { |term| lower.include?(term) }
51
+ end
52
+
30
53
  # Reads a request's `User-Agent` where the adapter names no reader: Rack's
31
54
  # request has `user_agent`, and so do Sinatra's and Hanami's.
32
55
  DEFAULT_USER_AGENT = ->(request) { request.user_agent if request.respond_to?(:user_agent) }
@@ -38,18 +61,23 @@ module VPNDetection
38
61
  # @param user_agent_of [#call] reads the request's own `User-Agent`, which
39
62
  # `allow_bots: true` sends with the lookup.
40
63
  # @option options [Boolean] :allow_bots (false) send the request's own
41
- # `User-Agent` with its lookup, and never refuse a request whose answer
42
- # says `user_agent.verdict` is `verified`, whatever the condition
43
- # matches; the answer is still attached. An absent or empty header sends
44
- # none. A keyless client, or a free key past its trial, never gets a
45
- # verdict, so nothing is let through there, and that is warned of once
46
- # under `on_missing_field`.
64
+ # `User-Agent` with its lookup when it names a crawler, and never refuse
65
+ # a request whose answer says `user_agent.verdict` is `verified`,
66
+ # whatever the condition matches; the answer is still attached. Any other
67
+ # agent, an absent or an empty header sends none, since the verdict could
68
+ # only be `not_bot`. One address is looked up with at most
69
+ # {MAX_AGENTS_PER_ADDRESS} crawler agents an hour: past those, the lookup
70
+ # sends none, and the request passes as a crawler only where the answer's
71
+ # `bot.verified` is true. A keyless client, or a free key past its trial,
72
+ # never gets a verdict, so nothing is let through there, and that is
73
+ # warned of once under `on_missing_field`.
47
74
  def initialize(default_ip_selector, user_agent_of = DEFAULT_USER_AGENT, **options)
48
75
  Condition.validate!(options[:block_condition])
49
76
  @condition = options[:block_condition]
50
77
  @selector = options[:ip_selector] || default_ip_selector
51
78
  @allow_bots = options.fetch(:allow_bots, false) == true
52
79
  @user_agent_of = user_agent_of
80
+ @agents = @allow_bots ? CrawlerAgents.new : nil
53
81
  @fail_closed = options.fetch(:fail_closed, false)
54
82
  @on_missing_field = options.fetch(:on_missing_field, :warn)
55
83
  @skip = options[:skip]
@@ -92,13 +120,14 @@ module VPNDetection
92
120
  end
93
121
 
94
122
  # A bogon is answered locally, so nothing is sent for it.
95
- agent = @allow_bots && !Bogon.bogon?(ip) ? user_agent(request) : nil
123
+ claim = @allow_bots && !Bogon.bogon?(ip) ? claim_agent(ip, request) : nil
124
+ agent = claim&.agent
96
125
  begin
97
126
  result = @client.lookup(ip, retries: @retries, **(agent ? { user_agent: agent } : {}))
98
127
  rescue VPNDetection::Error => e
99
128
  return Lookup.new(blocked: @fail_closed, ip: ip, error: e)
100
129
  end
101
- decide(ip, result, agent)
130
+ decide(ip, result, claim)
102
131
  end
103
132
 
104
133
  private
@@ -114,28 +143,36 @@ module VPNDetection
114
143
  )
115
144
  end
116
145
 
117
- # The request's own `User-Agent`, or nil when it sent none or an empty one.
118
- def user_agent(request)
146
+ # What this request's agent comes to: nil when it names no crawler (or sent
147
+ # none), else a claim whose agent is the one to send, or nil past the
148
+ # address's bound.
149
+ def claim_agent(ip, request)
119
150
  agent = @user_agent_of.call(request)
120
- agent.is_a?(String) && !agent.empty? ? agent : nil
151
+ return nil unless agent.is_a?(String) && !agent.empty? && Middleware.names_crawler?(agent)
152
+
153
+ Claim.new(@agents.admit(ip, agent))
121
154
  end
122
155
 
123
- def decide(ip, result, agent)
124
- report_unanswered_agent(result) unless agent.nil?
156
+ def decide(ip, result, claim)
157
+ report_unanswered_agent(result) unless claim&.agent.nil?
125
158
  return Lookup.new(blocked: false, ip: ip, result: result) if @condition.nil?
126
159
 
127
160
  report_missing(result)
128
161
  Lookup.new(
129
- blocked: Condition.matches?(@condition, result) && !verified?(result),
162
+ blocked: Condition.matches?(@condition, result) && !verified?(result, claim),
130
163
  ip: ip,
131
164
  result: result
132
165
  )
133
166
  end
134
167
 
135
168
  # Whether `allow_bots` lets this answer through: its agent's operator
136
- # vouches for the address.
137
- def verified?(result)
138
- @allow_bots && result.user_agent.is_a?(Hash) && result.user_agent['verdict'] == 'verified'
169
+ # vouches for the address, or, past the bound, the answer says a crawler's
170
+ # operator does.
171
+ def verified?(result, claim)
172
+ return false if claim.nil?
173
+ return result.bot.is_a?(Hash) && result.bot['verified'] == true if claim.agent.nil?
174
+
175
+ result.user_agent.is_a?(Hash) && result.user_agent['verdict'] == 'verified'
139
176
  end
140
177
 
141
178
  def report_missing(result)
@@ -183,6 +220,42 @@ module VPNDetection
183
220
  end
184
221
  end
185
222
 
223
+ # A crawler's agent as one request makes it: `agent` is what the lookup sends,
224
+ # nil once the address is past its bound.
225
+ Claim = Struct.new(:agent)
226
+ private_constant :Claim
227
+
228
+ # The crawler agents each address was looked up with. An address claiming more
229
+ # than MAX_AGENTS_PER_ADDRESS of them in an hour sends none past those, so a
230
+ # visitor inventing an agent per request spends at most that many lookups.
231
+ #
232
+ # An agent is kept as its digest, so what an address costs in memory is
233
+ # bounded whatever length of header it sends. Adding one changes the stored
234
+ # list in place, which leaves the address's hour running from its first.
235
+ class CrawlerAgents
236
+ def initialize
237
+ @seen = LruRedux::TTL::Cache.new(AGENTS_MAX_ADDRESSES, AGENTS_TTL)
238
+ @lock = Mutex.new
239
+ end
240
+
241
+ # The agent to send for `ip`, or nil once the address has its bound.
242
+ def admit(ip, agent)
243
+ digest = Digest::SHA256.digest(agent)
244
+ @lock.synchronize do
245
+ known = @seen[ip]
246
+ if known.nil?
247
+ @seen[ip] = [digest]
248
+ elsif !known.include?(digest)
249
+ return nil if known.length >= MAX_AGENTS_PER_ADDRESS
250
+
251
+ known << digest
252
+ end
253
+ agent
254
+ end
255
+ end
256
+ end
257
+ private_constant :CrawlerAgents
258
+
186
259
  # The shared client-address selectors, bound to one framework's request type.
187
260
  #
188
261
  # There is no portable default: a framework's own accessor may return the
@@ -0,0 +1,74 @@
1
+ # Generated. Do not edit: a regeneration overwrites it.
2
+ # Lowercase substrings, one of which a crawler's ASCII-lowercased User-Agent contains.
3
+
4
+ module VPNDetection
5
+ module Middleware
6
+ module Crawlers
7
+ TERMS = [
8
+ '+http',
9
+ 'ahrefssiteaudit',
10
+ 'amzn-user',
11
+ 'anthropic-ai',
12
+ 'barkrowler',
13
+ 'better stack',
14
+ 'betterstack',
15
+ 'bingpreview',
16
+ 'bot',
17
+ 'censysinspect',
18
+ 'chatgpt-user',
19
+ 'claude-user',
20
+ 'claude-web',
21
+ 'cohere-ai',
22
+ 'crawl',
23
+ 'datadogsynthetics',
24
+ 'embedly',
25
+ 'expanse',
26
+ 'facebookcatalog',
27
+ 'facebookexternalhit',
28
+ 'flipboardproxy',
29
+ 'flipboardrss',
30
+ 'github-hookshot/',
31
+ 'google-agent',
32
+ 'google-extended',
33
+ 'google-inspectiontool',
34
+ 'google-read-aloud',
35
+ 'google-site-verification',
36
+ 'googleother',
37
+ 'iframely',
38
+ 'internetmeasurement',
39
+ 'keenable-user',
40
+ 'lumar',
41
+ 'masscan',
42
+ 'mediapartners-google',
43
+ 'meta-externalagent',
44
+ 'meta-externalfetcher',
45
+ 'meta-webindexer',
46
+ 'mistralai-user',
47
+ 'nmap',
48
+ 'notebooklm',
49
+ 'nuclei',
50
+ 'paloaltonetworks.com',
51
+ 'parse.ly',
52
+ 'parsely.com',
53
+ 'perplexity-user',
54
+ 'pingdom',
55
+ 'pinterest',
56
+ 'rssapi/',
57
+ 'screaming frog',
58
+ 'site24x7',
59
+ 'skypeuripreview',
60
+ 'slack-imgproxy',
61
+ 'slurp',
62
+ 'sogou',
63
+ 'spider',
64
+ 'statuscake',
65
+ 'stripe/1.0',
66
+ 'ttd-content',
67
+ 'whatsapp',
68
+ 'yandex',
69
+ 'yeti/',
70
+ 'zgrab',
71
+ ].freeze
72
+ end
73
+ end
74
+ end
@@ -1,9 +1,9 @@
1
1
  =begin
2
2
  #VPNDetection API
3
3
 
4
- #The VPNDetection API: classify any IP address, and download the databases behind the answers. Lookups need no API key: Unlimited, the free plan, answers any address with no daily or monthly cap, with a key or without one. Every paid plan answers every field, and a free account tries them. Unlimited's answers may be used commercially, but not redistributed or used in a competing service (https://vpndetection.io/terms#no-key). See https://docs.vpndetection.io for guides and https://github.com/vpndetection-io for the official client libraries.
4
+ #The VPNDetection API: classify any IP address, and download the databases behind the answers. Lookups need no API key: Unlimited, the free plan, answers any address with no daily or monthly cap, with a key or without one. The Data plan answers every field, and a free account tries them. Unlimited's answers may be used commercially, but not redistributed or used in a competing service (https://vpndetection.io/terms#no-key). See https://docs.vpndetection.io for guides and https://github.com/vpndetection-io for the official client libraries.
5
5
 
6
- The version of the OpenAPI document: 2026.11.23
6
+ The version of the OpenAPI document: 2026.11.25
7
7
  Contact: support@vpndetection.io
8
8
  Generated by: https://openapi-generator.tech
9
9
  Generator version: 7.25.0
@@ -14,7 +14,7 @@ require 'date'
14
14
  require 'time'
15
15
 
16
16
  module VPNDetection
17
- # Where to report abuse from the address, from our IP Abuse Contact database. Paid plans. Every key is present whenever the object is: empty strings where no record covers the address.
17
+ # Where to report abuse from the address, from our IP Abuse Contact database. On a paid plan. Every key is present whenever the object is: empty strings where no record covers the address.
18
18
  class AbuseContact < ApiModelBase
19
19
  # Where to report abuse from the address.
20
20
  attr_accessor :email
@@ -1,9 +1,9 @@
1
1
  =begin
2
2
  #VPNDetection API
3
3
 
4
- #The VPNDetection API: classify any IP address, and download the databases behind the answers. Lookups need no API key: Unlimited, the free plan, answers any address with no daily or monthly cap, with a key or without one. Every paid plan answers every field, and a free account tries them. Unlimited's answers may be used commercially, but not redistributed or used in a competing service (https://vpndetection.io/terms#no-key). See https://docs.vpndetection.io for guides and https://github.com/vpndetection-io for the official client libraries.
4
+ #The VPNDetection API: classify any IP address, and download the databases behind the answers. Lookups need no API key: Unlimited, the free plan, answers any address with no daily or monthly cap, with a key or without one. The Data plan answers every field, and a free account tries them. Unlimited's answers may be used commercially, but not redistributed or used in a competing service (https://vpndetection.io/terms#no-key). See https://docs.vpndetection.io for guides and https://github.com/vpndetection-io for the official client libraries.
5
5
 
6
- The version of the OpenAPI document: 2026.11.23
6
+ The version of the OpenAPI document: 2026.11.25
7
7
  Contact: support@vpndetection.io
8
8
  Generated by: https://openapi-generator.tech
9
9
  Generator version: 7.25.0
@@ -1,9 +1,9 @@
1
1
  =begin
2
2
  #VPNDetection API
3
3
 
4
- #The VPNDetection API: classify any IP address, and download the databases behind the answers. Lookups need no API key: Unlimited, the free plan, answers any address with no daily or monthly cap, with a key or without one. Every paid plan answers every field, and a free account tries them. Unlimited's answers may be used commercially, but not redistributed or used in a competing service (https://vpndetection.io/terms#no-key). See https://docs.vpndetection.io for guides and https://github.com/vpndetection-io for the official client libraries.
4
+ #The VPNDetection API: classify any IP address, and download the databases behind the answers. Lookups need no API key: Unlimited, the free plan, answers any address with no daily or monthly cap, with a key or without one. The Data plan answers every field, and a free account tries them. Unlimited's answers may be used commercially, but not redistributed or used in a competing service (https://vpndetection.io/terms#no-key). See https://docs.vpndetection.io for guides and https://github.com/vpndetection-io for the official client libraries.
5
5
 
6
- The version of the OpenAPI document: 2026.11.23
6
+ The version of the OpenAPI document: 2026.11.25
7
7
  Contact: support@vpndetection.io
8
8
  Generated by: https://openapi-generator.tech
9
9
  Generator version: 7.25.0
@@ -1,9 +1,9 @@
1
1
  =begin
2
2
  #VPNDetection API
3
3
 
4
- #The VPNDetection API: classify any IP address, and download the databases behind the answers. Lookups need no API key: Unlimited, the free plan, answers any address with no daily or monthly cap, with a key or without one. Every paid plan answers every field, and a free account tries them. Unlimited's answers may be used commercially, but not redistributed or used in a competing service (https://vpndetection.io/terms#no-key). See https://docs.vpndetection.io for guides and https://github.com/vpndetection-io for the official client libraries.
4
+ #The VPNDetection API: classify any IP address, and download the databases behind the answers. Lookups need no API key: Unlimited, the free plan, answers any address with no daily or monthly cap, with a key or without one. The Data plan answers every field, and a free account tries them. Unlimited's answers may be used commercially, but not redistributed or used in a competing service (https://vpndetection.io/terms#no-key). See https://docs.vpndetection.io for guides and https://github.com/vpndetection-io for the official client libraries.
5
5
 
6
- The version of the OpenAPI document: 2026.11.23
6
+ The version of the OpenAPI document: 2026.11.25
7
7
  Contact: support@vpndetection.io
8
8
  Generated by: https://openapi-generator.tech
9
9
  Generator version: 7.25.0
@@ -1,9 +1,9 @@
1
1
  =begin
2
2
  #VPNDetection API
3
3
 
4
- #The VPNDetection API: classify any IP address, and download the databases behind the answers. Lookups need no API key: Unlimited, the free plan, answers any address with no daily or monthly cap, with a key or without one. Every paid plan answers every field, and a free account tries them. Unlimited's answers may be used commercially, but not redistributed or used in a competing service (https://vpndetection.io/terms#no-key). See https://docs.vpndetection.io for guides and https://github.com/vpndetection-io for the official client libraries.
4
+ #The VPNDetection API: classify any IP address, and download the databases behind the answers. Lookups need no API key: Unlimited, the free plan, answers any address with no daily or monthly cap, with a key or without one. The Data plan answers every field, and a free account tries them. Unlimited's answers may be used commercially, but not redistributed or used in a competing service (https://vpndetection.io/terms#no-key). See https://docs.vpndetection.io for guides and https://github.com/vpndetection-io for the official client libraries.
5
5
 
6
- The version of the OpenAPI document: 2026.11.23
6
+ The version of the OpenAPI document: 2026.11.25
7
7
  Contact: support@vpndetection.io
8
8
  Generated by: https://openapi-generator.tech
9
9
  Generator version: 7.25.0
@@ -1,9 +1,9 @@
1
1
  =begin
2
2
  #VPNDetection API
3
3
 
4
- #The VPNDetection API: classify any IP address, and download the databases behind the answers. Lookups need no API key: Unlimited, the free plan, answers any address with no daily or monthly cap, with a key or without one. Every paid plan answers every field, and a free account tries them. Unlimited's answers may be used commercially, but not redistributed or used in a competing service (https://vpndetection.io/terms#no-key). See https://docs.vpndetection.io for guides and https://github.com/vpndetection-io for the official client libraries.
4
+ #The VPNDetection API: classify any IP address, and download the databases behind the answers. Lookups need no API key: Unlimited, the free plan, answers any address with no daily or monthly cap, with a key or without one. The Data plan answers every field, and a free account tries them. Unlimited's answers may be used commercially, but not redistributed or used in a competing service (https://vpndetection.io/terms#no-key). See https://docs.vpndetection.io for guides and https://github.com/vpndetection-io for the official client libraries.
5
5
 
6
- The version of the OpenAPI document: 2026.11.23
6
+ The version of the OpenAPI document: 2026.11.25
7
7
  Contact: support@vpndetection.io
8
8
  Generated by: https://openapi-generator.tech
9
9
  Generator version: 7.25.0
@@ -1,9 +1,9 @@
1
1
  =begin
2
2
  #VPNDetection API
3
3
 
4
- #The VPNDetection API: classify any IP address, and download the databases behind the answers. Lookups need no API key: Unlimited, the free plan, answers any address with no daily or monthly cap, with a key or without one. Every paid plan answers every field, and a free account tries them. Unlimited's answers may be used commercially, but not redistributed or used in a competing service (https://vpndetection.io/terms#no-key). See https://docs.vpndetection.io for guides and https://github.com/vpndetection-io for the official client libraries.
4
+ #The VPNDetection API: classify any IP address, and download the databases behind the answers. Lookups need no API key: Unlimited, the free plan, answers any address with no daily or monthly cap, with a key or without one. The Data plan answers every field, and a free account tries them. Unlimited's answers may be used commercially, but not redistributed or used in a competing service (https://vpndetection.io/terms#no-key). See https://docs.vpndetection.io for guides and https://github.com/vpndetection-io for the official client libraries.
5
5
 
6
- The version of the OpenAPI document: 2026.11.23
6
+ The version of the OpenAPI document: 2026.11.25
7
7
  Contact: support@vpndetection.io
8
8
  Generated by: https://openapi-generator.tech
9
9
  Generator version: 7.25.0
@@ -1,9 +1,9 @@
1
1
  =begin
2
2
  #VPNDetection API
3
3
 
4
- #The VPNDetection API: classify any IP address, and download the databases behind the answers. Lookups need no API key: Unlimited, the free plan, answers any address with no daily or monthly cap, with a key or without one. Every paid plan answers every field, and a free account tries them. Unlimited's answers may be used commercially, but not redistributed or used in a competing service (https://vpndetection.io/terms#no-key). See https://docs.vpndetection.io for guides and https://github.com/vpndetection-io for the official client libraries.
4
+ #The VPNDetection API: classify any IP address, and download the databases behind the answers. Lookups need no API key: Unlimited, the free plan, answers any address with no daily or monthly cap, with a key or without one. The Data plan answers every field, and a free account tries them. Unlimited's answers may be used commercially, but not redistributed or used in a competing service (https://vpndetection.io/terms#no-key). See https://docs.vpndetection.io for guides and https://github.com/vpndetection-io for the official client libraries.
5
5
 
6
- The version of the OpenAPI document: 2026.11.23
6
+ The version of the OpenAPI document: 2026.11.25
7
7
  Contact: support@vpndetection.io
8
8
  Generated by: https://openapi-generator.tech
9
9
  Generator version: 7.25.0
@@ -1,9 +1,9 @@
1
1
  =begin
2
2
  #VPNDetection API
3
3
 
4
- #The VPNDetection API: classify any IP address, and download the databases behind the answers. Lookups need no API key: Unlimited, the free plan, answers any address with no daily or monthly cap, with a key or without one. Every paid plan answers every field, and a free account tries them. Unlimited's answers may be used commercially, but not redistributed or used in a competing service (https://vpndetection.io/terms#no-key). See https://docs.vpndetection.io for guides and https://github.com/vpndetection-io for the official client libraries.
4
+ #The VPNDetection API: classify any IP address, and download the databases behind the answers. Lookups need no API key: Unlimited, the free plan, answers any address with no daily or monthly cap, with a key or without one. The Data plan answers every field, and a free account tries them. Unlimited's answers may be used commercially, but not redistributed or used in a competing service (https://vpndetection.io/terms#no-key). See https://docs.vpndetection.io for guides and https://github.com/vpndetection-io for the official client libraries.
5
5
 
6
- The version of the OpenAPI document: 2026.11.23
6
+ The version of the OpenAPI document: 2026.11.25
7
7
  Contact: support@vpndetection.io
8
8
  Generated by: https://openapi-generator.tech
9
9
  Generator version: 7.25.0
@@ -1,9 +1,9 @@
1
1
  =begin
2
2
  #VPNDetection API
3
3
 
4
- #The VPNDetection API: classify any IP address, and download the databases behind the answers. Lookups need no API key: Unlimited, the free plan, answers any address with no daily or monthly cap, with a key or without one. Every paid plan answers every field, and a free account tries them. Unlimited's answers may be used commercially, but not redistributed or used in a competing service (https://vpndetection.io/terms#no-key). See https://docs.vpndetection.io for guides and https://github.com/vpndetection-io for the official client libraries.
4
+ #The VPNDetection API: classify any IP address, and download the databases behind the answers. Lookups need no API key: Unlimited, the free plan, answers any address with no daily or monthly cap, with a key or without one. The Data plan answers every field, and a free account tries them. Unlimited's answers may be used commercially, but not redistributed or used in a competing service (https://vpndetection.io/terms#no-key). See https://docs.vpndetection.io for guides and https://github.com/vpndetection-io for the official client libraries.
5
5
 
6
- The version of the OpenAPI document: 2026.11.23
6
+ The version of the OpenAPI document: 2026.11.25
7
7
  Contact: support@vpndetection.io
8
8
  Generated by: https://openapi-generator.tech
9
9
  Generator version: 7.25.0
@@ -1,9 +1,9 @@
1
1
  =begin
2
2
  #VPNDetection API
3
3
 
4
- #The VPNDetection API: classify any IP address, and download the databases behind the answers. Lookups need no API key: Unlimited, the free plan, answers any address with no daily or monthly cap, with a key or without one. Every paid plan answers every field, and a free account tries them. Unlimited's answers may be used commercially, but not redistributed or used in a competing service (https://vpndetection.io/terms#no-key). See https://docs.vpndetection.io for guides and https://github.com/vpndetection-io for the official client libraries.
4
+ #The VPNDetection API: classify any IP address, and download the databases behind the answers. Lookups need no API key: Unlimited, the free plan, answers any address with no daily or monthly cap, with a key or without one. The Data plan answers every field, and a free account tries them. Unlimited's answers may be used commercially, but not redistributed or used in a competing service (https://vpndetection.io/terms#no-key). See https://docs.vpndetection.io for guides and https://github.com/vpndetection-io for the official client libraries.
5
5
 
6
- The version of the OpenAPI document: 2026.11.23
6
+ The version of the OpenAPI document: 2026.11.25
7
7
  Contact: support@vpndetection.io
8
8
  Generated by: https://openapi-generator.tech
9
9
  Generator version: 7.25.0
@@ -1,9 +1,9 @@
1
1
  =begin
2
2
  #VPNDetection API
3
3
 
4
- #The VPNDetection API: classify any IP address, and download the databases behind the answers. Lookups need no API key: Unlimited, the free plan, answers any address with no daily or monthly cap, with a key or without one. Every paid plan answers every field, and a free account tries them. Unlimited's answers may be used commercially, but not redistributed or used in a competing service (https://vpndetection.io/terms#no-key). See https://docs.vpndetection.io for guides and https://github.com/vpndetection-io for the official client libraries.
4
+ #The VPNDetection API: classify any IP address, and download the databases behind the answers. Lookups need no API key: Unlimited, the free plan, answers any address with no daily or monthly cap, with a key or without one. The Data plan answers every field, and a free account tries them. Unlimited's answers may be used commercially, but not redistributed or used in a competing service (https://vpndetection.io/terms#no-key). See https://docs.vpndetection.io for guides and https://github.com/vpndetection-io for the official client libraries.
5
5
 
6
- The version of the OpenAPI document: 2026.11.23
6
+ The version of the OpenAPI document: 2026.11.25
7
7
  Contact: support@vpndetection.io
8
8
  Generated by: https://openapi-generator.tech
9
9
  Generator version: 7.25.0