From 9697567b8d2c3edb7ea742baf901ab1c6f40828d Mon Sep 17 00:00:00 2001 From: John Preston Date: Fri, 23 Oct 2020 13:10:30 +0300 Subject: [PATCH] Add some more open file warnings. --- Telegram/Resources/langs/lang.strings | 1 + Telegram/SourceFiles/core/core_settings.cpp | 9 ++- Telegram/SourceFiles/core/core_settings.h | 7 +++ Telegram/SourceFiles/data/data_document.cpp | 67 +++++++++++++-------- Telegram/SourceFiles/data/data_document.h | 7 ++- 5 files changed, 63 insertions(+), 28 deletions(-) diff --git a/Telegram/Resources/langs/lang.strings b/Telegram/Resources/langs/lang.strings index d045626dda..78d54b8512 100644 --- a/Telegram/Resources/langs/lang.strings +++ b/Telegram/Resources/langs/lang.strings @@ -2271,6 +2271,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL "lng_language_not_ready_link" = "translations platform"; "lng_launch_exe_warning" = "This file has a {extension} extension.\nAre you sure you want to run it?"; +"lng_launch_svg_warning" = "Opening this file can potentially expose your IP address to its sender. Continue?"; "lng_launch_exe_sure" = "Run"; "lng_launch_exe_dont_ask" = "Don't ask me again"; diff --git a/Telegram/SourceFiles/core/core_settings.cpp b/Telegram/SourceFiles/core/core_settings.cpp index 43fdefe2db..a7b0b124d0 100644 --- a/Telegram/SourceFiles/core/core_settings.cpp +++ b/Telegram/SourceFiles/core/core_settings.cpp @@ -109,7 +109,8 @@ QByteArray Settings::serialize() const { << qint32(_notifyFromAll ? 1 : 0) << qint32(_nativeWindowFrame.current() ? 1 : 0) << qint32(_systemDarkModeEnabled.current() ? 1 : 0) - << _callVideoInputDeviceId; + << _callVideoInputDeviceId + << qint32(_ipRevealWarning ? 1 : 0); } return result; } @@ -176,6 +177,7 @@ void Settings::addFromSerialized(const QByteArray &serialized) { qint32 notifyFromAll = _notifyFromAll ? 1 : 0; qint32 nativeWindowFrame = _nativeWindowFrame.current() ? 1 : 0; qint32 systemDarkModeEnabled = _systemDarkModeEnabled.current() ? 1 : 0; + qint32 ipRevealWarning = _ipRevealWarning ? 1 : 0; stream >> themesAccentColors; if (!stream.atEnd()) { @@ -259,6 +261,9 @@ void Settings::addFromSerialized(const QByteArray &serialized) { if (!stream.atEnd()) { stream >> callVideoInputDeviceId; } + if (!stream.atEnd()) { + stream >> ipRevealWarning; + } if (stream.status() != QDataStream::Ok) { LOG(("App Error: " "Bad data for Core::Settings::constructFromSerialized()")); @@ -318,6 +323,7 @@ void Settings::addFromSerialized(const QByteArray &serialized) { _includeMutedCounter = (includeMutedCounter == 1); _countUnreadMessages = (countUnreadMessages == 1); _exeLaunchWarning = (exeLaunchWarning == 1); + _ipRevealWarning = (ipRevealWarning == 1); _notifyAboutPinned = (notifyAboutPinned == 1); _loopAnimatedStickers = (loopAnimatedStickers == 1); _largeEmoji = (largeEmoji == 1); @@ -468,6 +474,7 @@ void Settings::resetOnLastLogout() { _soundOverrides = {}; _exeLaunchWarning = true; + _ipRevealWarning = true; _loopAnimatedStickers = true; _largeEmoji = true; _replaceEmoji = true; diff --git a/Telegram/SourceFiles/core/core_settings.h b/Telegram/SourceFiles/core/core_settings.h index a774db0951..d9c0bfaa85 100644 --- a/Telegram/SourceFiles/core/core_settings.h +++ b/Telegram/SourceFiles/core/core_settings.h @@ -255,6 +255,12 @@ public: void setExeLaunchWarning(bool warning) { _exeLaunchWarning = warning; } + [[nodiscard]] bool ipRevealWarning() const { + return _ipRevealWarning; + } + void setIpRevealWarning(bool warning) { + _ipRevealWarning = warning; + } [[nodiscard]] bool loopAnimatedStickers() const { return _loopAnimatedStickers; } @@ -513,6 +519,7 @@ private: Ui::InputSubmitSettings _sendSubmitWay; base::flat_map _soundOverrides; bool _exeLaunchWarning = true; + bool _ipRevealWarning = true; bool _loopAnimatedStickers = true; rpl::variable _largeEmoji = true; rpl::variable _replaceEmoji = true; diff --git a/Telegram/SourceFiles/data/data_document.cpp b/Telegram/SourceFiles/data/data_document.cpp index b30b7eb489..f9fcac1e94 100644 --- a/Telegram/SourceFiles/data/data_document.cpp +++ b/Telegram/SourceFiles/data/data_document.cpp @@ -74,15 +74,15 @@ void LaunchWithWarning( not_null session, const QString &name, HistoryItem *item) { + const auto isExecutable = Data::IsExecutableName(name); + const auto isIpReveal = Data::IsIpRevealingName(name); + auto &app = Core::App(); const auto warn = [&] { - if (!Data::IsExecutableName(name)) { - return false; - } else if (!Core::App().settings().exeLaunchWarning()) { - return false; - } else if (item && item->history()->peer->isVerified()) { + if (item && item->history()->peer->isVerified()) { return false; } - return true; + return (isExecutable && app.settings().exeLaunchWarning()) + || (isIpReveal && app.settings().ipRevealWarning()); }(); const auto extension = '.' + Data::FileExtension(name); if (Platform::IsWindows() && extension == u"."_q) { @@ -99,20 +99,27 @@ void LaunchWithWarning( File::Launch(name); return; } - const auto callback = [=](bool checked) { + const auto callback = [=, &app](bool checked) { if (checked) { - Core::App().settings().setExeLaunchWarning(false); - Core::App().saveSettingsDelayed(); + if (isExecutable) { + app.settings().setExeLaunchWarning(false); + } else if (isIpReveal) { + app.settings().setIpRevealWarning(false); + } + app.saveSettingsDelayed(); } File::Launch(name); }; - Ui::show(Box( - tr::lng_launch_exe_warning( + auto text = isExecutable + ? tr::lng_launch_exe_warning( lt_extension, rpl::single(Ui::Text::Bold(extension)), - Ui::Text::WithEntities), + Ui::Text::WithEntities) + : tr::lng_launch_svg_warning(Ui::Text::WithEntities); + Ui::show(Box( + std::move(text), tr::lng_launch_exe_dont_ask(tr::now), - tr::lng_launch_exe_sure(), + (isExecutable ? tr::lng_launch_exe_sure : tr::lng_continue)(), callback)); } @@ -1668,17 +1675,17 @@ mpkg pkg scpt scptd xhtm webarchive"); slp zsh"); #else // Q_OS_MAC || Q_OS_UNIX qsl("\ -ad ade adp app application appref-ms asp asx bas bat bin cdxml cer cfg chi \ -chm cmd cnt com cpl crt csh der diagcab dll drv eml exe fon fxp gadget grp \ -hlp hpj hta htt inf ini ins inx isp isu its jar jnlp job js jse ksh lnk \ -local lua mad maf mag mam manifest maq mar mas mat mau mav maw mcf mda mdb \ -mde mdt mdw mdz mht mhtml mjs mmc mof msc msg msh msh1 msh2 msh1xml msh2xml \ -mshxml msi msp mst ops osd paf pcd phar php php3 php4 php5 php7 phps php-s \ -pht phtml pif pl plg pm pod prf prg ps1 ps2 ps1xml ps2xml psc1 psc2 psd1 \ -psm1 pssc pst py py3 pyc pyd pyi pyo pyw pywz pyz rb reg rgs scf scr sct \ -search-ms settingcontent-ms sh shb shs slk sys t tmp u3p url vb vbe vbp vbs \ -vbscript vdx vsmacros vsd vsdm vsdx vss vssm vssx vst vstm vstx vsw vsx vtx \ -website ws wsc wsf wsh xbap xll xnk xs"); +ad ade adp app application appref-ms asp asx bas bat bin cab cdxml cer cfg \ +chi chm cmd cnt com cpl crt csh der diagcab dll drv eml exe fon fxp gadget \ +grp hlp hpj hta htt inf ini ins inx isp isu its jar jnlp job js jse key ksh \ +lnk local lua mad maf mag mam manifest maq mar mas mat mau mav maw mcf mda \ +mdb mde mdt mdw mdz mht mhtml mjs mmc mof msc msg msh msh1 msh2 msh1xml \ +msh2xml mshxml msi msp mst ops osd paf pcd phar php php3 php4 php5 php7 phps \ +php-s pht phtml pif pl plg pm pod prf prg ps1 ps2 ps1xml ps2xml psc1 psc2 \ +psd1 psm1 pssc pst py py3 pyc pyd pyi pyo pyw pywz pyz rb reg rgs scf scr \ +sct search-ms settingcontent-ms sh shb shs slk sys t tmp u3p url vb vbe vbp \ +vbs vbscript vdx vsmacros vsd vsdm vsdx vss vssm vssx vst vstm vstx vsw vsx \ +vtx website ws wsc wsf wsh xbap xll xnk xs"); #endif // !Q_OS_MAC && !Q_OS_UNIX const auto list = joined.split(' '); return base::flat_set(list.begin(), list.end()); @@ -1689,6 +1696,18 @@ website ws wsc wsf wsh xbap xll xnk xs"); FileExtension(filepath).toLower()); } +bool IsIpRevealingName(const QString &filepath) { + static const auto kExtensions = [] { + const auto joined = u"htm html svg"_q; + const auto list = joined.split(' '); + return base::flat_set(list.begin(), list.end()); + }(); + + return ranges::binary_search( + kExtensions, + FileExtension(filepath).toLower()); +} + base::binary_guard ReadImageAsync( not_null media, FnMut postprocess, diff --git a/Telegram/SourceFiles/data/data_document.h b/Telegram/SourceFiles/data/data_document.h index ea6a8528ca..efd777f5ee 100644 --- a/Telegram/SourceFiles/data/data_document.h +++ b/Telegram/SourceFiles/data/data_document.h @@ -443,9 +443,10 @@ QString DocumentFileNameForSave( namespace Data { -QString FileExtension(const QString &filepath); -bool IsValidMediaFile(const QString &filepath); -bool IsExecutableName(const QString &filepath); +[[nodiscard]] QString FileExtension(const QString &filepath); +[[nodiscard]] bool IsValidMediaFile(const QString &filepath); +[[nodiscard]] bool IsExecutableName(const QString &filepath); +[[nodiscard]] bool IsIpRevealingName(const QString &filepath); base::binary_guard ReadImageAsync( not_null media, FnMut postprocess,