Skip to content

Commit 19f01bb

Browse files
committed
Security: Remember hosts with ignored cert errors for load status
Without this change, we only set a flag when a certificate error occurred. However, when the same certificate error then happens a second time (e.g. because of a reload or opening the same URL again), we then colored the URL as success_https (i.e. green) again. See #5403 (cherry picked from commit 021ab57)
1 parent 3508352 commit 19f01bb

File tree

3 files changed

+17
-9
lines changed

3 files changed

+17
-9
lines changed

Diff for: qutebrowser/browser/browsertab.py

+12-4
Original file line numberDiff line numberDiff line change
@@ -864,6 +864,13 @@ class AbstractTab(QWidget):
864864
# arg 1: The exit code.
865865
renderer_process_terminated = pyqtSignal(TerminationStatus, int)
866866

867+
# Hosts for which a certificate error happened. Shared between all tabs.
868+
#
869+
# Note that we remember hosts here, without scheme/port:
870+
# QtWebEngine/Chromium also only remembers hostnames, and certificates are
871+
# for a given hostname anyways.
872+
_insecure_hosts = set() # type: typing.Set[str]
873+
867874
def __init__(self, *, win_id: int, private: bool,
868875
parent: QWidget = None) -> None:
869876
self.is_private = private
@@ -881,7 +888,6 @@ def __init__(self, *, win_id: int, private: bool,
881888
self._layout = miscwidgets.WrapperLayout(self)
882889
self._widget = None # type: typing.Optional[QWidget]
883890
self._progress = 0
884-
self._has_ssl_errors = False
885891
self._load_status = usertypes.LoadStatus.none
886892
self._mouse_event_filter = mouse.MouseEventFilter(
887893
self, parent=self)
@@ -969,7 +975,6 @@ def _on_url_changed(self, url: QUrl) -> None:
969975
@pyqtSlot()
970976
def _on_load_started(self) -> None:
971977
self._progress = 0
972-
self._has_ssl_errors = False
973978
self.data.viewing_source = False
974979
self._set_load_status(usertypes.LoadStatus.loading)
975980
self.load_started.emit()
@@ -1029,9 +1034,12 @@ def _update_load_status(self, ok: bool) -> None:
10291034
Needs to be called by subclasses to trigger a load status update, e.g.
10301035
as a response to a loadFinished signal.
10311036
"""
1032-
if ok and not self._has_ssl_errors:
1037+
if ok:
10331038
if self.url().scheme() == 'https':
1034-
self._set_load_status(usertypes.LoadStatus.success_https)
1039+
if self.url().host() in self._insecure_hosts:
1040+
self._set_load_status(usertypes.LoadStatus.warn)
1041+
else:
1042+
self._set_load_status(usertypes.LoadStatus.success_https)
10351043
else:
10361044
self._set_load_status(usertypes.LoadStatus.success)
10371045
elif ok:

Diff for: qutebrowser/browser/webengine/webenginetab.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1395,9 +1395,9 @@ def _on_load_finished(self, ok: bool) -> None:
13951395

13961396
@pyqtSlot(certificateerror.CertificateErrorWrapper)
13971397
def _on_ssl_errors(self, error):
1398-
self._has_ssl_errors = True
1399-
14001398
url = error.url()
1399+
self._insecure_hosts.add(url.host())
1400+
14011401
log.webview.debug("Certificate error: {}".format(error))
14021402

14031403
if error.is_overridable():

Diff for: qutebrowser/browser/webkit/webkittab.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -851,9 +851,9 @@ def _on_navigation_request(self, navigation):
851851
if navigation.is_main_frame:
852852
self.settings.update_for_url(navigation.url)
853853

854-
@pyqtSlot()
855-
def _on_ssl_errors(self):
856-
self._has_ssl_errors = True
854+
@pyqtSlot('QNetworkReply*')
855+
def _on_ssl_errors(self, reply):
856+
self._insecure_hosts.add(reply.url().host())
857857

858858
def _connect_signals(self):
859859
view = self._widget

0 commit comments

Comments
 (0)