Commit 4f0c908c authored by mvrable@chromium.org's avatar mvrable@chromium.org

[Activity log] Generalize the whitelist for keeping arguments

Previously, we kept all arguments for only a selected set of API calls,
but preserved arguments for all DOM actions that were logged.  Change
the logic so that the whitelist can cover actions of all types, and make
the default to strip arguments for all types unless in the whitelist.

BUG=253368

Review URL: https://chromiumcodereview.appspot.com/23567022

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@222010 0039d316-1c4b-4281-b951-d872f2087c98
parent 436190ec
...@@ -123,16 +123,13 @@ void ActivityLogPolicy::Util::StripPrivacySensitiveFields( ...@@ -123,16 +123,13 @@ void ActivityLogPolicy::Util::StripPrivacySensitiveFields(
} }
// static // static
void ActivityLogPolicy::Util::StripArguments( void ActivityLogPolicy::Util::StripArguments(const ApiSet& api_whitelist,
const std::set<std::string>& api_whitelist, scoped_refptr<Action> action) {
scoped_refptr<Action> action) { if (api_whitelist.find(
if (action->action_type() != Action::ACTION_API_CALL && std::make_pair(action->action_type(), action->api_name())) ==
action->action_type() != Action::ACTION_API_EVENT && api_whitelist.end()) {
action->action_type() != Action::UNUSED_ACTION_API_BLOCKED)
return;
if (api_whitelist.find(action->api_name()) == api_whitelist.end())
action->set_args(scoped_ptr<ListValue>()); action->set_args(scoped_ptr<ListValue>());
}
} }
// static // static
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#ifndef CHROME_BROWSER_EXTENSIONS_ACTIVITY_LOG_ACTIVITY_LOG_POLICY_H_ #ifndef CHROME_BROWSER_EXTENSIONS_ACTIVITY_LOG_ACTIVITY_LOG_POLICY_H_
#define CHROME_BROWSER_EXTENSIONS_ACTIVITY_LOG_ACTIVITY_LOG_POLICY_H_ #define CHROME_BROWSER_EXTENSIONS_ACTIVITY_LOG_ACTIVITY_LOG_POLICY_H_
#include <map>
#include <set> #include <set>
#include <string> #include <string>
...@@ -104,6 +105,10 @@ class ActivityLogPolicy { ...@@ -104,6 +105,10 @@ class ActivityLogPolicy {
// these methods more convenient from within a policy, but they are public. // these methods more convenient from within a policy, but they are public.
class Util { class Util {
public: public:
// A collection of API calls, used to specify whitelists for argument
// filtering.
typedef std::set<std::pair<Action::ActionType, std::string> > ApiSet;
// Serialize a Value as a JSON string. Returns an empty string if value is // Serialize a Value as a JSON string. Returns an empty string if value is
// null. // null.
static std::string Serialize(const base::Value* value); static std::string Serialize(const base::Value* value);
...@@ -117,7 +122,7 @@ class ActivityLogPolicy { ...@@ -117,7 +122,7 @@ class ActivityLogPolicy {
// Strip arguments from most API actions, preserving actions only for a // Strip arguments from most API actions, preserving actions only for a
// whitelisted set. Modifies the Action object in-place. // whitelisted set. Modifies the Action object in-place.
static void StripArguments(const std::set<std::string>& api_whitelist, static void StripArguments(const ApiSet& api_whitelist,
scoped_refptr<Action> action); scoped_refptr<Action> action);
// Given a base day (timestamp at local midnight), computes the timestamp // Given a base day (timestamp at local midnight), computes the timestamp
......
...@@ -59,8 +59,9 @@ TEST_F(ActivityLogPolicyUtilTest, StripPrivacySensitiveWebRequest) { ...@@ -59,8 +59,9 @@ TEST_F(ActivityLogPolicyUtilTest, StripPrivacySensitiveWebRequest) {
// Test that argument values are stripped as appropriate. // Test that argument values are stripped as appropriate.
TEST_F(ActivityLogPolicyUtilTest, StripArguments) { TEST_F(ActivityLogPolicyUtilTest, StripArguments) {
std::set<std::string> whitelist; ActivityLogPolicy::Util::ApiSet whitelist;
whitelist.insert("tabs.executeScript"); whitelist.insert(
std::make_pair(Action::ACTION_API_CALL, "tabs.executeScript"));
// API is in whitelist; not stripped. // API is in whitelist; not stripped.
scoped_refptr<Action> action = scoped_refptr<Action> action =
...@@ -78,13 +79,6 @@ TEST_F(ActivityLogPolicyUtilTest, StripArguments) { ...@@ -78,13 +79,6 @@ TEST_F(ActivityLogPolicyUtilTest, StripArguments) {
action->mutable_args()->AppendString("woof"); action->mutable_args()->AppendString("woof");
ActivityLogPolicy::Util::StripArguments(whitelist, action); ActivityLogPolicy::Util::StripArguments(whitelist, action);
ASSERT_EQ("", ActivityLogPolicy::Util::Serialize(action->args())); ASSERT_EQ("", ActivityLogPolicy::Util::Serialize(action->args()));
// Not an API type: not stripped.
action = new Action(
"punky", base::Time::Now(), Action::ACTION_DOM_ACCESS, "tabs.create");
action->mutable_args()->AppendString("woof");
ActivityLogPolicy::Util::StripArguments(whitelist, action);
ASSERT_EQ("[\"woof\"]", ActivityLogPolicy::Util::Serialize(action->args()));
} }
// Test parsing of URLs serialized to strings. // Test parsing of URLs serialized to strings.
......
...@@ -46,6 +46,8 @@ using content::BrowserThread; ...@@ -46,6 +46,8 @@ using content::BrowserThread;
namespace { namespace {
using extensions::Action;
// Delay between cleaning passes (to delete old action records) through the // Delay between cleaning passes (to delete old action records) through the
// database. // database.
const int kCleaningDelayInHours = 12; const int kCleaningDelayInHours = 12;
...@@ -56,8 +58,19 @@ const int kCleaningDelayInHours = 12; ...@@ -56,8 +58,19 @@ const int kCleaningDelayInHours = 12;
// //
// TODO(mvrable): The contents of this whitelist should be reviewed and // TODO(mvrable): The contents of this whitelist should be reviewed and
// expanded as needed. // expanded as needed.
const char* kAlwaysLog[] = {"extension.connect", "extension.sendMessage", struct ApiList {
"tabs.executeScript", "tabs.insertCSS"}; Action::ActionType type;
const char* name;
};
const ApiList kAlwaysLog[] = {
{Action::ACTION_API_CALL, "extension.connect"},
{Action::ACTION_API_CALL, "extension.sendMessage"},
{Action::ACTION_API_CALL, "tabs.executeScript"},
{Action::ACTION_API_CALL, "tabs.insertCSS"},
{Action::ACTION_CONTENT_SCRIPT, ""},
{Action::ACTION_DOM_ACCESS, "XMLHttpRequest.open"},
};
// Columns in the main database table. See the file-level comment for a // Columns in the main database table. See the file-level comment for a
// discussion of how data is stored and the meanings of the _x columns. // discussion of how data is stored and the meanings of the _x columns.
...@@ -138,7 +151,8 @@ CountingPolicy::CountingPolicy(Profile* profile) ...@@ -138,7 +151,8 @@ CountingPolicy::CountingPolicy(Profile* profile)
url_table_("url_ids"), url_table_("url_ids"),
retention_time_(base::TimeDelta::FromHours(60)) { retention_time_(base::TimeDelta::FromHours(60)) {
for (size_t i = 0; i < arraysize(kAlwaysLog); i++) { for (size_t i = 0; i < arraysize(kAlwaysLog); i++) {
api_arg_whitelist_.insert(kAlwaysLog[i]); api_arg_whitelist_.insert(
std::make_pair(kAlwaysLog[i].type, kAlwaysLog[i].name));
} }
} }
......
...@@ -100,7 +100,7 @@ class CountingPolicy : public ActivityLogDatabasePolicy { ...@@ -100,7 +100,7 @@ class CountingPolicy : public ActivityLogDatabasePolicy {
bool CleanStringTables(sql::Connection* db); bool CleanStringTables(sql::Connection* db);
// API calls for which complete arguments should be logged. // API calls for which complete arguments should be logged.
std::set<std::string> api_arg_whitelist_; Util::ApiSet api_arg_whitelist_;
// Tables for mapping strings to integers for shrinking database storage // Tables for mapping strings to integers for shrinking database storage
// requirements. URLs are kept in a separate table from other strings to // requirements. URLs are kept in a separate table from other strings to
......
...@@ -191,7 +191,7 @@ class CountingPolicyTest : public testing::Test { ...@@ -191,7 +191,7 @@ class CountingPolicyTest : public testing::Test {
CheckAction(*actions->at(0), "punky", Action::ACTION_API_CALL, "brewster", CheckAction(*actions->at(0), "punky", Action::ACTION_API_CALL, "brewster",
"", "", "", "", 2); "", "", "", "", 2);
CheckAction(*actions->at(1), "punky", Action::ACTION_DOM_ACCESS, "lets", CheckAction(*actions->at(1), "punky", Action::ACTION_DOM_ACCESS, "lets",
"[\"vamoose\"]", "http://www.google.com/", "", "", 1); "", "http://www.google.com/", "", "", 1);
CheckAction(*actions->at(2), "punky", Action::ACTION_API_CALL, CheckAction(*actions->at(2), "punky", Action::ACTION_API_CALL,
"extension.sendMessage", "[\"not\",\"stripped\"]", "", "", "", "extension.sendMessage", "[\"not\",\"stripped\"]", "", "", "",
1); 1);
...@@ -201,7 +201,7 @@ class CountingPolicyTest : public testing::Test { ...@@ -201,7 +201,7 @@ class CountingPolicyTest : public testing::Test {
scoped_ptr<Action::ActionVector> actions) { scoped_ptr<Action::ActionVector> actions) {
ASSERT_EQ(2, static_cast<int>(actions->size())); ASSERT_EQ(2, static_cast<int>(actions->size()));
CheckAction(*actions->at(0), "punky", Action::ACTION_DOM_ACCESS, "lets", CheckAction(*actions->at(0), "punky", Action::ACTION_DOM_ACCESS, "lets",
"[\"vamoose\"]", "http://www.google.com/", "", "", 1); "", "http://www.google.com/", "", "", 1);
CheckAction(*actions->at(1), "punky", Action::ACTION_API_CALL, "brewster", CheckAction(*actions->at(1), "punky", Action::ACTION_API_CALL, "brewster",
"", "", "", "", 1); "", "", "", "", 1);
} }
...@@ -235,25 +235,25 @@ class CountingPolicyTest : public testing::Test { ...@@ -235,25 +235,25 @@ class CountingPolicyTest : public testing::Test {
static void AllURLsRemoved(scoped_ptr<Action::ActionVector> actions) { static void AllURLsRemoved(scoped_ptr<Action::ActionVector> actions) {
ASSERT_EQ(2, static_cast<int>(actions->size())); ASSERT_EQ(2, static_cast<int>(actions->size()));
CheckAction(*actions->at(0), "punky", Action::ACTION_DOM_ACCESS, "lets", CheckAction(*actions->at(0), "punky", Action::ACTION_DOM_ACCESS, "lets",
"[\"vamoose\"]", "", "", "", 1); "", "", "", "", 1);
CheckAction(*actions->at(1), "punky", Action::ACTION_DOM_ACCESS, "lets", CheckAction(*actions->at(1), "punky", Action::ACTION_DOM_ACCESS, "lets",
"[\"vamoose\"]", "", "", "", 1); "", "", "", "", 1);
} }
static void SomeURLsRemoved(scoped_ptr<Action::ActionVector> actions) { static void SomeURLsRemoved(scoped_ptr<Action::ActionVector> actions) {
// These will be in the vector in reverse time order. // These will be in the vector in reverse time order.
ASSERT_EQ(5, static_cast<int>(actions->size())); ASSERT_EQ(5, static_cast<int>(actions->size()));
CheckAction(*actions->at(0), "punky", Action::ACTION_DOM_ACCESS, "lets", CheckAction(*actions->at(0), "punky", Action::ACTION_DOM_ACCESS, "lets",
"[\"vamoose\"]", "http://www.google.com/", "Google", "", "http://www.google.com/", "Google",
"http://www.args-url.com/", 1); "http://www.args-url.com/", 1);
CheckAction(*actions->at(1), "punky", Action::ACTION_DOM_ACCESS, "lets", CheckAction(*actions->at(1), "punky", Action::ACTION_DOM_ACCESS, "lets",
"[\"vamoose\"]", "http://www.google.com/", "Google", "", 1); "", "http://www.google.com/", "Google", "", 1);
CheckAction(*actions->at(2), "punky", Action::ACTION_DOM_ACCESS, "lets", CheckAction(*actions->at(2), "punky", Action::ACTION_DOM_ACCESS, "lets",
"[\"vamoose\"]", "", "", "", 1); "", "", "", "", 1);
CheckAction(*actions->at(3), "punky", Action::ACTION_DOM_ACCESS, "lets", CheckAction(*actions->at(3), "punky", Action::ACTION_DOM_ACCESS, "lets",
"[\"vamoose\"]", "", "", "http://www.google.com/", 1); "", "", "", "http://www.google.com/", 1);
CheckAction(*actions->at(4), "punky", Action::ACTION_DOM_ACCESS, "lets", CheckAction(*actions->at(4), "punky", Action::ACTION_DOM_ACCESS, "lets",
"[\"vamoose\"]", "", "", "", 1); "", "", "", "", 1);
} }
static void CheckDuplicates(scoped_ptr<Action::ActionVector> actions) { static void CheckDuplicates(scoped_ptr<Action::ActionVector> actions) {
......
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