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

Side by Side Diff: chrome/browser/safe_browsing/safe_browsing_database.h

Issue 1643573002: Add a ModuleLoadAnalyzer which checks modules against a whitelist (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Only enable for extended reporting AND feature flag. Add unit test. Created 4 years, 10 months 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
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CHROME_BROWSER_SAFE_BROWSING_SAFE_BROWSING_DATABASE_H_ 5 #ifndef CHROME_BROWSER_SAFE_BROWSING_SAFE_BROWSING_DATABASE_H_
6 #define CHROME_BROWSER_SAFE_BROWSING_SAFE_BROWSING_DATABASE_H_ 6 #define CHROME_BROWSER_SAFE_BROWSING_SAFE_BROWSING_DATABASE_H_
7 7
8 #include <map> 8 #include <map>
9 #include <set> 9 #include <set>
10 #include <string> 10 #include <string>
(...skipping 24 matching lines...) Expand all
35 public: 35 public:
36 SafeBrowsingDatabaseFactory() { } 36 SafeBrowsingDatabaseFactory() { }
37 virtual ~SafeBrowsingDatabaseFactory() { } 37 virtual ~SafeBrowsingDatabaseFactory() { }
38 virtual SafeBrowsingDatabase* CreateSafeBrowsingDatabase( 38 virtual SafeBrowsingDatabase* CreateSafeBrowsingDatabase(
39 const scoped_refptr<base::SequencedTaskRunner>& db_task_runner, 39 const scoped_refptr<base::SequencedTaskRunner>& db_task_runner,
40 bool enable_download_protection, 40 bool enable_download_protection,
41 bool enable_client_side_whitelist, 41 bool enable_client_side_whitelist,
42 bool enable_download_whitelist, 42 bool enable_download_whitelist,
43 bool enable_extension_blacklist, 43 bool enable_extension_blacklist,
44 bool enable_ip_blacklist, 44 bool enable_ip_blacklist,
45 bool enable_unwanted_software_list) = 0; 45 bool enable_unwanted_software_list,
46 bool enable_module_whitelist) = 0;
46 47
47 private: 48 private:
48 DISALLOW_COPY_AND_ASSIGN(SafeBrowsingDatabaseFactory); 49 DISALLOW_COPY_AND_ASSIGN(SafeBrowsingDatabaseFactory);
49 }; 50 };
50 51
51 // Encapsulates on-disk databases that for safebrowsing. There are 52 // Encapsulates on-disk databases that for safebrowsing. There are
52 // four databases: browse, download, download whitelist and 53 // four databases: browse, download, download whitelist and
53 // client-side detection (csd) whitelist databases. The browse database contains 54 // client-side detection (csd) whitelist databases. The browse database contains
54 // information about phishing and malware urls. The download database contains 55 // information about phishing and malware urls. The download database contains
55 // URLs for bad binaries (e.g: those containing virus) and hash of 56 // URLs for bad binaries (e.g: those containing virus) and hash of
(...skipping 10 matching lines...) Expand all
66 // It is not thread safe. 67 // It is not thread safe.
67 // The browse list and off-domain inclusion whitelist are always on; 68 // The browse list and off-domain inclusion whitelist are always on;
68 // availability of other lists is controlled by the flags on this method. 69 // availability of other lists is controlled by the flags on this method.
69 static SafeBrowsingDatabase* Create( 70 static SafeBrowsingDatabase* Create(
70 const scoped_refptr<base::SequencedTaskRunner>& db_task_runner, 71 const scoped_refptr<base::SequencedTaskRunner>& db_task_runner,
71 bool enable_download_protection, 72 bool enable_download_protection,
72 bool enable_client_side_whitelist, 73 bool enable_client_side_whitelist,
73 bool enable_download_whitelist, 74 bool enable_download_whitelist,
74 bool enable_extension_blacklist, 75 bool enable_extension_blacklist,
75 bool enable_ip_blacklist, 76 bool enable_ip_blacklist,
76 bool enable_unwanted_software_list); 77 bool enable_unwanted_software_list,
78 bool enable_module_whitelist);
77 79
78 // Makes the passed |factory| the factory used to instantiate 80 // Makes the passed |factory| the factory used to instantiate
79 // a SafeBrowsingDatabase. This is used for tests. 81 // a SafeBrowsingDatabase. This is used for tests.
80 static void RegisterFactory(SafeBrowsingDatabaseFactory* factory) { 82 static void RegisterFactory(SafeBrowsingDatabaseFactory* factory) {
81 factory_ = factory; 83 factory_ = factory;
82 } 84 }
83 85
84 virtual ~SafeBrowsingDatabase(); 86 virtual ~SafeBrowsingDatabase();
85 87
86 // Initializes the database with the given filename. 88 // Initializes the database with the given filename.
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
151 // are considered to be trusted. The two methods below let you lookup the 153 // are considered to be trusted. The two methods below let you lookup the
152 // whitelist either for a URL or an arbitrary string. These methods will 154 // whitelist either for a URL or an arbitrary string. These methods will
153 // return false if no match is found and true otherwise. This function is safe 155 // return false if no match is found and true otherwise. This function is safe
154 // to call from any thread. 156 // to call from any thread.
155 virtual bool ContainsDownloadWhitelistedUrl(const GURL& url) = 0; 157 virtual bool ContainsDownloadWhitelistedUrl(const GURL& url) = 0;
156 virtual bool ContainsDownloadWhitelistedString(const std::string& str) = 0; 158 virtual bool ContainsDownloadWhitelistedString(const std::string& str) = 0;
157 159
158 // Returns true if |url| is on the off-domain inclusion whitelist. 160 // Returns true if |url| is on the off-domain inclusion whitelist.
159 virtual bool ContainsInclusionWhitelistedUrl(const GURL& url) = 0; 161 virtual bool ContainsInclusionWhitelistedUrl(const GURL& url) = 0;
160 162
163 // Returns true if the given module hash is in the module whitelist.
164 // Returns false otheriwse.
165 virtual bool ContainsModuleWhitelistedString(const std::string& str) = 0;
166
161 // Populates |prefix_hits| with any prefixes in |prefixes| that have matches 167 // Populates |prefix_hits| with any prefixes in |prefixes| that have matches
162 // in the database, returning true if there were any matches. 168 // in the database, returning true if there were any matches.
163 // 169 //
164 // This function can ONLY be accessed from the creation thread. 170 // This function can ONLY be accessed from the creation thread.
165 virtual bool ContainsExtensionPrefixes( 171 virtual bool ContainsExtensionPrefixes(
166 const std::vector<SBPrefix>& prefixes, 172 const std::vector<SBPrefix>& prefixes,
167 std::vector<SBPrefix>* prefix_hits) = 0; 173 std::vector<SBPrefix>* prefix_hits) = 0;
168 174
169 // Returns true iff the given IP is currently on the csd malware IP blacklist. 175 // Returns true iff the given IP is currently on the csd malware IP blacklist.
170 // This function is safe to call from any thread. 176 // This function is safe to call from any thread.
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
254 const base::FilePath& side_effect_free_whitelist_base_filename); 260 const base::FilePath& side_effect_free_whitelist_base_filename);
255 261
256 // Filename for the csd malware IP blacklist database. 262 // Filename for the csd malware IP blacklist database.
257 static base::FilePath IpBlacklistDBFilename( 263 static base::FilePath IpBlacklistDBFilename(
258 const base::FilePath& ip_blacklist_base_filename); 264 const base::FilePath& ip_blacklist_base_filename);
259 265
260 // Filename for the unwanted software blacklist database. 266 // Filename for the unwanted software blacklist database.
261 static base::FilePath UnwantedSoftwareDBFilename( 267 static base::FilePath UnwantedSoftwareDBFilename(
262 const base::FilePath& db_filename); 268 const base::FilePath& db_filename);
263 269
270 // Filename for the module whitelist database.
271 static base::FilePath ModuleWhitelistDBFilename(
272 const base::FilePath& db_filename);
273
264 // Get the prefixes matching the download |urls|. 274 // Get the prefixes matching the download |urls|.
265 static void GetDownloadUrlPrefixes(const std::vector<GURL>& urls, 275 static void GetDownloadUrlPrefixes(const std::vector<GURL>& urls,
266 std::vector<SBPrefix>* prefixes); 276 std::vector<SBPrefix>* prefixes);
267 277
268 // SafeBrowsing Database failure types for histogramming purposes. Explicitly 278 // SafeBrowsing Database failure types for histogramming purposes. Explicitly
269 // label new values and do not re-use old values. Also make sure to reflect 279 // label new values and do not re-use old values. Also make sure to reflect
270 // modifications made below in the SB2DatabaseFailure histogram enum. 280 // modifications made below in the SB2DatabaseFailure histogram enum.
271 enum FailureType { 281 enum FailureType {
272 FAILURE_DATABASE_CORRUPT = 0, 282 FAILURE_DATABASE_CORRUPT = 0,
273 FAILURE_DATABASE_CORRUPT_HANDLER = 1, 283 FAILURE_DATABASE_CORRUPT_HANDLER = 1,
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
326 // for which the store is initialized to NULL. 336 // for which the store is initialized to NULL.
327 SafeBrowsingDatabaseNew( 337 SafeBrowsingDatabaseNew(
328 const scoped_refptr<base::SequencedTaskRunner>& db_task_runner, 338 const scoped_refptr<base::SequencedTaskRunner>& db_task_runner,
329 SafeBrowsingStore* browse_store, 339 SafeBrowsingStore* browse_store,
330 SafeBrowsingStore* download_store, 340 SafeBrowsingStore* download_store,
331 SafeBrowsingStore* csd_whitelist_store, 341 SafeBrowsingStore* csd_whitelist_store,
332 SafeBrowsingStore* download_whitelist_store, 342 SafeBrowsingStore* download_whitelist_store,
333 SafeBrowsingStore* inclusion_whitelist_store, 343 SafeBrowsingStore* inclusion_whitelist_store,
334 SafeBrowsingStore* extension_blacklist_store, 344 SafeBrowsingStore* extension_blacklist_store,
335 SafeBrowsingStore* ip_blacklist_store, 345 SafeBrowsingStore* ip_blacklist_store,
336 SafeBrowsingStore* unwanted_software_store); 346 SafeBrowsingStore* unwanted_software_store,
347 SafeBrowsingStore* module_whitelist_store);
337 348
338 ~SafeBrowsingDatabaseNew() override; 349 ~SafeBrowsingDatabaseNew() override;
339 350
340 // Implement SafeBrowsingDatabase interface. 351 // Implement SafeBrowsingDatabase interface.
341 void Init(const base::FilePath& filename) override; 352 void Init(const base::FilePath& filename) override;
342 bool ResetDatabase() override; 353 bool ResetDatabase() override;
343 bool ContainsBrowseUrl(const GURL& url, 354 bool ContainsBrowseUrl(const GURL& url,
344 std::vector<SBPrefix>* prefix_hits, 355 std::vector<SBPrefix>* prefix_hits,
345 std::vector<SBFullHashResult>* cache_hits) override; 356 std::vector<SBFullHashResult>* cache_hits) override;
346 bool ContainsBrowseHashes(const std::vector<SBFullHash>& full_hashes, 357 bool ContainsBrowseHashes(const std::vector<SBFullHash>& full_hashes,
347 std::vector<SBPrefix>* prefix_hits, 358 std::vector<SBPrefix>* prefix_hits,
348 std::vector<SBFullHashResult>* cache_hits) override; 359 std::vector<SBFullHashResult>* cache_hits) override;
349 bool ContainsUnwantedSoftwareUrl( 360 bool ContainsUnwantedSoftwareUrl(
350 const GURL& url, 361 const GURL& url,
351 std::vector<SBPrefix>* prefix_hits, 362 std::vector<SBPrefix>* prefix_hits,
352 std::vector<SBFullHashResult>* cache_hits) override; 363 std::vector<SBFullHashResult>* cache_hits) override;
353 bool ContainsUnwantedSoftwareHashes( 364 bool ContainsUnwantedSoftwareHashes(
354 const std::vector<SBFullHash>& full_hashes, 365 const std::vector<SBFullHash>& full_hashes,
355 std::vector<SBPrefix>* prefix_hits, 366 std::vector<SBPrefix>* prefix_hits,
356 std::vector<SBFullHashResult>* cache_hits) override; 367 std::vector<SBFullHashResult>* cache_hits) override;
357 bool ContainsDownloadUrlPrefixes(const std::vector<SBPrefix>& prefixes, 368 bool ContainsDownloadUrlPrefixes(const std::vector<SBPrefix>& prefixes,
358 std::vector<SBPrefix>* prefix_hits) override; 369 std::vector<SBPrefix>* prefix_hits) override;
359 bool ContainsCsdWhitelistedUrl(const GURL& url) override; 370 bool ContainsCsdWhitelistedUrl(const GURL& url) override;
360 bool ContainsDownloadWhitelistedUrl(const GURL& url) override; 371 bool ContainsDownloadWhitelistedUrl(const GURL& url) override;
361 bool ContainsDownloadWhitelistedString(const std::string& str) override; 372 bool ContainsDownloadWhitelistedString(const std::string& str) override;
362 bool ContainsInclusionWhitelistedUrl(const GURL& url) override; 373 bool ContainsInclusionWhitelistedUrl(const GURL& url) override;
374 bool ContainsModuleWhitelistedString(const std::string& str) override;
363 bool ContainsExtensionPrefixes(const std::vector<SBPrefix>& prefixes, 375 bool ContainsExtensionPrefixes(const std::vector<SBPrefix>& prefixes,
364 std::vector<SBPrefix>* prefix_hits) override; 376 std::vector<SBPrefix>* prefix_hits) override;
365 bool ContainsMalwareIP(const std::string& ip_address) override; 377 bool ContainsMalwareIP(const std::string& ip_address) override;
366 bool UpdateStarted(std::vector<SBListChunkRanges>* lists) override; 378 bool UpdateStarted(std::vector<SBListChunkRanges>* lists) override;
367 void InsertChunks( 379 void InsertChunks(
368 const std::string& list_name, 380 const std::string& list_name,
369 const std::vector<scoped_ptr<SBChunkData>>& chunks) override; 381 const std::vector<scoped_ptr<SBChunkData>>& chunks) override;
370 void DeleteChunks(const std::vector<SBChunkDelete>& chunk_deletes) override; 382 void DeleteChunks(const std::vector<SBChunkDelete>& chunk_deletes) override;
371 void UpdateFinished(bool update_succeeded) override; 383 void UpdateFinished(bool update_succeeded) override;
372 void CacheHashResults(const std::vector<SBPrefix>& prefixes, 384 void CacheHashResults(const std::vector<SBPrefix>& prefixes,
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
411 class ThreadSafeStateManager { 423 class ThreadSafeStateManager {
412 public: 424 public:
413 // Identifiers for stores held by the ThreadSafeStateManager. Allows helper 425 // Identifiers for stores held by the ThreadSafeStateManager. Allows helper
414 // methods to start a transaction themselves and keep it as short as 426 // methods to start a transaction themselves and keep it as short as
415 // possible rather than force callers to start the transaction early to pass 427 // possible rather than force callers to start the transaction early to pass
416 // a store pointer to the said helper methods. 428 // a store pointer to the said helper methods.
417 enum class SBWhitelistId { 429 enum class SBWhitelistId {
418 CSD, 430 CSD,
419 DOWNLOAD, 431 DOWNLOAD,
420 INCLUSION, 432 INCLUSION,
433 MODULE,
421 }; 434 };
422 enum class PrefixSetId { 435 enum class PrefixSetId {
423 BROWSE, 436 BROWSE,
424 UNWANTED_SOFTWARE, 437 UNWANTED_SOFTWARE,
425 }; 438 };
426 439
427 // Obtained through BeginReadTransaction(NoLockOnMainTaskRunner)?(): a 440 // Obtained through BeginReadTransaction(NoLockOnMainTaskRunner)?(): a
428 // ReadTransaction allows read-only observations of the 441 // ReadTransaction allows read-only observations of the
429 // ThreadSafeStateManager's state. The |prefix_gethash_cache_| has a special 442 // ThreadSafeStateManager's state. The |prefix_gethash_cache_| has a special
430 // allowance to be writable from a ReadTransaction but can't benefit from 443 // allowance to be writable from a ReadTransaction but can't benefit from
(...skipping 20 matching lines...) Expand all
451 // The sequenced task runner for this object, used to verify that its state 464 // The sequenced task runner for this object, used to verify that its state
452 // is only ever accessed from the runner. 465 // is only ever accessed from the runner.
453 scoped_refptr<const base::SequencedTaskRunner> db_task_runner_; 466 scoped_refptr<const base::SequencedTaskRunner> db_task_runner_;
454 467
455 // Lock for protecting access to this class' state. 468 // Lock for protecting access to this class' state.
456 mutable base::Lock lock_; 469 mutable base::Lock lock_;
457 470
458 SBWhitelist csd_whitelist_; 471 SBWhitelist csd_whitelist_;
459 SBWhitelist download_whitelist_; 472 SBWhitelist download_whitelist_;
460 SBWhitelist inclusion_whitelist_; 473 SBWhitelist inclusion_whitelist_;
474 SBWhitelist module_whitelist_;
461 475
462 // The IP blacklist should be small. At most a couple hundred IPs. 476 // The IP blacklist should be small. At most a couple hundred IPs.
463 IPBlacklist ip_blacklist_; 477 IPBlacklist ip_blacklist_;
464 478
465 // PrefixSets to speed up lookups for particularly large lists. The 479 // PrefixSets to speed up lookups for particularly large lists. The
466 // PrefixSet themselves are never modified, instead a new one is swapped in 480 // PrefixSet themselves are never modified, instead a new one is swapped in
467 // on update. 481 // on update.
468 scoped_ptr<const PrefixSet> browse_prefix_set_; 482 scoped_ptr<const PrefixSet> browse_prefix_set_;
469 scoped_ptr<const PrefixSet> unwanted_software_prefix_set_; 483 scoped_ptr<const PrefixSet> unwanted_software_prefix_set_;
470 484
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after
674 // whitelist chunks and full-length hashes. This list only contains 256 688 // whitelist chunks and full-length hashes. This list only contains 256
675 // bit hashes. 689 // bit hashes.
676 // - |download_whitelist_store_|: For the download whitelist chunks and 690 // - |download_whitelist_store_|: For the download whitelist chunks and
677 // full-length hashes. This list only contains 256 bit hashes. 691 // full-length hashes. This list only contains 256 bit hashes.
678 // - |inclusion_whitelist_store_|: For the inclusion whitelist. Same format 692 // - |inclusion_whitelist_store_|: For the inclusion whitelist. Same format
679 // as |download_whitelist_store_|. 693 // as |download_whitelist_store_|.
680 // - |extension_blacklist_store_|: For extension IDs. 694 // - |extension_blacklist_store_|: For extension IDs.
681 // - |ip_blacklist_store_|: For IP blacklist. 695 // - |ip_blacklist_store_|: For IP blacklist.
682 // - |unwanted_software_store_|: For unwanted software list (format 696 // - |unwanted_software_store_|: For unwanted software list (format
683 // identical to browsing lists). 697 // identical to browsing lists).
698 // - |module_whitelist_store_|: For module whitelist. This list only
699 // contains 256 bit hashes.
684 // 700 //
685 // The stores themselves will be modified throughout the existence of this 701 // The stores themselves will be modified throughout the existence of this
686 // database, but shouldn't ever be swapped out (hence the const scoped_ptr -- 702 // database, but shouldn't ever be swapped out (hence the const scoped_ptr --
687 // which could be swapped for C++11's std::optional when that's available). 703 // which could be swapped for C++11's std::optional when that's available).
688 // They are NonThreadSafe and should thus only be accessed on the database's 704 // They are NonThreadSafe and should thus only be accessed on the database's
689 // main thread as enforced by SafeBrowsingStoreFile's implementation. 705 // main thread as enforced by SafeBrowsingStoreFile's implementation.
690 const scoped_ptr<SafeBrowsingStore> browse_store_; 706 const scoped_ptr<SafeBrowsingStore> browse_store_;
691 const scoped_ptr<SafeBrowsingStore> download_store_; 707 const scoped_ptr<SafeBrowsingStore> download_store_;
692 const scoped_ptr<SafeBrowsingStore> csd_whitelist_store_; 708 const scoped_ptr<SafeBrowsingStore> csd_whitelist_store_;
693 const scoped_ptr<SafeBrowsingStore> download_whitelist_store_; 709 const scoped_ptr<SafeBrowsingStore> download_whitelist_store_;
694 const scoped_ptr<SafeBrowsingStore> inclusion_whitelist_store_; 710 const scoped_ptr<SafeBrowsingStore> inclusion_whitelist_store_;
695 const scoped_ptr<SafeBrowsingStore> extension_blacklist_store_; 711 const scoped_ptr<SafeBrowsingStore> extension_blacklist_store_;
696 const scoped_ptr<SafeBrowsingStore> ip_blacklist_store_; 712 const scoped_ptr<SafeBrowsingStore> ip_blacklist_store_;
697 const scoped_ptr<SafeBrowsingStore> unwanted_software_store_; 713 const scoped_ptr<SafeBrowsingStore> unwanted_software_store_;
714 const scoped_ptr<SafeBrowsingStore> module_whitelist_store_;
698 715
699 // Used to schedule resetting the database because of corruption. This factory 716 // Used to schedule resetting the database because of corruption. This factory
700 // and the WeakPtrs it issues should only be used on the database's main 717 // and the WeakPtrs it issues should only be used on the database's main
701 // thread. 718 // thread.
702 base::WeakPtrFactory<SafeBrowsingDatabaseNew> reset_factory_; 719 base::WeakPtrFactory<SafeBrowsingDatabaseNew> reset_factory_;
703 }; 720 };
704 721
705 } // namespace safe_browsing 722 } // namespace safe_browsing
706 723
707 #endif // CHROME_BROWSER_SAFE_BROWSING_SAFE_BROWSING_DATABASE_H_ 724 #endif // CHROME_BROWSER_SAFE_BROWSING_SAFE_BROWSING_DATABASE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698