Disallow PAC proxies with QtWebEngine

See #4577
This commit is contained in:
Florian Bruhin 2019-02-21 13:29:06 +01:00
parent 17846ea386
commit be26efddd3
3 changed files with 24 additions and 2 deletions

View File

@ -85,6 +85,8 @@ Fixed
- The outdated header `X-Do-Not-Track` is no longer sent. - The outdated header `X-Do-Not-Track` is no longer sent.
- A javascript error on page load when using Qt 5.12 was fixed. - A javascript error on page load when using Qt 5.12 was fixed.
- `window.print()` works with Qt 5.12 now. - `window.print()` works with Qt 5.12 now.
- PAC proxies were never correctly supported with QtWebEngine, but are now
explicitly disallowed.
v1.5.2 v1.5.2
------ ------

View File

@ -208,6 +208,8 @@ class PACResolver:
Return: Return:
A list of QNetworkProxy objects in order of preference. A list of QNetworkProxy objects in order of preference.
""" """
qtutils.ensure_valid(query.url())
if from_file: if from_file:
string_flags = QUrl.PrettyDecoded string_flags = QUrl.PrettyDecoded
else: else:

View File

@ -20,10 +20,12 @@
"""Handling of proxies.""" """Handling of proxies."""
from PyQt5.QtCore import QUrl
from PyQt5.QtNetwork import QNetworkProxy, QNetworkProxyFactory from PyQt5.QtNetwork import QNetworkProxy, QNetworkProxyFactory
from qutebrowser.config import config, configtypes from qutebrowser.config import config, configtypes
from qutebrowser.utils import objreg from qutebrowser.utils import objreg, message, usertypes, urlutils
from qutebrowser.misc import objects
from qutebrowser.browser.network import pac from qutebrowser.browser.network import pac
@ -33,6 +35,18 @@ def init():
objreg.register('proxy-factory', proxy_factory) objreg.register('proxy-factory', proxy_factory)
QNetworkProxyFactory.setApplicationProxyFactory(proxy_factory) QNetworkProxyFactory.setApplicationProxyFactory(proxy_factory)
config.instance.changed.connect(_warn_for_pac)
_warn_for_pac()
@config.change_filter('content.proxy', function=True)
def _warn_for_pac():
"""Show a warning if PAC is used with QtWebEngine."""
proxy = config.val.content.proxy
if (isinstance(proxy, pac.PACFetcher) and
objects.backend == usertypes.Backend.QtWebEngine):
message.error("PAC support isn't implemented for QtWebEngine yet!")
def shutdown(): def shutdown():
QNetworkProxyFactory.setApplicationProxyFactory(None) QNetworkProxyFactory.setApplicationProxyFactory(None)
@ -70,6 +84,10 @@ class ProxyFactory(QNetworkProxyFactory):
# ref. http://doc.qt.io/qt-5/qnetworkproxyfactory.html#systemProxyForQuery # ref. http://doc.qt.io/qt-5/qnetworkproxyfactory.html#systemProxyForQuery
proxies = QNetworkProxyFactory.systemProxyForQuery(query) proxies = QNetworkProxyFactory.systemProxyForQuery(query)
elif isinstance(proxy, pac.PACFetcher): elif isinstance(proxy, pac.PACFetcher):
if objects.backend == usertypes.Backend.QtWebEngine:
# Looks like query.url() is always invalid on QtWebEngine...
proxies = [urlutils.proxy_from_url(QUrl('direct://'))]
else:
proxies = proxy.resolve(query) proxies = proxy.resolve(query)
else: else:
proxies = [proxy] proxies = [proxy]