Add confirmation box for suspicious urls.

This commit is contained in:
John Preston 2020-04-23 17:56:50 +04:00
parent 3fa5e004fe
commit cfd733c54c
6 changed files with 18 additions and 5 deletions

View File

@ -51,9 +51,14 @@ void HiddenUrlClickHandler::Open(QString url, QVariant context) {
if (UrlRequiresConfirmation(url) if (UrlRequiresConfirmation(url)
&& QGuiApplication::keyboardModifiers() != Qt::ControlModifier) { && QGuiApplication::keyboardModifiers() != Qt::ControlModifier) {
Core::App().hideMediaView(); Core::App().hideMediaView();
const auto displayUrl = parsedUrl.isValid() const auto displayed = parsedUrl.isValid()
? parsedUrl.toDisplayString() ? parsedUrl.toDisplayString()
: url; : url;
const auto displayUrl = !IsSuspicious(displayed)
? displayed
: parsedUrl.isValid()
? QString::fromUtf8(parsedUrl.toEncoded())
: ShowEncoded(displayed);
Ui::show( Ui::show(
Box<ConfirmBox>( Box<ConfirmBox>(
(tr::lng_open_this_link(tr::now) (tr::lng_open_this_link(tr::now)

View File

@ -66,6 +66,11 @@ std::shared_ptr<ClickHandler> UiIntegration::createLinkHandler(
const QString &data, const QString &data,
const TextParseOptions &options) { const TextParseOptions &options) {
switch (type) { switch (type) {
case EntityType::Url:
return (!data.isEmpty() && UrlClickHandler::IsSuspicious(data))
? std::make_shared<HiddenUrlClickHandler>(data)
: nullptr;
case EntityType::CustomUrl: case EntityType::CustomUrl:
return !data.isEmpty() return !data.isEmpty()
? std::make_shared<HiddenUrlClickHandler>(data) ? std::make_shared<HiddenUrlClickHandler>(data)

View File

@ -3649,7 +3649,7 @@ void HistoryWidget::botCallbackDone(
updateSendAction(item->history(), SendAction::Type::PlayGame); updateSendAction(item->history(), SendAction::Type::PlayGame);
} }
} else { } else {
UrlClickHandler(link).onClick({}); UrlClickHandler::Open(link);
} }
} }
}); });

View File

@ -127,7 +127,8 @@ QSize WebPage::countOptimalSize() {
} }
return true; return true;
}(); }();
_openl = previewOfHiddenUrl _openl = (previewOfHiddenUrl
|| UrlClickHandler::IsSuspicious(_data->url))
? std::make_shared<HiddenUrlClickHandler>(_data->url) ? std::make_shared<HiddenUrlClickHandler>(_data->url)
: std::make_shared<UrlClickHandler>(_data->url, true); : std::make_shared<UrlClickHandler>(_data->url, true);
if (_data->document if (_data->document

View File

@ -1619,7 +1619,9 @@ const style::RoundCheckbox &Link::checkboxStyle() const {
Link::LinkEntry::LinkEntry(const QString &url, const QString &text) Link::LinkEntry::LinkEntry(const QString &url, const QString &text)
: text(text) : text(text)
, width(st::normalFont->width(text)) , width(st::normalFont->width(text))
, lnk(std::make_shared<UrlClickHandler>(url)) { , lnk(UrlClickHandler::IsSuspicious(url)
? std::make_shared<HiddenUrlClickHandler>(url)
: std::make_shared<UrlClickHandler>(url)) {
} }
} // namespace Layout } // namespace Layout

@ -1 +1 @@
Subproject commit 40084cab9577064436e2b381c27f498ac4a210a3 Subproject commit 725d768f0ff1c22f6b477c28c324c20cbf2419da