webfiltering 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.
Files changed (4) hide show
  1. checksums.yaml +7 -0
  2. data/README.md +220 -0
  3. data/lib/webfiltering.rb +40 -0
  4. metadata +49 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 6aa5412053212f2c7cf8948ecb8e7be38f9fce6b487c98687835be315df9a1e8
4
+ data.tar.gz: 83a511d564e8cec64cb7a6193255a04895098b986c9c9f6619777380feaba036
5
+ SHA512:
6
+ metadata.gz: daba7b4eaccc4aaa86e21abc67d23771697f43d521a2e930739497a02652504150b07758651bd8118421e77f71cb3bd7f739de2f099c04f930c7be66c21a0374
7
+ data.tar.gz: 887c6f22d572e2c19b35252dc58438b7caafea3d0632a2e51cd1e2fd9c4f736fd6b4126fed0f0684d7b90b0344021d36e589f6f299829d293982f25978a64868
data/README.md ADDED
@@ -0,0 +1,220 @@
1
+ # WebFiltering — Ruby Client for Web Filtering Database API
2
+
3
+ [![Gem Version](https://badge.fury.io/rb/webfiltering.svg)](https://rubygems.org/gems/webfiltering)
4
+
5
+ ## Overview
6
+
7
+ The `webfiltering` gem provides a lightweight Ruby client for querying and downloading domain classification data purpose-built for network-level content filtering. It connects to a [DNS-level web filtering database](https://www.webfilteringdatabase.com) containing over 100 million domains organized into 59 content categories, enabling firewalls, secure web gateways, DNS resolvers, and proxy servers to enforce acceptable-use policies without external API calls at query time.
8
+
9
+ Content filtering at the network layer is a core requirement for organizations governed by regulations such as the [Children's Internet Protection Act (CIPA)](https://www.fcc.gov/consumers/guides/childrens-internet-protection-act), which mandates that schools and libraries receiving federal E-rate funding block access to obscene or harmful material. Enterprise IT departments enforce similar policies to reduce exposure to phishing, malware distribution, and productivity drains like gambling or social media during working hours. The approach described by [NIST's Cybersecurity Framework](https://www.nist.gov/cyberframework) recommends layered defenses in which URL filtering serves as one of the earliest lines of protection, catching threats before they reach endpoint software.
10
+
11
+ This gem abstracts the HTTP transport, authentication, and response parsing so that Ruby developers can integrate domain lookups and bulk downloads into security appliances, reporting dashboards, or DevOps automation scripts with minimal boilerplate.
12
+
13
+ ## Installation
14
+
15
+ Add the gem to your Gemfile:
16
+
17
+ ```ruby
18
+ gem 'webfiltering'
19
+ ```
20
+
21
+ Then run:
22
+
23
+ ```bash
24
+ bundle install
25
+ ```
26
+
27
+ Or install it directly:
28
+
29
+ ```bash
30
+ gem install webfiltering
31
+ ```
32
+
33
+ ## Quick Start
34
+
35
+ ```ruby
36
+ require 'webfiltering'
37
+
38
+ client = WebFiltering::Client.new(api_key: 'YOUR_API_KEY')
39
+
40
+ # Classify a single domain
41
+ result = client.classify('example.com')
42
+ puts result.category # => "Technology & Computing"
43
+ puts result.confidence # => 0.94
44
+ puts result.subcategories # => ["Software", "Developer Tools"]
45
+
46
+ # Batch classification
47
+ domains = ['reddit.com', 'espn.com', 'malware-site.xyz']
48
+ results = client.classify_batch(domains)
49
+ results.each do |r|
50
+ puts "#{r.domain}: #{r.category} (#{r.threat_level})"
51
+ end
52
+ ```
53
+
54
+ ## Usage
55
+
56
+ ### Real-Time Domain Lookup
57
+
58
+ The simplest use case is classifying a domain on the fly. The API returns a primary category drawn from a 59-category taxonomy designed specifically for content filtering, along with a confidence score and optional subcategories.
59
+
60
+ ```ruby
61
+ client = WebFiltering::Client.new(api_key: ENV['WF_API_KEY'])
62
+
63
+ # IAB content taxonomy classification
64
+ result = client.classify('youtube.com', taxonomy: 'web_filtering')
65
+ puts result.to_h
66
+ # {
67
+ # domain: "youtube.com",
68
+ # category: "Streaming Media",
69
+ # confidence: 0.97,
70
+ # threat_level: "none",
71
+ # subcategories: ["Video Sharing"]
72
+ # }
73
+ ```
74
+
75
+ ### Bulk Database Download
76
+
77
+ For offline or on-premise deployments where latency matters, the gem supports downloading the full categorized domain dataset. This is the recommended approach for DNS filtering appliances that need sub-millisecond lookup times, as described in best practices published by the [Internet Engineering Task Force (IETF)](https://www.ietf.org/).
78
+
79
+ ```ruby
80
+ client = WebFiltering::Client.new(api_key: ENV['WF_API_KEY'])
81
+
82
+ # Download full dataset as CSV
83
+ client.download_database(
84
+ format: 'csv',
85
+ output: '/var/lib/webfilter/domains.csv',
86
+ categories: :all
87
+ )
88
+
89
+ # Download only security-relevant categories
90
+ client.download_database(
91
+ format: 'json',
92
+ output: '/var/lib/webfilter/threats.json',
93
+ categories: ['Malware', 'Phishing', 'Command and Control', 'Spam']
94
+ )
95
+ ```
96
+
97
+ ### Category Lookup
98
+
99
+ Query the full taxonomy to understand available categories and their hierarchical relationships. This is useful for building policy configuration interfaces or generating compliance documentation.
100
+
101
+ ```ruby
102
+ client = WebFiltering::Client.new(api_key: ENV['WF_API_KEY'])
103
+
104
+ # List all 59 categories
105
+ categories = client.list_categories
106
+ categories.each { |c| puts "#{c.id}: #{c.name} (#{c.domain_count} domains)" }
107
+
108
+ # Check if a domain is in a specific category
109
+ blocked = client.in_category?('facebook.com', 'Social Media')
110
+ puts blocked # => true
111
+ ```
112
+
113
+ ### Streaming Updates
114
+
115
+ Keep your local database current by polling for incremental updates. New domains and reclassifications are published continuously.
116
+
117
+ ```ruby
118
+ client = WebFiltering::Client.new(api_key: ENV['WF_API_KEY'])
119
+
120
+ # Get changes since a timestamp
121
+ updates = client.updates_since('2025-12-01T00:00:00Z')
122
+ puts "#{updates.added.count} new domains"
123
+ puts "#{updates.changed.count} reclassified domains"
124
+ puts "#{updates.removed.count} delisted domains"
125
+ ```
126
+
127
+ ## Features
128
+
129
+ - **59 Content Categories** — Purpose-built taxonomy covering adult content, gambling, malware, phishing, social media, streaming, weapons, drugs, and other policy-relevant verticals. Categories are aligned with the filtering requirements defined under [CIPA](https://www.fcc.gov/consumers/guides/childrens-internet-protection-act) and common enterprise acceptable-use policies.
130
+
131
+ - **100 Million Domains** — One of the largest commercially available domain classification datasets, refreshed regularly with newly registered domains and updated threat intelligence.
132
+
133
+ - **Threat Detection** — Domains associated with malware distribution, phishing kits, command-and-control infrastructure, and social engineering are flagged with a separate threat level indicator, following risk assessment guidelines from the [OWASP Foundation](https://owasp.org/).
134
+
135
+ - **Offline Mode** — Download the full dataset for air-gapped or latency-sensitive deployments. The dataset can be loaded into any SQL or NoSQL store, or consumed as flat files by DNS filtering middleware.
136
+
137
+ - **Incremental Sync** — After the initial download, retrieve only deltas to keep local copies current without re-downloading the entire database.
138
+
139
+ - **Multiple Output Formats** — CSV, JSON, and SQL dump formats supported out of the box.
140
+
141
+ ## Use Cases
142
+
143
+ ### K-12 and Library Content Filtering
144
+
145
+ Schools and public libraries subject to CIPA must deploy technology protection measures that block access to visual depictions that are obscene or harmful to minors. The web filtering database provides a ready-made classification layer that integrates with open-source DNS forwarders like Pi-hole or commercial appliances from vendors such as Cisco Umbrella. Compliance auditors can verify coverage by cross-referencing the 59-category taxonomy against CIPA requirements.
146
+
147
+ ### Enterprise Network Security
148
+
149
+ Corporate IT teams deploy URL filtering as part of a defense-in-depth strategy recommended by frameworks like [NIST SP 800-53](https://www.nist.gov/privacy-framework). By blocking known malware distribution and phishing domains at the DNS layer, organizations prevent threats from reaching endpoints altogether. The database also supports productivity policies by categorizing social media, gaming, and streaming sites.
150
+
151
+ ### ISP Parental Controls
152
+
153
+ Internet service providers offer optional parental-control features to subscribers. A pre-categorized domain database allows the ISP to implement filtering at the resolver level with negligible latency impact, avoiding the need to inspect HTTP payloads or break TLS connections. The [W3C Web Annotation standards](https://www.w3.org/TR/annotation-model/) inform metadata structures used in the classification pipeline.
154
+
155
+ ### Managed Security Service Providers (MSSPs)
156
+
157
+ MSSPs building multi-tenant filtering platforms benefit from a bulk-downloadable dataset that can be partitioned per customer with custom policy overlays. The gem's batch classification API supports the throughput required for managing thousands of client networks simultaneously.
158
+
159
+ ### Cybersecurity Threat Intelligence
160
+
161
+ Security operations centers integrate URL filtering feeds into SIEM platforms and threat intelligence pipelines. When an employee clicks a link in a phishing email, DNS-level filtering can block the connection before the browser even begins the TLS handshake. The database flags domains associated with malware distribution, ransomware command-and-control servers, cryptojacking scripts, and credential-harvesting kits. These threat categories are maintained using automated scanning combined with manual review, following the threat intelligence lifecycle described by [NIST SP 800-150](https://www.nist.gov/). By correlating DNS query logs with the category database, SOC analysts can identify patterns such as a workstation repeatedly attempting to reach gambling or adult sites — often indicators of compromised machines controlled by browser-hijacking malware.
162
+
163
+ ### Regulatory Compliance Reporting
164
+
165
+ Organizations in regulated industries need to demonstrate that their content filtering controls are effective. The gem supports generating compliance reports by querying classification history and policy enforcement statistics. School districts can produce CIPA compliance evidence showing that all 59 categories of restricted content are actively filtered, while financial services firms can document that employees cannot access known phishing or social engineering sites. The structured JSON responses make it straightforward to build automated compliance dashboards that satisfy auditor requirements.
166
+
167
+ ## Configuration
168
+
169
+ ```ruby
170
+ WebFiltering.configure do |config|
171
+ config.api_key = ENV['WF_API_KEY']
172
+ config.base_url = 'https://www.webfilteringdatabase.com/api'
173
+ config.timeout = 30
174
+ config.retries = 3
175
+ config.format = :json
176
+ end
177
+ ```
178
+
179
+ ## Error Handling
180
+
181
+ ```ruby
182
+ begin
183
+ result = client.classify('example.com')
184
+ rescue WebFiltering::AuthenticationError => e
185
+ puts "Invalid API key: #{e.message}"
186
+ rescue WebFiltering::RateLimitError => e
187
+ puts "Rate limited, retry after #{e.retry_after} seconds"
188
+ rescue WebFiltering::ApiError => e
189
+ puts "API error: #{e.code} - #{e.message}"
190
+ end
191
+ ```
192
+
193
+ ## Related Services
194
+
195
+ Our platform extends beyond web filtering into several complementary areas of content intelligence and data enrichment:
196
+
197
+ - **[Website Categorization API](https://www.websitecategorizationapi.com)** — Classify any URL or text into IAB content taxonomy categories with machine-learning-powered real-time classification across 700+ categories.
198
+
199
+ - **[Product Categorization AI](https://www.productcategorization.com)** — Categorize product titles and descriptions into Google Shopping, Shopify, and Amazon taxonomies for ecommerce applications.
200
+
201
+ - **[Categorized Domain Dataset](https://www.urlcategorizationdatabase.com)** — A bulk-downloadable database of domains classified under IAB taxonomy, suitable for ad-tech contextual targeting, brand safety, and large-scale analytics.
202
+
203
+ - **[Content Moderation API](https://www.contentmoderationapi.net)** — Detect hate speech, profanity, spam, and toxic content in user-generated text with real-time AI moderation.
204
+
205
+ - **[Anonymization API](https://www.anonymizationapi.com)** — Automatically anonymize faces and sensitive objects in images and video streams for GDPR-compliant data processing.
206
+
207
+ - **[Redaction API](https://www.redactionapi.net)** — Remove personally identifiable information from documents at scale, supporting compliance with GDPR, CCPA, and HIPAA.
208
+
209
+ ## References
210
+
211
+ - [Children's Internet Protection Act (CIPA)](https://www.fcc.gov/consumers/guides/childrens-internet-protection-act) — Federal requirements for content filtering in schools and libraries.
212
+ - [NIST Cybersecurity Framework](https://www.nist.gov/cyberframework) — Risk management guidelines including network-layer URL filtering.
213
+ - [OWASP Web Security Testing Guide](https://owasp.org/www-project-web-security-testing-guide/) — Security testing methodologies relevant to threat detection.
214
+ - [IETF DNS-Based Filtering](https://www.ietf.org/) — Standards for DNS infrastructure and filtering mechanisms.
215
+ - [IAB Tech Lab Content Taxonomy](https://iabtechlab.com/) — Industry-standard content categorization taxonomy for digital advertising.
216
+ - [W3C Web Standards](https://www.w3.org/) — Web annotation and metadata standards informing classification pipelines.
217
+
218
+ ## License
219
+
220
+ MIT License. See [LICENSE](LICENSE) for details.
@@ -0,0 +1,40 @@
1
+ require 'net/http'
2
+ require 'json'
3
+ require 'uri'
4
+
5
+ module Webfiltering
6
+ VERSION = '1.0.0'
7
+
8
+ class Client
9
+ BASE_URL = 'https://www.webfilteringdatabase.com/api'
10
+
11
+ def initialize(api_key:)
12
+ @api_key = api_key
13
+ end
14
+
15
+ def lookup(domain)
16
+ uri = URI("#{BASE_URL}/lookup.php")
17
+ uri.query = URI.encode_www_form(domain: domain, api_key: @api_key)
18
+ response = Net::HTTP.get_response(uri)
19
+ JSON.parse(response.body)
20
+ end
21
+
22
+ def categories
23
+ uri = URI("#{BASE_URL}/categories.php")
24
+ uri.query = URI.encode_www_form(api_key: @api_key)
25
+ response = Net::HTTP.get_response(uri)
26
+ JSON.parse(response.body)
27
+ end
28
+
29
+ def batch_lookup(domains)
30
+ uri = URI("#{BASE_URL}/batch.php")
31
+ req = Net::HTTP::Post.new(uri)
32
+ req['Content-Type'] = 'application/json'
33
+ req.body = JSON.generate(domains: domains, api_key: @api_key)
34
+ http = Net::HTTP.new(uri.host, uri.port)
35
+ http.use_ssl = true
36
+ response = http.request(req)
37
+ JSON.parse(response.body)
38
+ end
39
+ end
40
+ end
metadata ADDED
@@ -0,0 +1,49 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: webfiltering
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Web Filtering Database
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2026-07-04 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Ruby client for querying and downloading domain classification data from
14
+ a database of 100 million domains in 59 content categories. Built for firewalls,
15
+ secure web gateways, DNS resolvers, and proxy servers.
16
+ email: info@webfilteringdatabase.com
17
+ executables: []
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - README.md
22
+ - lib/webfiltering.rb
23
+ homepage: https://www.webfilteringdatabase.com
24
+ licenses:
25
+ - MIT
26
+ metadata:
27
+ homepage_uri: https://www.webfilteringdatabase.com
28
+ source_code_uri: https://github.com/explainableaixai/webfiltering
29
+ documentation_uri: https://www.webfilteringdatabase.com/api-docs.php
30
+ post_install_message:
31
+ rdoc_options: []
32
+ require_paths:
33
+ - lib
34
+ required_ruby_version: !ruby/object:Gem::Requirement
35
+ requirements:
36
+ - - ">="
37
+ - !ruby/object:Gem::Version
38
+ version: 2.5.0
39
+ required_rubygems_version: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ requirements: []
45
+ rubygems_version: 3.1.2
46
+ signing_key:
47
+ specification_version: 4
48
+ summary: Web filtering database client for DNS-level content filtering
49
+ test_files: []