Skip to content

Commit 6821c23

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 6cb0cfc commit 6821c23

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

872+
# Hosts for which a certificate error happened. Shared between all tabs.
873+
#
874+
# Note that we remember hosts here, without scheme/port:
875+
# QtWebEngine/Chromium also only remembers hostnames, and certificates are
876+
# for a given hostname anyways.
877+
_insecure_hosts = set() # type: typing.Set[str]
878+
872879
def __init__(self, *, win_id: int, private: bool,
873880
parent: QWidget = None) -> None:
874881
self.is_private = private
@@ -886,7 +893,6 @@ def __init__(self, *, win_id: int, private: bool,
886893
self._layout = miscwidgets.WrapperLayout(self)
887894
self._widget = typing.cast(QWidget, None)
888895
self._progress = 0
889-
self._has_ssl_errors = False
890896
self._load_status = usertypes.LoadStatus.none
891897
self._tab_event_filter = eventfilter.TabEventFilter(
892898
self, parent=self)
@@ -973,7 +979,6 @@ def _on_url_changed(self, url: QUrl) -> None:
973979
@pyqtSlot()
974980
def _on_load_started(self) -> None:
975981
self._progress = 0
976-
self._has_ssl_errors = False
977982
self.data.viewing_source = False
978983
self._set_load_status(usertypes.LoadStatus.loading)
979984
self.load_started.emit()
@@ -1032,9 +1037,12 @@ def _update_load_status(self, ok: bool) -> None:
10321037
Needs to be called by subclasses to trigger a load status update, e.g.
10331038
as a response to a loadFinished signal.
10341039
"""
1035-
if ok and not self._has_ssl_errors:
1040+
if ok:
10361041
if self.url().scheme() == 'https':
1037-
self._set_load_status(usertypes.LoadStatus.success_https)
1042+
if self.url().host() in self._insecure_hosts:
1043+
self._set_load_status(usertypes.LoadStatus.warn)
1044+
else:
1045+
self._set_load_status(usertypes.LoadStatus.success_https)
10381046
else:
10391047
self._set_load_status(usertypes.LoadStatus.success)
10401048
elif ok:

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

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

15501550
@pyqtSlot(certificateerror.CertificateErrorWrapper)
15511551
def _on_ssl_errors(self, error):
1552-
self._has_ssl_errors = True
1553-
15541552
url = error.url()
1553+
self._insecure_hosts.add(url.host())
1554+
15551555
log.webview.debug("Certificate error: {}".format(error))
15561556

15571557
if error.is_overridable():

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

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

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

856856
def _connect_signals(self):
857857
view = self._widget

0 commit comments

Comments
 (0)