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[] =
"interstitialEvent";
const char SafeBrowsingPrivateEventRouter::kKeySensitiveDataEvent[] =
"sensitiveDataEvent";
const char SafeBrowsingPrivateEventRouter::kKeyLargeUnscannedFileEvent[] =
"largeUnscannedFileEvent";
const char SafeBrowsingPrivateEventRouter::kKeyUnscannedFileEvent[] =
"unscannedFileEvent";
const char SafeBrowsingPrivateEventRouter::kTriggerFileDownload[] =
"FILE_DOWNLOAD";
......@@ -409,23 +409,25 @@ void SafeBrowsingPrivateEventRouter::OnSensitiveDataEvent(
GetProfileUserName(), mime_type, trigger, content_size));
}
void SafeBrowsingPrivateEventRouter::OnLargeUnscannedFileEvent(
void SafeBrowsingPrivateEventRouter::OnUnscannedFileEvent(
const GURL& url,
const std::string& file_name,
const std::string& download_digest_sha256,
const std::string& mime_type,
const std::string& trigger,
const std::string& reason,
const int64_t content_size) {
if (!IsRealtimeReportingEnabled())
return;
ReportRealtimeEvent(
kKeyLargeUnscannedFileEvent,
kKeyUnscannedFileEvent,
base::BindOnce(
[](const std::string& url, const std::string& file_name,
const std::string& download_digest_sha256,
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
// report it.
base::Value event(base::Value::Type::DICTIONARY);
......@@ -435,6 +437,7 @@ void SafeBrowsingPrivateEventRouter::OnLargeUnscannedFileEvent(
download_digest_sha256);
event.SetStringKey(kKeyProfileUserName, profile_user_name);
event.SetStringKey(kKeyContentType, mime_type);
event.SetStringKey(kKeyReason, reason);
// |content_size| can be set to -1 to indicate an unknown size, in
// which case the field is not set.
if (content_size >= 0)
......@@ -443,7 +446,7 @@ void SafeBrowsingPrivateEventRouter::OnLargeUnscannedFileEvent(
return event;
},
url.spec(), file_name, download_digest_sha256, GetProfileUserName(),
mime_type, trigger, content_size));
mime_type, trigger, reason, content_size));
}
void SafeBrowsingPrivateEventRouter::OnDangerousDownloadWarning(
......
......@@ -72,7 +72,7 @@ class SafeBrowsingPrivateEventRouter : public KeyedService {
static const char kKeyDangerousDownloadEvent[];
static const char kKeyInterstitialEvent[];
static const char kKeySensitiveDataEvent[];
static const char kKeyLargeUnscannedFileEvent[];
static const char kKeyUnscannedFileEvent[];
// String constants for the "trigger" event field.
static const char kTriggerFileDownload[];
......@@ -128,13 +128,14 @@ class SafeBrowsingPrivateEventRouter : public KeyedService {
const std::string& trigger,
const int64_t content_size);
// Notifies listeners that deep scanning failed, since the file was too large.
void OnLargeUnscannedFileEvent(const GURL& url,
const std::string& file_name,
const std::string& download_digest_sha256,
const std::string& mime_type,
const std::string& trigger,
const int64_t content_size);
// Notifies listeners that deep scanning failed, for the given |reason|.
void OnUnscannedFileEvent(const GURL& url,
const std::string& file_name,
const std::string& download_digest_sha256,
const std::string& mime_type,
const std::string& trigger,
const std::string& reason,
const int64_t content_size);
// Notifies listeners that the user saw a download warning.
// - |url| is the download URL
......
......@@ -136,8 +136,14 @@ void MaybeReportDeepScanningVerdict(Profile* profile,
DeepScanningClientResponse response) {
if (result == BinaryUploadService::Result::FILE_TOO_LARGE) {
extensions::SafeBrowsingPrivateEventRouterFactory::GetForProfile(profile)
->OnLargeUnscannedFileEvent(url, file_name, download_digest_sha256,
mime_type, trigger, content_size);
->OnUnscannedFileEvent(url, file_name, download_digest_sha256,
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)
......@@ -267,6 +273,8 @@ CheckClientDownloadRequest::CheckClientDownloadRequest(
item->GetFullPath(),
{item->GetTabUrl(), item->GetTabReferrerUrl()},
item->GetReceivedBytes(),
item->GetMimeType(),
item->GetHash(),
content::DownloadItemUtils::GetBrowserContext(item),
callback,
service,
......
......@@ -11,6 +11,8 @@
#include "base/rand_util.h"
#include "base/task/post_task.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/policy/chrome_browser_policy_connector.h"
#include "chrome/browser/profiles/profile.h"
......@@ -129,6 +131,8 @@ CheckClientDownloadRequestBase::CheckClientDownloadRequestBase(
base::FilePath full_path,
TabUrls tab_urls,
size_t file_size,
std::string mime_type,
std::string hash,
content::BrowserContext* browser_context,
CheckDownloadCallback callback,
DownloadProtectionService* service,
......@@ -144,7 +148,9 @@ CheckClientDownloadRequestBase::CheckClientDownloadRequestBase(
service_(service),
binary_feature_extractor_(std::move(binary_feature_extractor)),
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);
if (browser_context) {
......@@ -206,7 +212,17 @@ void CheckClientDownloadRequestBase::FinishRequest(
}
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;
reason = DownloadCheckResultReason::REASON_BLOCKED_PASSWORD_PROTECTED;
} else if (BinaryUploadService::ShouldBlockFileSize(file_size_)) {
......
......@@ -54,6 +54,8 @@ class CheckClientDownloadRequestBase {
base::FilePath full_path,
TabUrls tab_urls,
size_t file_size,
std::string mime_type,
std::string hash,
content::BrowserContext* browser_context,
CheckDownloadCallback callback,
DownloadProtectionService* service,
......@@ -216,6 +218,12 @@ class CheckClientDownloadRequestBase {
int file_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);
}; // namespace safe_browsing
......
......@@ -66,6 +66,8 @@ CheckNativeFileSystemWriteRequest::CheckNativeFileSystemWriteRequest(
item->full_path,
TabUrlsFromWebContents(item->web_contents),
item->size,
"application/octet-stream",
item->sha256_hash,
item->browser_context,
std::move(callback),
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