summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnder Punnar <ander@kvlt.ee>2021-07-19 20:38:27 +0300
committerAnder Punnar <ander@kvlt.ee>2021-07-19 20:38:27 +0300
commit38ec7f61c854bb1c89cd7aadcc93eff87cc70dd6 (patch)
treeff3bfa0232872d330513d4bc111dce0830f4e0ad
parent5b0365ddeefbd0fba443f5c152f5efa0a393dbec (diff)
downloadqutebrowser-38ec7f61c854bb1c89cd7aadcc93eff87cc70dd6.tar.gz
qutebrowser-38ec7f61c854bb1c89cd7aadcc93eff87cc70dd6.zip
make blocking subdomains configurable
-rw-r--r--doc/help/settings.asciidoc9
-rw-r--r--qutebrowser/components/hostblock.py13
-rw-r--r--qutebrowser/config/configdata.yml5
-rw-r--r--tests/unit/components/test_hostblock.py3
4 files changed, 26 insertions, 4 deletions
diff --git a/doc/help/settings.asciidoc b/doc/help/settings.asciidoc
index c5206e52e..57bcdd8e0 100644
--- a/doc/help/settings.asciidoc
+++ b/doc/help/settings.asciidoc
@@ -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.
diff --git a/qutebrowser/components/hostblock.py b/qutebrowser/components/hostblock.py
index 2d6086245..3cdd47223 100644
--- a/qutebrowser/components/hostblock.py
+++ b/qutebrowser/components/hostblock.py
@@ -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."""
diff --git a/qutebrowser/config/configdata.yml b/qutebrowser/config/configdata.yml
index 76c4ce369..2f090cc06 100644
--- a/qutebrowser/config/configdata.yml
+++ b/qutebrowser/config/configdata.yml
@@ -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:
diff --git a/tests/unit/components/test_hostblock.py b/tests/unit/components/test_hostblock.py
index 00a7a5f8f..a1ae2ad5c 100644
--- a/tests/unit/components/test_hostblock.py
+++ b/tests/unit/components/test_hostblock.py
@@ -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"))