Skip to content

Commit d28ed75

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 c792f41 commit d28ed75

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
@@ -867,6 +867,13 @@ class AbstractTab(QWidget):
867867
# arg 1: The exit code.
868868
renderer_process_terminated = pyqtSignal(TerminationStatus, int)
869869

870+
# Hosts for which a certificate error happened. Shared between all tabs.
871+
#
872+
# Note that we remember hosts here, without scheme/port:
873+
# QtWebEngine/Chromium also only remembers hostnames, and certificates are
874+
# for a given hostname anyways.
875+
_insecure_hosts = set() # type: typing.Set[str]
876+
870877
def __init__(self, *, win_id: int, private: bool,
871878
parent: QWidget = None) -> None:
872879
self.is_private = private
@@ -884,7 +891,6 @@ def __init__(self, *, win_id: int, private: bool,
884891
self._layout = miscwidgets.WrapperLayout(self)
885892
self._widget = typing.cast(QWidget, None)
886893
self._progress = 0
887-
self._has_ssl_errors = False
888894
self._load_status = usertypes.LoadStatus.none
889895
self._tab_event_filter = eventfilter.TabEventFilter(
890896
self, parent=self)
@@ -971,7 +977,6 @@ def _on_url_changed(self, url: QUrl) -> None:
971977
@pyqtSlot()
972978
def _on_load_started(self) -> None:
973979
self._progress = 0
974-
self._has_ssl_errors = False
975980
self.data.viewing_source = False
976981
self._set_load_status(usertypes.LoadStatus.loading)
977982
self.load_started.emit()
@@ -1030,9 +1035,12 @@ def _update_load_status(self, ok: bool) -> None:
10301035
Needs to be called by subclasses to trigger a load status update, e.g.
10311036
as a response to a loadFinished signal.
10321037
"""
1033-
if ok and not self._has_ssl_errors:
1038+
if ok:
10341039
if self.url().scheme() == 'https':
1035-
self._set_load_status(usertypes.LoadStatus.success_https)
1040+
if self.url().host() in self._insecure_hosts:
1041+
self._set_load_status(usertypes.LoadStatus.warn)
1042+
else:
1043+
self._set_load_status(usertypes.LoadStatus.success_https)
10361044
else:
10371045
self._set_load_status(usertypes.LoadStatus.success)
10381046
elif ok:

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

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

14511451
@pyqtSlot(certificateerror.CertificateErrorWrapper)
14521452
def _on_ssl_errors(self, error):
1453-
self._has_ssl_errors = True
1454-
14551453
url = error.url()
1454+
self._insecure_hosts.add(url.host())
1455+
14561456
log.webview.debug("Certificate error: {}".format(error))
14571457

14581458
if error.is_overridable():

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

+3-3
Original file line numberDiff line numberDiff line change
@@ -847,9 +847,9 @@ def _on_navigation_request(self, navigation):
847847
if navigation.is_main_frame:
848848
self.settings.update_for_url(navigation.url)
849849

850-
@pyqtSlot()
851-
def _on_ssl_errors(self):
852-
self._has_ssl_errors = True
850+
@pyqtSlot('QNetworkReply*')
851+
def _on_ssl_errors(self, reply):
852+
self._insecure_hosts.add(reply.url().host())
853853

854854
def _connect_signals(self):
855855
view = self._widget

0 commit comments

Comments
 (0)