make blocking subdomains configurable

This commit is contained in:
Ander Punnar 2021-07-19 20:38:27 +03:00
parent 5b0365ddee
commit 38ec7f61c8
No known key found for this signature in database
GPG Key ID: 0A2971E562D618F3
4 changed files with 26 additions and 4 deletions

View File

@ -142,6 +142,7 @@
|<<content.autoplay,content.autoplay>>|Automatically start playing `<video>` elements.
|<<content.blocking.adblock.lists,content.blocking.adblock.lists>>|List of URLs to ABP-style adblocking rulesets.
|<<content.blocking.enabled,content.blocking.enabled>>|Enable the ad/host blocker
|<<content.blocking.hosts.block_subdomains,content.blocking.hosts.block_subdomains>>|Block subdomains of blocked hosts.
|<<content.blocking.hosts.lists,content.blocking.hosts.lists>>|List of URLs to host blocklists for the host blocker.
|<<content.blocking.method,content.blocking.method>>|Which method of blocking ads should be used.
|<<content.blocking.whitelist,content.blocking.whitelist>>|A list of patterns that should always be loaded, despite being blocked by the ad-/host-blocker.
@ -1994,6 +1995,14 @@ Type: <<types,Bool>>
Default: +pass:[true]+
[[content.blocking.hosts.block_subdomains]]
=== content.blocking.hosts.block_subdomains
Block subdomains of blocked hosts.
Type: <<types,Bool>>
Default: +pass:[true]+
[[content.blocking.hosts.lists]]
=== content.blocking.hosts.lists
List of URLs to host blocklists for the host blocker.

View File

@ -132,10 +132,15 @@ class HostBlocker:
host = request_url.host()
return any(
hostname in self._blocked_hosts or hostname in self._config_blocked_hosts
for hostname in urlutils.widened_hostnames(host)
)
if config.get("content.blocking.hosts.block_subdomains"):
return any(
hostname in self._blocked_hosts or hostname in self._config_blocked_hosts
for hostname in urlutils.widened_hostnames(host)
)
else:
return (
host in self._blocked_hosts or host in self._config_blocked_hosts
)
def filter_request(self, info: interceptor.Request) -> None:
"""Block the given request if necessary."""

View File

@ -747,6 +747,11 @@ content.blocking.hosts.lists:
The file `~/.config/qutebrowser/blocked-hosts` is always read if it exists.
content.blocking.hosts.block_subdomains:
default: true
type: Bool
desc: Block subdomains of blocked hosts.
content.blocking.method:
default: auto
type:

View File

@ -570,4 +570,7 @@ def test_subdomain_blocking(config_stub, host_blocker_factory):
config_stub.val.content.blocking.hosts.lists = None
host_blocker = host_blocker_factory()
host_blocker._blocked_hosts.add("example.com")
config_stub.val.content.blocking.hosts.block_subdomains = True
assert host_blocker._is_blocked(QUrl("https://subdomain.example.com"))
config_stub.val.content.blocking.hosts.block_subdomains = False
assert not host_blocker._is_blocked(QUrl("https://subdomain.example.com"))