Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(339)

Side by Side Diff: chrome/browser/safe_browsing/unverified_download_field_trial.cc

Issue 1409003002: [SafeBrowsing] Block dangerous unchecked downloads based on a Finch trial. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2015 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/safe_browsing/unverified_download_field_trial.h"
6
7 #include "base/command_line.h"
8 #include "base/files/file_path.h"
9 #include "base/metrics/field_trial.h"
10 #include "base/metrics/histogram.h"
11 #include "base/strings/string_split.h"
12 #include "base/strings/utf_string_conversions.h"
13 #include "chrome/common/chrome_switches.h"
14 #include "chrome/common/safe_browsing/download_protection_util.h"
15 #include "components/variations/variations_associated_data.h"
16
17 namespace safe_browsing {
18
19 const char kUnverifiedDownloadFieldTrialName[] =
20 "SafeBrowsingUnverifiedDownloads";
21
22 const char kUnverifiedDownloadFieldTrialDisableAll[] = "DisableAll";
23 const char kUnverifiedDownloadFieldTrialDisableByParameter[] =
24 "DisableByParameter";
25 const char kUnverifiedDownloadFieldTrialDisableSBTypesAndByParameter[] =
26 "DisableSBTypesAndByParameter";
27
28 const char kUnverifiedDownloadFieldTrialWhitelistParam[] = "whitelist";
29 const char kUnverifiedDownloadFieldTrialBlacklistParam[] = "blacklist";
30
31 namespace {
32
33 bool MatchesExtensionList(const base::FilePath& needle,
34 const std::string& haystack) {
35 #if defined(OS_WIN)
36 const base::FilePath::StringType comma_separated_extensions =
37 base::UTF8ToUTF16(haystack);
38 #else
39 const base::FilePath::StringType& comma_separated_extensions = haystack;
40 #endif
41 std::vector<base::FilePath::StringPieceType> extension_list =
42 base::SplitStringPiece(comma_separated_extensions, FILE_PATH_LITERAL(","),
43 base::TRIM_WHITESPACE, base::SPLIT_WANT_NONEMPTY);
44 for (const auto& extension : extension_list) {
45 // This shouldn't happen, but check anyway in case the parameter is
46 // accidentally malformed. The underlying FilePath implementation expects
47 // the extension to begin with an extension separator.
48 if (extension.size() == 0 ||
49 extension[0] != base::FilePath::kExtensionSeparator)
50 continue;
51 if (needle.MatchesExtension(extension))
52 return true;
53 }
54 return false;
55 }
56
57 } // namespace
58
59 bool IsUnverifiedDownloadAllowedByFieldTrial(const base::FilePath& file) {
60 std::string group_name =
61 base::FieldTrialList::FindFullName(kUnverifiedDownloadFieldTrialName);
62
63 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
64 switches::kAllowUncheckedDangerousDownloads))
65 return true;
66
67 if (group_name == kUnverifiedDownloadFieldTrialDisableAll)
68 return false;
69
70 if (group_name == kUnverifiedDownloadFieldTrialDisableByParameter ||
71 group_name == kUnverifiedDownloadFieldTrialDisableSBTypesAndByParameter) {
72 std::map<std::string, std::string> parameters;
73 variations::GetVariationParams(kUnverifiedDownloadFieldTrialName,
74 &parameters);
75
76 if (parameters.count(kUnverifiedDownloadFieldTrialBlacklistParam) &&
77 MatchesExtensionList(
78 file, parameters[kUnverifiedDownloadFieldTrialBlacklistParam]))
79 return false;
80
81 if (parameters.count(kUnverifiedDownloadFieldTrialWhitelistParam) &&
82 MatchesExtensionList(
83 file, parameters[kUnverifiedDownloadFieldTrialWhitelistParam]))
84 return true;
85 }
86
87 if (group_name == kUnverifiedDownloadFieldTrialDisableSBTypesAndByParameter ||
88 base::CommandLine::ForCurrentProcess()->HasSwitch(
89 switches::kDisallowUncheckedDangerousDownloads))
90 return !download_protection_util::IsSupportedBinaryFile(file);
91
92 return true;
93 }
94
95 } // namespace safe_browsing
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698