Skip to content

Commit 87ebc16

Browse files
committed
Improve validator
1 parent 30e415d commit 87ebc16

4 files changed

Lines changed: 34 additions & 1 deletion

File tree

config/settings.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ http:
1111
proxy: null # Optional: "http://proxy.example.com:8080"
1212
timeout: 30 # seconds
1313

14+
# Validation settings
15+
validation:
16+
allow_private_suffixes: false # https://github.com/weppos/publicsuffix-ruby/blob/main/data/list.txt
17+
1418
# API server configuration
1519
api:
1620
port: 4567

lib/scopes_extractor/config.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,14 @@ def history_retention_days
8080
load[:history_retention_days] || 30
8181
end
8282

83+
def validation
84+
load[:validation] || {}
85+
end
86+
87+
def allow_private_suffixes?
88+
validation[:allow_private_suffixes] == true
89+
end
90+
8391
def discord
8492
load[:discord] || {}
8593
end

lib/scopes_extractor/validator.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ def self.valid_wildcard_usage?(val)
7070

7171
# 5. Domain part must be a valid registrable domain (not just a public suffix like *.co.uk)
7272
begin
73-
parsed = PublicSuffix.parse(domain_part)
73+
parsed = PublicSuffix.parse(domain_part, ignore_private: Config.allow_private_suffixes?)
7474
return false if parsed.sld.nil?
7575
rescue PublicSuffix::DomainInvalid, PublicSuffix::DomainNotAllowed
7676
return false

spec/scopes_extractor/validator_spec.rb

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,27 @@
5959
expect(described_class.valid_web_target?('*.test.com.au', 'web')).to be true
6060
end
6161

62+
it 'rejects wildcards on private suffixes by default' do
63+
expect(described_class.valid_web_target?('*.digitaloceanspaces.com', 'web')).to be false
64+
expect(described_class.valid_web_target?('*.githubusercontent.com', 'web')).to be false
65+
end
66+
67+
context 'when allow_private_suffixes is enabled' do
68+
before do
69+
allow(ScopesExtractor::Config).to receive(:allow_private_suffixes?).and_return(true)
70+
end
71+
72+
it 'accepts wildcards on private suffixes' do
73+
expect(described_class.valid_web_target?('*.digitaloceanspaces.com', 'web')).to be true
74+
expect(described_class.valid_web_target?('*.githubusercontent.com', 'web')).to be true
75+
end
76+
77+
it 'still rejects public suffixes' do
78+
expect(described_class.valid_web_target?('*.co.uk', 'web')).to be false
79+
expect(described_class.valid_web_target?('*.com.au', 'web')).to be false
80+
end
81+
end
82+
6283
it 'rejects descriptions in parentheses' do
6384
expect(described_class.valid_web_target?('*.example.com (description text)', 'web')).to be false
6485
end

0 commit comments

Comments
 (0)