Dns-leak in QtWebEngine



I create web-browser Qt whith QtWebEngine.而且它不想通过代理解析 DNS 请求。

QWebEngineSettings::DnsPrefetchEnabled不起作用。

我尝试通过QWebEngineUrlRequestInterceptor抓住它们,但也没有用。

举个例子:

主.cpp

#include "mainwindow.h"
#include <QApplication>
int main(int argc, char *argv[])
{
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
QCoreApplication::setAttribute(Qt::AA_UseHighDpiPixmaps);
QApplication a(argc, argv);
MainWindow w;
w.show();
return a.exec();
}

主窗口.h

#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
MainWindow(QWidget *parent = nullptr);
~MainWindow();
};
#endif // MAINWINDOW_H

主窗口.h

#include "mainwindow.h"
#include <QDebug>
#include <QWebEngineView>
#include <QWebEnginePage>
#include <QWebEngineProfile>
#include <QWebEngineSettings>
#include <QNetworkProxy>

MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
{
QNetworkProxy proxy;
proxy.setType(QNetworkProxy::HttpProxy);
proxy.setHostName("proxy_host");
proxy.setPort(proxy_port);
proxy.setCapabilities(QNetworkProxy::HostNameLookupCapability);
//proxy.setUser(user);
//proxy.setPassword(pass);
QNetworkProxy::setApplicationProxy(proxy);
QWebEngineProfile *profile = QWebEngineProfile::defaultProfile();
QWebEngineSettings* sett = profile->settings();
sett->setAttribute(QWebEngineSettings::PluginsEnabled, true);
sett->setAttribute(QWebEngineSettings::XSSAuditingEnabled, false);
sett->setAttribute(QWebEngineSettings::LocalContentCanAccessRemoteUrls, true);
sett->setUnknownUrlSchemePolicy(QWebEngineSettings::AllowAllUnknownUrlSchemes);
sett->setAttribute(QWebEngineSettings::DnsPrefetchEnabled, false);
profile->setUseForGlobalCertificateVerification();
QWebEngineView *w = new QWebEngineView(this);
QWebEnginePage *p = new QWebEnginePage(profile,this);
w->setPage(p);
w->load(QUrl("https://browserleaks.com/ip"));
this->setCentralWidget(w);
this->resize(900,900);
}

我编写了一个本地代理服务器并使用--host-resolver-rules标志(它最终在 5.15 开始工作(将所有内容都引用给了它。任务一般都解决了,但如果你知道更优雅的解决方案,欢迎你来到我的小屋。