Commit cf74abc8 authored by Daniel Rubery's avatar Daniel Rubery Committed by Commit Bot

Extend the largeUnscannedFileEvent to a more generic unscannedFileEvent

This CL changes the structure of the reporting event for large unscanned
files. Future CLs will report this event with additional reasons.

Bug: 1014949
Change-Id: I8e75fd9c6bb55b09fd3b72553a636991d37d4b39
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1935488
Commit-Queue: Daniel Rubery <drubery@chromium.org>
Reviewed-by: default avatarRoger Tawa <rogerta@chromium.org>
Cr-Commit-Position: refs/heads/master@{#719452}
parent 98d44a05
...@@ -76,8 +76,8 @@ const char SafeBrowsingPrivateEventRouter::kKeyInterstitialEvent[] = ...@@ -76,8 +76,8 @@ const char SafeBrowsingPrivateEventRouter::kKeyInterstitialEvent[] =
"interstitialEvent"; "interstitialEvent";
const char SafeBrowsingPrivateEventRouter::kKeySensitiveDataEvent[] = const char SafeBrowsingPrivateEventRouter::kKeySensitiveDataEvent[] =
"sensitiveDataEvent"; "sensitiveDataEvent";
const char SafeBrowsingPrivateEventRouter::kKeyLargeUnscannedFileEvent[] = const char SafeBrowsingPrivateEventRouter::kKeyUnscannedFileEvent[] =
"largeUnscannedFileEvent"; "unscannedFileEvent";
const char SafeBrowsingPrivateEventRouter::kTriggerFileDownload[] = const char SafeBrowsingPrivateEventRouter::kTriggerFileDownload[] =
"FILE_DOWNLOAD"; "FILE_DOWNLOAD";
...@@ -409,23 +409,25 @@ void SafeBrowsingPrivateEventRouter::OnSensitiveDataEvent( ...@@ -409,23 +409,25 @@ void SafeBrowsingPrivateEventRouter::OnSensitiveDataEvent(
GetProfileUserName(), mime_type, trigger, content_size)); GetProfileUserName(), mime_type, trigger, content_size));
} }
void SafeBrowsingPrivateEventRouter::OnLargeUnscannedFileEvent( void SafeBrowsingPrivateEventRouter::OnUnscannedFileEvent(
const GURL& url, const GURL& url,
const std::string& file_name, const std::string& file_name,
const std::string& download_digest_sha256, const std::string& download_digest_sha256,
const std::string& mime_type, const std::string& mime_type,
const std::string& trigger, const std::string& trigger,
const std::string& reason,
const int64_t content_size) { const int64_t content_size) {
if (!IsRealtimeReportingEnabled()) if (!IsRealtimeReportingEnabled())
return; return;
ReportRealtimeEvent( ReportRealtimeEvent(
kKeyLargeUnscannedFileEvent, kKeyUnscannedFileEvent,
base::BindOnce( base::BindOnce(
[](const std::string& url, const std::string& file_name, [](const std::string& url, const std::string& file_name,
const std::string& download_digest_sha256, const std::string& download_digest_sha256,
const std::string& profile_user_name, const std::string& mime_type, const std::string& profile_user_name, const std::string& mime_type,
const std::string& trigger, const int64_t content_size) { const std::string& trigger, const std::string& reason,
const int64_t content_size) {
// Create a real-time event dictionary from the arguments and // Create a real-time event dictionary from the arguments and
// report it. // report it.
base::Value event(base::Value::Type::DICTIONARY); base::Value event(base::Value::Type::DICTIONARY);
...@@ -435,6 +437,7 @@ void SafeBrowsingPrivateEventRouter::OnLargeUnscannedFileEvent( ...@@ -435,6 +437,7 @@ void SafeBrowsingPrivateEventRouter::OnLargeUnscannedFileEvent(
download_digest_sha256); download_digest_sha256);
event.SetStringKey(kKeyProfileUserName, profile_user_name); event.SetStringKey(kKeyProfileUserName, profile_user_name);
event.SetStringKey(kKeyContentType, mime_type); event.SetStringKey(kKeyContentType, mime_type);
event.SetStringKey(kKeyReason, reason);
// |content_size| can be set to -1 to indicate an unknown size, in // |content_size| can be set to -1 to indicate an unknown size, in
// which case the field is not set. // which case the field is not set.
if (content_size >= 0) if (content_size >= 0)
...@@ -443,7 +446,7 @@ void SafeBrowsingPrivateEventRouter::OnLargeUnscannedFileEvent( ...@@ -443,7 +446,7 @@ void SafeBrowsingPrivateEventRouter::OnLargeUnscannedFileEvent(
return event; return event;
}, },
url.spec(), file_name, download_digest_sha256, GetProfileUserName(), url.spec(), file_name, download_digest_sha256, GetProfileUserName(),
mime_type, trigger, content_size)); mime_type, trigger, reason, content_size));
} }
void SafeBrowsingPrivateEventRouter::OnDangerousDownloadWarning( void SafeBrowsingPrivateEventRouter::OnDangerousDownloadWarning(
......
...@@ -72,7 +72,7 @@ class SafeBrowsingPrivateEventRouter : public KeyedService { ...@@ -72,7 +72,7 @@ class SafeBrowsingPrivateEventRouter : public KeyedService {
static const char kKeyDangerousDownloadEvent[]; static const char kKeyDangerousDownloadEvent[];
static const char kKeyInterstitialEvent[]; static const char kKeyInterstitialEvent[];
static const char kKeySensitiveDataEvent[]; static const char kKeySensitiveDataEvent[];
static const char kKeyLargeUnscannedFileEvent[]; static const char kKeyUnscannedFileEvent[];
// String constants for the "trigger" event field. // String constants for the "trigger" event field.
static const char kTriggerFileDownload[]; static const char kTriggerFileDownload[];
...@@ -128,13 +128,14 @@ class SafeBrowsingPrivateEventRouter : public KeyedService { ...@@ -128,13 +128,14 @@ class SafeBrowsingPrivateEventRouter : public KeyedService {
const std::string& trigger, const std::string& trigger,
const int64_t content_size); const int64_t content_size);
// Notifies listeners that deep scanning failed, since the file was too large. // Notifies listeners that deep scanning failed, for the given |reason|.
void OnLargeUnscannedFileEvent(const GURL& url, void OnUnscannedFileEvent(const GURL& url,
const std::string& file_name, const std::string& file_name,
const std::string& download_digest_sha256, const std::string& download_digest_sha256,
const std::string& mime_type, const std::string& mime_type,
const std::string& trigger, const std::string& trigger,
const int64_t content_size); const std::string& reason,
const int64_t content_size);
// Notifies listeners that the user saw a download warning. // Notifies listeners that the user saw a download warning.
// - |url| is the download URL // - |url| is the download URL
......
...@@ -136,8 +136,14 @@ void MaybeReportDeepScanningVerdict(Profile* profile, ...@@ -136,8 +136,14 @@ void MaybeReportDeepScanningVerdict(Profile* profile,
DeepScanningClientResponse response) { DeepScanningClientResponse response) {
if (result == BinaryUploadService::Result::FILE_TOO_LARGE) { if (result == BinaryUploadService::Result::FILE_TOO_LARGE) {
extensions::SafeBrowsingPrivateEventRouterFactory::GetForProfile(profile) extensions::SafeBrowsingPrivateEventRouterFactory::GetForProfile(profile)
->OnLargeUnscannedFileEvent(url, file_name, download_digest_sha256, ->OnUnscannedFileEvent(url, file_name, download_digest_sha256,
mime_type, trigger, content_size); mime_type, trigger, "fileTooLarge",
content_size);
} else if (result == BinaryUploadService::Result::TIMEOUT) {
extensions::SafeBrowsingPrivateEventRouterFactory::GetForProfile(profile)
->OnUnscannedFileEvent(url, file_name, download_digest_sha256,
mime_type, trigger, "scanTimedOut",
content_size);
} }
if (result != BinaryUploadService::Result::SUCCESS) if (result != BinaryUploadService::Result::SUCCESS)
...@@ -267,6 +273,8 @@ CheckClientDownloadRequest::CheckClientDownloadRequest( ...@@ -267,6 +273,8 @@ CheckClientDownloadRequest::CheckClientDownloadRequest(
item->GetFullPath(), item->GetFullPath(),
{item->GetTabUrl(), item->GetTabReferrerUrl()}, {item->GetTabUrl(), item->GetTabReferrerUrl()},
item->GetReceivedBytes(), item->GetReceivedBytes(),
item->GetMimeType(),
item->GetHash(),
content::DownloadItemUtils::GetBrowserContext(item), content::DownloadItemUtils::GetBrowserContext(item),
callback, callback,
service, service,
......
...@@ -11,6 +11,8 @@ ...@@ -11,6 +11,8 @@
#include "base/rand_util.h" #include "base/rand_util.h"
#include "base/task/post_task.h" #include "base/task/post_task.h"
#include "chrome/browser/browser_process.h" #include "chrome/browser/browser_process.h"
#include "chrome/browser/extensions/api/safe_browsing_private/safe_browsing_private_event_router.h"
#include "chrome/browser/extensions/api/safe_browsing_private/safe_browsing_private_event_router_factory.h"
#include "chrome/browser/history/history_service_factory.h" #include "chrome/browser/history/history_service_factory.h"
#include "chrome/browser/policy/chrome_browser_policy_connector.h" #include "chrome/browser/policy/chrome_browser_policy_connector.h"
#include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile.h"
...@@ -129,6 +131,8 @@ CheckClientDownloadRequestBase::CheckClientDownloadRequestBase( ...@@ -129,6 +131,8 @@ CheckClientDownloadRequestBase::CheckClientDownloadRequestBase(
base::FilePath full_path, base::FilePath full_path,
TabUrls tab_urls, TabUrls tab_urls,
size_t file_size, size_t file_size,
std::string mime_type,
std::string hash,
content::BrowserContext* browser_context, content::BrowserContext* browser_context,
CheckDownloadCallback callback, CheckDownloadCallback callback,
DownloadProtectionService* service, DownloadProtectionService* service,
...@@ -144,7 +148,9 @@ CheckClientDownloadRequestBase::CheckClientDownloadRequestBase( ...@@ -144,7 +148,9 @@ CheckClientDownloadRequestBase::CheckClientDownloadRequestBase(
service_(service), service_(service),
binary_feature_extractor_(std::move(binary_feature_extractor)), binary_feature_extractor_(std::move(binary_feature_extractor)),
database_manager_(std::move(database_manager)), database_manager_(std::move(database_manager)),
pingback_enabled_(service_->enabled()) { pingback_enabled_(service_->enabled()),
mime_type_(mime_type),
hash_(hash) {
DCHECK_CURRENTLY_ON(BrowserThread::UI); DCHECK_CURRENTLY_ON(BrowserThread::UI);
if (browser_context) { if (browser_context) {
...@@ -206,7 +212,17 @@ void CheckClientDownloadRequestBase::FinishRequest( ...@@ -206,7 +212,17 @@ void CheckClientDownloadRequestBase::FinishRequest(
} }
if (ShouldUploadBinary(reason)) { if (ShouldUploadBinary(reason)) {
if (!password_protected_allowed_ && is_password_protected_) { if (password_protected_allowed_ && is_password_protected_) {
Profile* profile = Profile::FromBrowserContext(GetBrowserContext());
extensions::SafeBrowsingPrivateEventRouterFactory::GetForProfile(profile)
->OnUnscannedFileEvent(
source_url_, target_file_path_.AsUTF8Unsafe(),
base::HexEncode(hash_.data(), hash_.size()), mime_type_,
extensions::SafeBrowsingPrivateEventRouter::kTriggerFileDownload,
"filePasswordProtected", file_size_);
}
if (is_password_protected_ && !password_protected_allowed_) {
result = DownloadCheckResult::BLOCKED_PASSWORD_PROTECTED; result = DownloadCheckResult::BLOCKED_PASSWORD_PROTECTED;
reason = DownloadCheckResultReason::REASON_BLOCKED_PASSWORD_PROTECTED; reason = DownloadCheckResultReason::REASON_BLOCKED_PASSWORD_PROTECTED;
} else if (BinaryUploadService::ShouldBlockFileSize(file_size_)) { } else if (BinaryUploadService::ShouldBlockFileSize(file_size_)) {
......
...@@ -54,6 +54,8 @@ class CheckClientDownloadRequestBase { ...@@ -54,6 +54,8 @@ class CheckClientDownloadRequestBase {
base::FilePath full_path, base::FilePath full_path,
TabUrls tab_urls, TabUrls tab_urls,
size_t file_size, size_t file_size,
std::string mime_type,
std::string hash,
content::BrowserContext* browser_context, content::BrowserContext* browser_context,
CheckDownloadCallback callback, CheckDownloadCallback callback,
DownloadProtectionService* service, DownloadProtectionService* service,
...@@ -216,6 +218,12 @@ class CheckClientDownloadRequestBase { ...@@ -216,6 +218,12 @@ class CheckClientDownloadRequestBase {
int file_count_; int file_count_;
int directory_count_; int directory_count_;
// The mime type of the download, if known.
std::string mime_type_;
// The hash of the download, if known.
std::string hash_;
DISALLOW_COPY_AND_ASSIGN(CheckClientDownloadRequestBase); DISALLOW_COPY_AND_ASSIGN(CheckClientDownloadRequestBase);
}; // namespace safe_browsing }; // namespace safe_browsing
......
...@@ -66,6 +66,8 @@ CheckNativeFileSystemWriteRequest::CheckNativeFileSystemWriteRequest( ...@@ -66,6 +66,8 @@ CheckNativeFileSystemWriteRequest::CheckNativeFileSystemWriteRequest(
item->full_path, item->full_path,
TabUrlsFromWebContents(item->web_contents), TabUrlsFromWebContents(item->web_contents),
item->size, item->size,
"application/octet-stream",
item->sha256_hash,
item->browser_context, item->browser_context,
std::move(callback), std::move(callback),
service, service,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment