[email protected] | 33ca232f | 2012-04-10 00:08:45 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #include "chrome/browser/download/download_danger_prompt.h" |
| 6 | |
avi | e4d7b6f | 2015-12-26 00:59:18 | [diff] [blame] | 7 | #include "base/macros.h" |
Ilya Sherman | 982457e6 | 2017-12-13 02:19:36 | [diff] [blame] | 8 | #include "base/metrics/histogram_functions.h" |
jialiul | 70cd6f2c | 2016-02-02 23:24:57 | [diff] [blame] | 9 | #include "base/strings/stringprintf.h" |
jialiul | 7f11b74 | 2015-11-26 04:54:49 | [diff] [blame] | 10 | #include "chrome/browser/browser_process.h" |
Micah Morton | 5675f90 | 2017-08-16 22:35:19 | [diff] [blame] | 11 | #include "chrome/browser/safe_browsing/download_protection/download_protection_service.h" |
jialiul | 7f11b74 | 2015-11-26 04:54:49 | [diff] [blame] | 12 | #include "chrome/browser/safe_browsing/safe_browsing_service.h" |
Min Qin | 0ca8e1ee | 2018-01-31 00:49:35 | [diff] [blame] | 13 | #include "components/download/public/common/download_danger_type.h" |
Min Qin | a9f48787 | 2018-02-09 20:43:23 | [diff] [blame] | 14 | #include "components/download/public/common/download_item.h" |
Colin Blundell | 641e4e4 | 2021-06-24 16:09:53 | [diff] [blame^] | 15 | #include "components/safe_browsing/content/browser/web_ui/safe_browsing_ui.h" |
Daniel Rubery | af17ad3 | 2020-03-02 20:06:49 | [diff] [blame] | 16 | #include "components/safe_browsing/core/file_type_policies.h" |
Xinghui Lu | 09e84f58 | 2021-05-11 19:18:29 | [diff] [blame] | 17 | #include "content/public/browser/browser_task_traits.h" |
| 18 | #include "content/public/browser/browser_thread.h" |
Daniel Rubery | dd3f5a49 | 2020-08-18 19:20:35 | [diff] [blame] | 19 | #include "content/public/browser/download_item_utils.h" |
[email protected] | 33ca232f | 2012-04-10 00:08:45 | [diff] [blame] | 20 | |
jialiul | ee910ec1 | 2016-01-11 19:42:46 | [diff] [blame] | 21 | using safe_browsing::ClientDownloadResponse; |
jialiul | 7f11b74 | 2015-11-26 04:54:49 | [diff] [blame] | 22 | using safe_browsing::ClientSafeBrowsingReportRequest; |
[email protected] | f85a34b | 2014-08-16 01:10:16 | [diff] [blame] | 23 | |
[email protected] | 33ca232f | 2012-04-10 00:08:45 | [diff] [blame] | 24 | namespace { |
| 25 | |
jialiul | 70cd6f2c | 2016-02-02 23:24:57 | [diff] [blame] | 26 | const char kDownloadDangerPromptPrefix[] = "Download.DownloadDangerPrompt"; |
| 27 | |
jialiul | 70cd6f2c | 2016-02-02 23:24:57 | [diff] [blame] | 28 | // Converts DownloadDangerType into their corresponding string. |
| 29 | const char* GetDangerTypeString( |
Min Qin | 0ca8e1ee | 2018-01-31 00:49:35 | [diff] [blame] | 30 | const download::DownloadDangerType& danger_type) { |
jialiul | 70cd6f2c | 2016-02-02 23:24:57 | [diff] [blame] | 31 | switch (danger_type) { |
Min Qin | 0ca8e1ee | 2018-01-31 00:49:35 | [diff] [blame] | 32 | case download::DOWNLOAD_DANGER_TYPE_DANGEROUS_FILE: |
jialiul | 70cd6f2c | 2016-02-02 23:24:57 | [diff] [blame] | 33 | return "DangerousFile"; |
Min Qin | 0ca8e1ee | 2018-01-31 00:49:35 | [diff] [blame] | 34 | case download::DOWNLOAD_DANGER_TYPE_DANGEROUS_URL: |
jialiul | 70cd6f2c | 2016-02-02 23:24:57 | [diff] [blame] | 35 | return "DangerousURL"; |
Min Qin | 0ca8e1ee | 2018-01-31 00:49:35 | [diff] [blame] | 36 | case download::DOWNLOAD_DANGER_TYPE_DANGEROUS_CONTENT: |
jialiul | 70cd6f2c | 2016-02-02 23:24:57 | [diff] [blame] | 37 | return "DangerousContent"; |
Min Qin | 0ca8e1ee | 2018-01-31 00:49:35 | [diff] [blame] | 38 | case download::DOWNLOAD_DANGER_TYPE_DANGEROUS_HOST: |
jialiul | 70cd6f2c | 2016-02-02 23:24:57 | [diff] [blame] | 39 | return "DangerousHost"; |
Min Qin | 0ca8e1ee | 2018-01-31 00:49:35 | [diff] [blame] | 40 | case download::DOWNLOAD_DANGER_TYPE_UNCOMMON_CONTENT: |
jialiul | 70cd6f2c | 2016-02-02 23:24:57 | [diff] [blame] | 41 | return "UncommonContent"; |
Min Qin | 0ca8e1ee | 2018-01-31 00:49:35 | [diff] [blame] | 42 | case download::DOWNLOAD_DANGER_TYPE_POTENTIALLY_UNWANTED: |
jialiul | 70cd6f2c | 2016-02-02 23:24:57 | [diff] [blame] | 43 | return "PotentiallyUnwanted"; |
Daniel Rubery | e357cb41a | 2019-07-08 20:22:20 | [diff] [blame] | 44 | case download::DOWNLOAD_DANGER_TYPE_ASYNC_SCANNING: |
| 45 | return "AsyncScanning"; |
Daniel Rubery | 7746d12 | 2019-07-17 01:28:59 | [diff] [blame] | 46 | case download::DOWNLOAD_DANGER_TYPE_BLOCKED_PASSWORD_PROTECTED: |
| 47 | return "BlockedPasswordProtected"; |
Daniel Rubery | 0b556b9 | 2019-10-15 20:35:09 | [diff] [blame] | 48 | case download::DOWNLOAD_DANGER_TYPE_BLOCKED_TOO_LARGE: |
| 49 | return "BlockedTooLarge"; |
| 50 | case download::DOWNLOAD_DANGER_TYPE_SENSITIVE_CONTENT_WARNING: |
| 51 | return "SensitiveContentWarning"; |
| 52 | case download::DOWNLOAD_DANGER_TYPE_SENSITIVE_CONTENT_BLOCK: |
| 53 | return "SensitiveContentBlock"; |
| 54 | case download::DOWNLOAD_DANGER_TYPE_DEEP_SCANNED_SAFE: |
| 55 | return "DeepScannedSafe"; |
| 56 | case download::DOWNLOAD_DANGER_TYPE_DEEP_SCANNED_OPENED_DANGEROUS: |
| 57 | return "DeepScannedOpenedDangerous"; |
Daniel Rubery | e6247df | 2019-12-16 19:51:53 | [diff] [blame] | 58 | case download::DOWNLOAD_DANGER_TYPE_PROMPT_FOR_SCANNING: |
| 59 | return "PromptForScanning"; |
Daniel Rubery | d6a3efe5 | 2020-03-13 19:51:48 | [diff] [blame] | 60 | case download::DOWNLOAD_DANGER_TYPE_BLOCKED_UNSUPPORTED_FILETYPE: |
| 61 | return "BlockedUnsupportedFiletype"; |
Olabode Anise | 20accf3 | 2021-05-19 15:02:23 | [diff] [blame] | 62 | case download::DOWNLOAD_DANGER_TYPE_DANGEROUS_ACCOUNT_COMPROMISE: |
| 63 | return "DangerousAccountCompromise"; |
Min Qin | 0ca8e1ee | 2018-01-31 00:49:35 | [diff] [blame] | 64 | case download::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS: |
| 65 | case download::DOWNLOAD_DANGER_TYPE_MAYBE_DANGEROUS_CONTENT: |
| 66 | case download::DOWNLOAD_DANGER_TYPE_USER_VALIDATED: |
Scott Violet | 5177d69 | 2020-12-11 16:55:10 | [diff] [blame] | 67 | case download::DOWNLOAD_DANGER_TYPE_ALLOWLISTED_BY_POLICY: |
Min Qin | 0ca8e1ee | 2018-01-31 00:49:35 | [diff] [blame] | 68 | case download::DOWNLOAD_DANGER_TYPE_MAX: |
jialiul | 70cd6f2c | 2016-02-02 23:24:57 | [diff] [blame] | 69 | break; |
| 70 | } |
| 71 | NOTREACHED(); |
| 72 | return nullptr; |
| 73 | } |
| 74 | |
[email protected] | cce1bad6 | 2013-01-04 02:26:38 | [diff] [blame] | 75 | } // namespace |
[email protected] | 33ca232f | 2012-04-10 00:08:45 | [diff] [blame] | 76 | |
jialiul | 2c263858 | 2016-06-08 22:18:08 | [diff] [blame] | 77 | void DownloadDangerPrompt::SendSafeBrowsingDownloadReport( |
| 78 | ClientSafeBrowsingReportRequest::ReportType report_type, |
jialiul | 7f11b74 | 2015-11-26 04:54:49 | [diff] [blame] | 79 | bool did_proceed, |
Min Qin | a9f48787 | 2018-02-09 20:43:23 | [diff] [blame] | 80 | const download::DownloadItem& download) { |
jialiul | 7f11b74 | 2015-11-26 04:54:49 | [diff] [blame] | 81 | safe_browsing::SafeBrowsingService* sb_service = |
| 82 | g_browser_process->safe_browsing_service(); |
Daniel Rubery | dd3f5a49 | 2020-08-18 19:20:35 | [diff] [blame] | 83 | Profile* profile = Profile::FromBrowserContext( |
| 84 | content::DownloadItemUtils::GetBrowserContext(&download)); |
Xinghui Lu | 09e84f58 | 2021-05-11 19:18:29 | [diff] [blame] | 85 | auto report = std::make_unique<ClientSafeBrowsingReportRequest>(); |
| 86 | report->set_type(report_type); |
jialiul | ee910ec1 | 2016-01-11 19:42:46 | [diff] [blame] | 87 | switch (download.GetDangerType()) { |
Min Qin | 0ca8e1ee | 2018-01-31 00:49:35 | [diff] [blame] | 88 | case download::DOWNLOAD_DANGER_TYPE_DANGEROUS_URL: |
| 89 | case download::DOWNLOAD_DANGER_TYPE_DANGEROUS_CONTENT: |
Xinghui Lu | 09e84f58 | 2021-05-11 19:18:29 | [diff] [blame] | 90 | report->set_download_verdict(ClientDownloadResponse::DANGEROUS); |
jialiul | ee910ec1 | 2016-01-11 19:42:46 | [diff] [blame] | 91 | break; |
Min Qin | 0ca8e1ee | 2018-01-31 00:49:35 | [diff] [blame] | 92 | case download::DOWNLOAD_DANGER_TYPE_UNCOMMON_CONTENT: |
Xinghui Lu | 09e84f58 | 2021-05-11 19:18:29 | [diff] [blame] | 93 | report->set_download_verdict(ClientDownloadResponse::UNCOMMON); |
jialiul | ee910ec1 | 2016-01-11 19:42:46 | [diff] [blame] | 94 | break; |
Min Qin | 0ca8e1ee | 2018-01-31 00:49:35 | [diff] [blame] | 95 | case download::DOWNLOAD_DANGER_TYPE_POTENTIALLY_UNWANTED: |
Xinghui Lu | 09e84f58 | 2021-05-11 19:18:29 | [diff] [blame] | 96 | report->set_download_verdict( |
| 97 | ClientDownloadResponse::POTENTIALLY_UNWANTED); |
jialiul | ee910ec1 | 2016-01-11 19:42:46 | [diff] [blame] | 98 | break; |
Min Qin | 0ca8e1ee | 2018-01-31 00:49:35 | [diff] [blame] | 99 | case download::DOWNLOAD_DANGER_TYPE_DANGEROUS_HOST: |
Xinghui Lu | 09e84f58 | 2021-05-11 19:18:29 | [diff] [blame] | 100 | report->set_download_verdict(ClientDownloadResponse::DANGEROUS_HOST); |
jialiul | ee910ec1 | 2016-01-11 19:42:46 | [diff] [blame] | 101 | break; |
Olabode Anise | 20accf3 | 2021-05-19 15:02:23 | [diff] [blame] | 102 | case download::DOWNLOAD_DANGER_TYPE_DANGEROUS_ACCOUNT_COMPROMISE: |
| 103 | report->set_download_verdict( |
| 104 | ClientDownloadResponse::DANGEROUS_ACCOUNT_COMPROMISE); |
| 105 | break; |
jialiul | 7526f82 | 2016-05-20 22:22:27 | [diff] [blame] | 106 | default: // Don't send report for any other danger types. |
| 107 | return; |
jialiul | ee910ec1 | 2016-01-11 19:42:46 | [diff] [blame] | 108 | } |
Xinghui Lu | 09e84f58 | 2021-05-11 19:18:29 | [diff] [blame] | 109 | report->set_url(download.GetURL().spec()); |
| 110 | report->set_did_proceed(did_proceed); |
jialiul | 2c263858 | 2016-06-08 22:18:08 | [diff] [blame] | 111 | std::string token = |
Olabode Anise | 20accf3 | 2021-05-19 15:02:23 | [diff] [blame] | 112 | safe_browsing::DownloadProtectionService::GetDownloadPingToken(&download); |
jialiul | 2c263858 | 2016-06-08 22:18:08 | [diff] [blame] | 113 | if (!token.empty()) |
Xinghui Lu | 09e84f58 | 2021-05-11 19:18:29 | [diff] [blame] | 114 | report->set_token(token); |
jialiul | 7f11b74 | 2015-11-26 04:54:49 | [diff] [blame] | 115 | std::string serialized_report; |
Xinghui Lu | 09e84f58 | 2021-05-11 19:18:29 | [diff] [blame] | 116 | if (report->SerializeToString(&serialized_report)) { |
Daniel Rubery | dd3f5a49 | 2020-08-18 19:20:35 | [diff] [blame] | 117 | sb_service->SendSerializedDownloadReport(profile, serialized_report); |
Xinghui Lu | 09e84f58 | 2021-05-11 19:18:29 | [diff] [blame] | 118 | |
| 119 | // The following is to log this ClientSafeBrowsingReportRequest on any open |
| 120 | // chrome://safe-browsing pages. |
| 121 | content::GetUIThreadTaskRunner({})->PostTask( |
| 122 | FROM_HERE, |
| 123 | base::BindOnce( |
| 124 | &safe_browsing::WebUIInfoSingleton::AddToCSBRRsSent, |
| 125 | base::Unretained(safe_browsing::WebUIInfoSingleton::GetInstance()), |
| 126 | std::move(report))); |
| 127 | } else { |
jialiul | 7f11b74 | 2015-11-26 04:54:49 | [diff] [blame] | 128 | DLOG(ERROR) << "Unable to serialize the threat report."; |
Xinghui Lu | 09e84f58 | 2021-05-11 19:18:29 | [diff] [blame] | 129 | } |
jialiul | 7f11b74 | 2015-11-26 04:54:49 | [diff] [blame] | 130 | } |
jialiul | 70cd6f2c | 2016-02-02 23:24:57 | [diff] [blame] | 131 | |
| 132 | void DownloadDangerPrompt::RecordDownloadDangerPrompt( |
| 133 | bool did_proceed, |
Min Qin | a9f48787 | 2018-02-09 20:43:23 | [diff] [blame] | 134 | const download::DownloadItem& download) { |
nparker | ac9da06 | 2016-05-19 21:47:23 | [diff] [blame] | 135 | int64_t file_type_uma_value = |
| 136 | safe_browsing::FileTypePolicies::GetInstance()->UmaValueForFile( |
| 137 | download.GetTargetFilePath()); |
Min Qin | 0ca8e1ee | 2018-01-31 00:49:35 | [diff] [blame] | 138 | download::DownloadDangerType danger_type = download.GetDangerType(); |
jialiul | 70cd6f2c | 2016-02-02 23:24:57 | [diff] [blame] | 139 | |
Ilya Sherman | 982457e6 | 2017-12-13 02:19:36 | [diff] [blame] | 140 | base::UmaHistogramSparse( |
jialiul | 70cd6f2c | 2016-02-02 23:24:57 | [diff] [blame] | 141 | base::StringPrintf("%s.%s.Shown", kDownloadDangerPromptPrefix, |
| 142 | GetDangerTypeString(danger_type)), |
nparker | ac9da06 | 2016-05-19 21:47:23 | [diff] [blame] | 143 | file_type_uma_value); |
jialiul | 70cd6f2c | 2016-02-02 23:24:57 | [diff] [blame] | 144 | if (did_proceed) { |
Ilya Sherman | 982457e6 | 2017-12-13 02:19:36 | [diff] [blame] | 145 | base::UmaHistogramSparse( |
jialiul | 70cd6f2c | 2016-02-02 23:24:57 | [diff] [blame] | 146 | base::StringPrintf("%s.%s.Proceed", kDownloadDangerPromptPrefix, |
| 147 | GetDangerTypeString(danger_type)), |
nparker | ac9da06 | 2016-05-19 21:47:23 | [diff] [blame] | 148 | file_type_uma_value); |
jialiul | 70cd6f2c | 2016-02-02 23:24:57 | [diff] [blame] | 149 | } |
| 150 | } |