utilvo-shield-filters 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 +7 -0
- data/LICENSE +21 -0
- data/README.md +79 -0
- data/lib/utilvo_shield_filters.rb +62 -0
- metadata +48 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: 71031c7466f8d5138a1af2ef37fea9813ce81fbeccc486caf14bed9f7d0feb2b
|
|
4
|
+
data.tar.gz: db1c9d95bcb2e4bf7706e9deb50e26436b350b6c8e2ee3a1f03a3404c669d5d0
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 708230a45be21f203f56a4b5de2cb80660ba1ed285c6079840113ffab5d4a7c8a8eaf037e350faf8bb2ab8d29fe047bf5498af0a9fef4b790e802496054e9a1b
|
|
7
|
+
data.tar.gz: 1ca32485daec47aecb3f7befae1aed6e729d16fb5ec85660a084884fe1ecb26c6dfadefe5198b7100b3278eb976fd39689d38141074a3f49265709e72bbe24b9
|
data/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Utilvo (https://utilvo.com)
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
# utilvo-shield-filters
|
|
2
|
+
|
|
3
|
+
Zero-dependency JavaScript, TypeScript, Python, and Go parser for Adblock Plus 2.0 (`[Adblock Plus 2.0]`) and uBlock Origin static network filter rules.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- Parse standard `||domain^$third-party,domain=~example.com` network rules
|
|
8
|
+
- Extract target hostnames, `$third-party` modifiers, and excluded context domains
|
|
9
|
+
- Fast parent-domain suffix matching (`Set`-backed lookup) for hostname verification
|
|
10
|
+
- Built-in fetcher for the `utilvo-shield-filters.txt` blocklist
|
|
11
|
+
|
|
12
|
+
## Installation
|
|
13
|
+
|
|
14
|
+
### Node.js
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
npm install utilvo-shield-filters
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
```javascript
|
|
21
|
+
const { parseAbpRule, isHostBlocked, fetchFilterHosts } = require("utilvo-shield-filters");
|
|
22
|
+
|
|
23
|
+
// Parse a single rule
|
|
24
|
+
const rule = parseAbpRule("||01counter.com^$third-party,domain=~youtube.com");
|
|
25
|
+
// => { domain: '01counter.com', thirdParty: true, excludedDomains: ['youtube.com'] }
|
|
26
|
+
|
|
27
|
+
// Match a hostname against a Set of rules
|
|
28
|
+
const blocked = new Set(["01counter.com"]);
|
|
29
|
+
console.log(isHostBlocked("tracker.01counter.com", blocked)); // true
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
### Python
|
|
33
|
+
|
|
34
|
+
```bash
|
|
35
|
+
pip install utilvo-shield-filters
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
```python
|
|
39
|
+
from utilvo_shield_filters import parse_abp_rule, is_host_blocked
|
|
40
|
+
|
|
41
|
+
rule = parse_abp_rule("||01counter.com^$third-party,domain=~youtube.com")
|
|
42
|
+
print(rule)
|
|
43
|
+
# {'domain': '01counter.com', 'third_party': True, 'excluded_domains': ['youtube.com']}
|
|
44
|
+
|
|
45
|
+
blocked = {"01counter.com"}
|
|
46
|
+
print(is_host_blocked("sub.01counter.com", blocked)) # True
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
### Go
|
|
50
|
+
|
|
51
|
+
```bash
|
|
52
|
+
go get github.com/utilvo/utilvo-shield-filters@latest
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
```go
|
|
56
|
+
package main
|
|
57
|
+
|
|
58
|
+
import (
|
|
59
|
+
"fmt"
|
|
60
|
+
shieldfilters "github.com/utilvo/utilvo-shield-filters"
|
|
61
|
+
)
|
|
62
|
+
|
|
63
|
+
func main() {
|
|
64
|
+
domain, ok := shieldfilters.ParseAbpDomain("||01counter.com^$third-party")
|
|
65
|
+
if ok {
|
|
66
|
+
fmt.Println(domain) // 01counter.com
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
## API Reference
|
|
72
|
+
|
|
73
|
+
- `parseAbpRule(line)` / `parse_abp_rule(line)` / `ParseAbpDomain(line)`: Parses a single ABP 2.0 rule line and returns the normalized lowercase domain and rule options. Returns `null` / `None` for comments (`!`), headers (`[Adblock Plus 2.0]`), or cosmetic filters.
|
|
74
|
+
- `isHostBlocked(hostname, blockedSet)` / `is_host_blocked(hostname, blocked_set)`: Checks whether `hostname` or any of its parent registrable labels exist in `blockedSet`.
|
|
75
|
+
- `fetchFilterHosts(url?)` / `fetch_filter_hosts(url?)`: Downloads and parses a remote ABP filter list into a `Set` of domain strings.
|
|
76
|
+
|
|
77
|
+
## License
|
|
78
|
+
|
|
79
|
+
Code is licensed under the [MIT License](./LICENSE). Filter list rules are licensed under CC BY-SA 4.0.
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "set"
|
|
4
|
+
|
|
5
|
+
# Zero-dependency parser and domain matcher for Adblock Plus 2.0 network filter rules.
|
|
6
|
+
module UtilvoShieldFilters
|
|
7
|
+
VERSION = "1.0.0"
|
|
8
|
+
FILTER_LIST_URL = "https://utilvo.com/filters/utilvo-shield-filters.txt"
|
|
9
|
+
MIRROR_FILTER_LIST_URL = "https://utilvo.com/shield/filters.txt"
|
|
10
|
+
SHIELD_HOMEPAGE = "https://utilvo.com/shield"
|
|
11
|
+
|
|
12
|
+
module_function
|
|
13
|
+
|
|
14
|
+
def parse_abp_rule(line)
|
|
15
|
+
return nil unless line.is_a?(String)
|
|
16
|
+
|
|
17
|
+
trimmed = line.strip
|
|
18
|
+
return nil if trimmed.empty? || trimmed.start_with?("!", "[")
|
|
19
|
+
return nil unless trimmed.start_with?("||")
|
|
20
|
+
|
|
21
|
+
caret_idx = trimmed.index("^")
|
|
22
|
+
return nil if caret_idx.nil? || caret_idx <= 2
|
|
23
|
+
|
|
24
|
+
domain = trimmed[2...caret_idx].downcase
|
|
25
|
+
options_str = trimmed[(caret_idx + 1)..] || ""
|
|
26
|
+
third_party = false
|
|
27
|
+
excluded_domains = []
|
|
28
|
+
|
|
29
|
+
if options_str.start_with?("$")
|
|
30
|
+
options_str[1..].split(",").each do |opt|
|
|
31
|
+
if opt == "third-party" || opt == "3p"
|
|
32
|
+
third_party = true
|
|
33
|
+
elsif opt.start_with?("domain=")
|
|
34
|
+
opt[7..].split("|").each do |dom|
|
|
35
|
+
excluded_domains << dom[1..].downcase if dom.start_with?("~") && dom.length > 1
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
{
|
|
42
|
+
domain: domain,
|
|
43
|
+
third_party: third_party,
|
|
44
|
+
excluded_domains: excluded_domains
|
|
45
|
+
}
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
def host_blocked?(hostname, blocked_set)
|
|
49
|
+
return false if hostname.nil? || blocked_set.nil?
|
|
50
|
+
|
|
51
|
+
clean = hostname.strip.chomp(".").downcase
|
|
52
|
+
return false if clean.empty?
|
|
53
|
+
|
|
54
|
+
parts = clean.split(".")
|
|
55
|
+
return false if parts.length < 2
|
|
56
|
+
|
|
57
|
+
(0...(parts.length - 1)).any? do |i|
|
|
58
|
+
candidate = parts[i..].join(".")
|
|
59
|
+
blocked_set.include?(candidate)
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: utilvo-shield-filters
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 1.0.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Utilvo
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2026-10-19 00:00:00.000000000 Z
|
|
12
|
+
dependencies: []
|
|
13
|
+
description: Parses Adblock Plus 2.0 and uBlock Origin static network filter rules (||domain^$third-party) and matches hostnames against domain blocklists.
|
|
14
|
+
email: utilvo.com@gmail.com
|
|
15
|
+
executables: []
|
|
16
|
+
extensions: []
|
|
17
|
+
extra_rdoc_files: []
|
|
18
|
+
files:
|
|
19
|
+
- lib/utilvo_shield_filters.rb
|
|
20
|
+
- README.md
|
|
21
|
+
- LICENSE
|
|
22
|
+
homepage: https://utilvo.com/shield
|
|
23
|
+
licenses:
|
|
24
|
+
- MIT
|
|
25
|
+
metadata:
|
|
26
|
+
homepage_uri: https://utilvo.com/shield
|
|
27
|
+
source_code_uri: https://github.com/utilvo/utilvo-shield-filters
|
|
28
|
+
bug_tracker_uri: https://github.com/utilvo/utilvo-shield-filters/issues
|
|
29
|
+
post_install_message:
|
|
30
|
+
rdoc_options: []
|
|
31
|
+
require_paths:
|
|
32
|
+
- lib
|
|
33
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
34
|
+
requirements:
|
|
35
|
+
- - ">="
|
|
36
|
+
- !ruby/object:Gem::Version
|
|
37
|
+
version: 2.7.0
|
|
38
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
39
|
+
requirements:
|
|
40
|
+
- - ">="
|
|
41
|
+
- !ruby/object:Gem::Version
|
|
42
|
+
version: '0'
|
|
43
|
+
requirements: []
|
|
44
|
+
rubygems_version: 3.4.20
|
|
45
|
+
signing_key:
|
|
46
|
+
specification_version: 4
|
|
47
|
+
summary: Zero-dependency parser and domain matcher for Adblock Plus 2.0 network filter rules.
|
|
48
|
+
test_files: []
|