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

Initial implementation of PhishGuard event log.

Add a PhishGuard event log to chrome://safe-browsing. Currently only
logs when triggered by on focus or password reuse events. Will add
further logged events in future CLs.

Screenshot: http://screen/YPyPv8CbirO

Bug: 849351
Change-Id: I7341b79685af1839584a165a7c1e3ee200947329
Reviewed-on: https://chromium-review.googlesource.com/1102665Reviewed-by: default avatarMikel Astiz <mastiz@chromium.org>
Reviewed-by: default avatarvitaliii <vitaliii@chromium.org>
Reviewed-by: default avatarVarun Khaneja <vakh@chromium.org>
Commit-Queue: Daniel Rubery <drubery@chromium.org>
Cr-Commit-Position: refs/heads/master@{#568544}
parent 629d0a97
......@@ -42,6 +42,7 @@
#include "components/safe_browsing/password_protection/password_protection_navigation_throttle.h"
#include "components/safe_browsing/password_protection/password_protection_request.h"
#include "components/safe_browsing/triggers/trigger_throttler.h"
#include "components/safe_browsing/web_ui/safe_browsing_ui.h"
#include "components/signin/core/browser/account_info.h"
#include "components/signin/core/browser/account_tracker_service.h"
#include "components/signin/core/browser/signin_manager.h"
......@@ -510,9 +511,6 @@ void ChromePasswordProtectionService::MaybeLogPasswordReuseDetectedEvent(
content::WebContents* web_contents) {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
if (!IsEventLoggingEnabled())
return;
syncer::UserEventService* user_event_service =
browser_sync::UserEventServiceFactory::GetForProfile(profile_);
if (!user_event_service)
......@@ -541,7 +539,11 @@ void ChromePasswordProtectionService::MaybeLogPasswordReuseDetectedEvent(
status->set_safe_browsing_reporting_population(SafeBrowsingStatus::SCOUT);
break;
}
user_event_service->RecordUserEvent(std::move(specifics));
WebUIInfoSingleton::GetInstance()->AddToPGEvents(*specifics);
if (IsEventLoggingEnabled())
user_event_service->RecordUserEvent(std::move(specifics));
}
void ChromePasswordProtectionService::LogPasswordReuseDialogInteraction(
......
......@@ -2,6 +2,7 @@ include_rules = [
"+components/data_use_measurement/core",
"+components/security_interstitials/content",
"+components/security_interstitials/core",
"+components/sync/protocol",
"+content/public/browser",
"+content/public/common",
"+google_apis",
......
......@@ -30,6 +30,7 @@ source_set("password_protection") {
"//components/safe_browsing/db:database_manager",
"//components/safe_browsing/db:v4_protocol_manager_util",
"//components/safe_browsing/db:whitelist_checker_client",
"//components/safe_browsing/web_ui:web_ui",
"//components/sessions",
"//content/public/browser:browser",
"//net:net",
......
......@@ -21,6 +21,7 @@ static_library("web_ui") {
"//components/safe_browsing/common:safe_browsing_prefs",
"//components/safe_browsing/db:v4_local_database_manager",
"//components/strings:components_strings_grit",
"//components/sync/protocol:protocol",
"//components/user_prefs:user_prefs",
"//content/public/browser",
"//net",
......
......@@ -39,6 +39,10 @@
<div class="content">
<p id="sent-client-download-requests-list"></p>
</div>
<h2>PhishGuard Events</h2>
<div class="content">
<p id="pg-event-log"></p>
</div>
<script src="chrome://resources/js/i18n_template.js"></script>
</body>
</html>
......@@ -39,6 +39,16 @@ cr.define('safe_browsing', function() {
cr.addWebUIListener('sent-csbrr-update', function(result) {
addSentCSBRRsInfo(result);
});
cr.sendWithPromise('getPGEvents', [])
.then(
(pgEvents) => {
pgEvents.forEach(function (pgEvent) {
addPGEvent(pgEvent);
})});
cr.addWebUIListener('sent-pg-event', function(result) {
addPGEvent(result);
});
}
function addExperiments(result) {
......@@ -88,6 +98,13 @@ cr.define('safe_browsing', function() {
appendChildWithInnerText(logDiv, result);
}
function addPGEvent(result) {
var logDiv = $('pg-event-log');
var eventFormatted = "[" + (new Date(result['time'])).toLocaleString() +
"] " + result['message'];
appendChildWithInnerText(logDiv, eventFormatted);
}
function appendChildWithInnerText(logDiv, text) {
if (!logDiv)
return;
......@@ -99,6 +116,7 @@ cr.define('safe_browsing', function() {
return {
addSentCSBRRsInfo: addSentCSBRRsInfo,
addSentClientDownloadRequestsInfo: addSentClientDownloadRequestsInfo,
addPGEvent: addPGEvent,
initialize: initialize,
};
});
......
......@@ -76,6 +76,21 @@ void WebUIInfoSingleton::ClearCSBRRsSent() {
csbrrs_sent_);
}
void WebUIInfoSingleton::AddToPGEvents(
const sync_pb::UserEventSpecifics& event) {
if (webui_instances_.empty())
return;
for (auto* webui_listener : webui_instances_)
webui_listener->NotifyPGEventJsListener(event);
pg_event_log_.push_back(event);
}
void WebUIInfoSingleton::ClearPGEvents() {
std::vector<sync_pb::UserEventSpecifics>().swap(pg_event_log_);
}
void WebUIInfoSingleton::RegisterWebUIInstance(SafeBrowsingUIHandler* webui) {
webui_instances_.push_back(webui);
}
......@@ -87,6 +102,7 @@ void WebUIInfoSingleton::UnregisterWebUIInstance(SafeBrowsingUIHandler* webui) {
if (webui_instances_.empty()) {
ClearCSBRRsSent();
ClearClientDownloadRequestsSent();
ClearPGEvents();
}
}
......@@ -322,6 +338,35 @@ std::string SerializeCSBRR(const ClientSafeBrowsingReportRequest& report) {
return report_request_serialized;
}
base::DictionaryValue SerializePGEvent(
const sync_pb::UserEventSpecifics& event) {
base::DictionaryValue result;
base::Time timestamp = base::Time::FromDeltaSinceWindowsEpoch(
base::TimeDelta::FromMicroseconds(event.event_time_usec()));
result.SetDouble("time", timestamp.ToJsTime());
base::DictionaryValue event_dict;
sync_pb::UserEventSpecifics::GaiaPasswordReuse reuse =
event.gaia_password_reuse_event();
if (reuse.has_reuse_detected()) {
event_dict.SetPath({"reuse_detected", "status", "enabled"},
base::Value(reuse.reuse_detected().status().enabled()));
event_dict.SetPath({"reuse_detected", "status", "reporting_population"},
base::Value(reuse.reuse_detected()
.status()
.safe_browsing_reporting_population()));
}
std::string event_serialized;
JSONStringValueSerializer serializer(&event_serialized);
serializer.set_pretty_print(true);
serializer.Serialize(event_dict);
result.SetString("message", event_serialized);
return result;
}
} // namespace
SafeBrowsingUI::SafeBrowsingUI(content::WebUI* web_ui)
......@@ -444,6 +489,21 @@ void SafeBrowsingUIHandler::GetSentCSBRRs(const base::ListValue* args) {
ResolveJavascriptCallback(base::Value(callback_id), sent_reports);
}
void SafeBrowsingUIHandler::GetPGEvents(const base::ListValue* args) {
const std::vector<sync_pb::UserEventSpecifics>& events =
WebUIInfoSingleton::GetInstance()->pg_event_log();
base::ListValue events_sent;
for (const sync_pb::UserEventSpecifics& event : events)
events_sent.GetList().push_back(SerializePGEvent(event));
AllowJavascript();
std::string callback_id;
args->GetString(0, &callback_id);
ResolveJavascriptCallback(base::Value(callback_id), events_sent);
}
void SafeBrowsingUIHandler::NotifyClientDownloadRequestJsListener(
ClientDownloadRequest* client_download_request) {
AllowJavascript();
......@@ -458,6 +518,12 @@ void SafeBrowsingUIHandler::NotifyCSBRRJsListener(
FireWebUIListener("sent-csbrr-update", base::Value(SerializeCSBRR(*csbrr)));
}
void SafeBrowsingUIHandler::NotifyPGEventJsListener(
const sync_pb::UserEventSpecifics& event) {
AllowJavascript();
FireWebUIListener("sent-pg-event", SerializePGEvent(event));
}
void SafeBrowsingUIHandler::RegisterMessages() {
web_ui()->RegisterMessageCallback(
"getExperiments",
......@@ -478,6 +544,9 @@ void SafeBrowsingUIHandler::RegisterMessages() {
"getSentCSBRRs",
base::BindRepeating(&SafeBrowsingUIHandler::GetSentCSBRRs,
base::Unretained(this)));
web_ui()->RegisterMessageCallback(
"getPGEvents", base::BindRepeating(&SafeBrowsingUIHandler::GetPGEvents,
base::Unretained(this)));
}
} // namespace safe_browsing
......@@ -8,6 +8,7 @@
#include "base/macros.h"
#include "components/safe_browsing/proto/csd.pb.h"
#include "components/safe_browsing/proto/webui.pb.h"
#include "components/sync/protocol/user_event_specifics.pb.h"
#include "content/public/browser/web_contents.h"
#include "content/public/browser/web_ui_controller.h"
#include "content/public/browser/web_ui_data_source.h"
......@@ -45,6 +46,10 @@ class SafeBrowsingUIHandler : public content::WebUIMessageHandler {
// open chrome://safe-browsing tab was opened.
void GetSentCSBRRs(const base::ListValue* args);
// Get the PhishGuard events that have been collected since the oldest
// currently open chrome://safe-browsing tab was opened.
void GetPGEvents(const base::ListValue* args);
// Register callbacks for WebUI messages.
void RegisterMessages() override;
......@@ -60,6 +65,10 @@ class SafeBrowsingUIHandler : public content::WebUIMessageHandler {
// sent, while one or more WebUI tabs are opened.
void NotifyCSBRRJsListener(ClientSafeBrowsingReportRequest* csbrr);
// Called when any new PhishGuard events are sent while one or more WebUI tabs
// are open.
void NotifyPGEventJsListener(const sync_pb::UserEventSpecifics& event);
content::BrowserContext* browser_context_;
// List that keeps all the WebUI listener objects.
static std::vector<SafeBrowsingUIHandler*> webui_list_;
......@@ -95,6 +104,13 @@ class WebUIInfoSingleton {
// Clear the list of the sent ClientSafeBrowsingReportRequest messages.
void ClearCSBRRsSent();
// Add the new message in |pg_event_log_| and send it to all the open
// chrome://safe-browsing tabs.
void AddToPGEvents(const sync_pb::UserEventSpecifics& event);
// Clear the list of sent PhishGuard events.
void ClearPGEvents();
// Register the new WebUI listener object.
void RegisterWebUIInstance(SafeBrowsingUIHandler* webui);
......@@ -121,6 +137,10 @@ class WebUIInfoSingleton {
return webui_instances_;
}
const std::vector<sync_pb::UserEventSpecifics>& pg_event_log() const {
return pg_event_log_;
}
private:
WebUIInfoSingleton();
~WebUIInfoSingleton();
......@@ -140,6 +160,10 @@ class WebUIInfoSingleton {
// functions that call AllowJavascript(), which is not marked const.
std::vector<std::unique_ptr<ClientSafeBrowsingReportRequest>> csbrrs_sent_;
// List of PhishGuard events sent since the oldest currently open
// chrome://safe-browsing tab was opened.
std::vector<sync_pb::UserEventSpecifics> pg_event_log_;
// List of WebUI listener objects. "SafeBrowsingUIHandler*" cannot be const,
// due to being used by functions that call AllowJavascript(), which is not
// marked const.
......
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