From 9875bae1249eca18acbd319bbb4dd218ffb63026 Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Tue, 27 Aug 2019 16:36:41 +0200 Subject: [PATCH] Ignore invalid URLs in QtWebEngine interceptor Closes #4969 --- qutebrowser/api/qtutils.py | 23 ++++++++++++++++++++ qutebrowser/browser/webengine/interceptor.py | 5 +++++ qutebrowser/components/adblock.py | 4 +++- 3 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 qutebrowser/api/qtutils.py diff --git a/qutebrowser/api/qtutils.py b/qutebrowser/api/qtutils.py new file mode 100644 index 000000000..dc751486f --- /dev/null +++ b/qutebrowser/api/qtutils.py @@ -0,0 +1,23 @@ +# vim: ft=python fileencoding=utf-8 sts=4 sw=4 et: + +# Copyright 2019 Florian Bruhin (The Compiler) +# +# This file is part of qutebrowser. +# +# qutebrowser is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# qutebrowser is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with qutebrowser. If not, see . + +"""Utilities related to Qt classes.""" + +# pylint: disable=unused-import +from qutebrowser.utils.qtutils import ensure_valid diff --git a/qutebrowser/browser/webengine/interceptor.py b/qutebrowser/browser/webengine/interceptor.py index e95ec92b0..0729188b7 100644 --- a/qutebrowser/browser/webengine/interceptor.py +++ b/qutebrowser/browser/webengine/interceptor.py @@ -150,6 +150,11 @@ class RequestInterceptor(QWebEngineUrlRequestInterceptor): url = info.requestUrl() first_party = info.firstPartyUrl() + if not url.isValid(): + log.webview.debug("Ignoring invalid intercepted URL: {}".format( + url.errorString())) + return + # Per QWebEngineUrlRequestInfo::ResourceType documentation, if we fail # our lookup, we should fall back to ResourceTypeUnknown try: diff --git a/qutebrowser/components/adblock.py b/qutebrowser/components/adblock.py index 3073642d7..24dfcb8dd 100644 --- a/qutebrowser/components/adblock.py +++ b/qutebrowser/components/adblock.py @@ -31,7 +31,7 @@ import pathlib from PyQt5.QtCore import QUrl from qutebrowser.api import (cmdutils, hook, config, message, downloads, - interceptor, apitypes) + interceptor, apitypes, qtutils) logger = logging.getLogger('misc') @@ -114,6 +114,8 @@ class HostBlocker: if first_party_url is not None and not first_party_url.isValid(): first_party_url = None + qtutils.ensure_valid(request_url) + if not config.get('content.host_blocking.enabled', url=first_party_url): return False