Merge remote-tracking branch 'origin/pr/4046'
This commit is contained in:
commit
14957c75ff
@ -110,9 +110,10 @@ class HostBlocker:
|
||||
|
||||
config.instance.changed.connect(self._update_files)
|
||||
|
||||
def is_blocked(self, url):
|
||||
def is_blocked(self, url, first_party_url=None):
|
||||
"""Check if the given URL (as QUrl) is blocked."""
|
||||
if not config.val.content.host_blocking.enabled:
|
||||
if not config.instance.get('content.host_blocking.enabled',
|
||||
url=first_party_url):
|
||||
return False
|
||||
host = url.host()
|
||||
return ((host in self._blocked_hosts or
|
||||
|
@ -70,21 +70,21 @@ class RequestInterceptor(QWebEngineUrlRequestInterceptor):
|
||||
resource_type, navigation_type))
|
||||
|
||||
url = info.requestUrl()
|
||||
firstparty = info.firstPartyUrl()
|
||||
first_party = info.firstPartyUrl()
|
||||
|
||||
if ((url.scheme(), url.host(), url.path()) ==
|
||||
('qute', 'settings', '/set')):
|
||||
if (firstparty != QUrl('qute://settings/') or
|
||||
if (first_party != QUrl('qute://settings/') or
|
||||
info.resourceType() !=
|
||||
QWebEngineUrlRequestInfo.ResourceTypeXhr):
|
||||
log.webview.warning("Blocking malicious request from {} to {}"
|
||||
.format(firstparty.toDisplayString(),
|
||||
.format(first_party.toDisplayString(),
|
||||
url.toDisplayString()))
|
||||
info.block(True)
|
||||
return
|
||||
|
||||
# FIXME:qtwebengine only block ads for NavigationTypeOther?
|
||||
if self._host_blocker.is_blocked(url):
|
||||
if self._host_blocker.is_blocked(url, first_party):
|
||||
log.webview.info("Request to {} blocked by host blocker.".format(
|
||||
url.host()))
|
||||
info.block(True)
|
||||
|
@ -376,14 +376,6 @@ class NetworkManager(QNetworkAccessManager):
|
||||
for header, value in shared.custom_headers(url=req.url()):
|
||||
req.setRawHeader(header, value)
|
||||
|
||||
host_blocker = objreg.get('host-blocker')
|
||||
if host_blocker.is_blocked(req.url()):
|
||||
log.webview.info("Request to {} blocked by host blocker.".format(
|
||||
req.url().host()))
|
||||
return networkreply.ErrorNetworkReply(
|
||||
req, HOSTBLOCK_ERROR_STRING, QNetworkReply.ContentAccessDenied,
|
||||
self)
|
||||
|
||||
# There are some scenarios where we can't figure out current_url:
|
||||
# - There's a generic NetworkManager, e.g. for downloads
|
||||
# - The download was in a tab which is now closed.
|
||||
@ -401,6 +393,14 @@ class NetworkManager(QNetworkAccessManager):
|
||||
# the webpage shutdown here.
|
||||
current_url = QUrl()
|
||||
|
||||
host_blocker = objreg.get('host-blocker')
|
||||
if host_blocker.is_blocked(req.url(), current_url):
|
||||
log.webview.info("Request to {} blocked by host blocker.".format(
|
||||
req.url().host()))
|
||||
return networkreply.ErrorNetworkReply(
|
||||
req, HOSTBLOCK_ERROR_STRING, QNetworkReply.ContentAccessDenied,
|
||||
self)
|
||||
|
||||
if 'log-requests' in self._args.debug_flags:
|
||||
operation = debug.qenum_key(QNetworkAccessManager, op)
|
||||
operation = operation.replace('Operation', '').upper()
|
||||
|
@ -529,6 +529,7 @@ content.headers.user_agent:
|
||||
|
||||
content.host_blocking.enabled:
|
||||
default: true
|
||||
supports_pattern: true
|
||||
type: Bool
|
||||
desc: Enable host blocking.
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user