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

Side by Side Diff: chrome/common/safe_browsing/download_protection_util.cc

Issue 1230483005: [SafeBrowsing] Send pingbacks for additional file types. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@more-dangerous-files
Patch Set: Cleanup some file extension checks. Created 5 years, 5 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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 #include "chrome/common/safe_browsing/download_protection_util.h" 5 #include "chrome/common/safe_browsing/download_protection_util.h"
6 6
7 #include "base/files/file_path.h" 7 #include "base/files/file_path.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 9
10 namespace safe_browsing { 10 namespace safe_browsing {
11 namespace download_protection_util { 11 namespace download_protection_util {
12 12
13 bool IsArchiveFile(const base::FilePath& file) { 13 bool IsArchiveFile(const base::FilePath& file) {
14 // TODO(mattm): should .dmg be checked here instead of IsBinaryFile? 14 // TODO(mattm): should .dmg be checked here instead of IsBinaryFile?
15 return file.MatchesExtension(FILE_PATH_LITERAL(".zip")); 15 return file.MatchesExtension(FILE_PATH_LITERAL(".zip"));
16 } 16 }
17 17
18 bool IsBinaryFile(const base::FilePath& file) { 18 bool IsBinaryFile(const base::FilePath& file) {
19 return ( 19 const base::FilePath::CharType* kSupportedBinaryFileTypes[] = {
20 // Executable extensions for MS Windows. 20 // Executable extensions for MS Windows.
21 file.MatchesExtension(FILE_PATH_LITERAL(".bas")) || 21 FILE_PATH_LITERAL(".bas"), FILE_PATH_LITERAL(".bat"),
22 file.MatchesExtension(FILE_PATH_LITERAL(".bat")) || 22 FILE_PATH_LITERAL(".cab"), FILE_PATH_LITERAL(".cmd"),
23 file.MatchesExtension(FILE_PATH_LITERAL(".cab")) || 23 FILE_PATH_LITERAL(".com"), FILE_PATH_LITERAL(".exe"),
24 file.MatchesExtension(FILE_PATH_LITERAL(".cmd")) || 24 FILE_PATH_LITERAL(".hta"), FILE_PATH_LITERAL(".msi"),
25 file.MatchesExtension(FILE_PATH_LITERAL(".com")) || 25 FILE_PATH_LITERAL(".pif"), FILE_PATH_LITERAL(".reg"),
26 file.MatchesExtension(FILE_PATH_LITERAL(".exe")) || 26 FILE_PATH_LITERAL(".scr"), FILE_PATH_LITERAL(".url"),
27 file.MatchesExtension(FILE_PATH_LITERAL(".hta")) || 27 FILE_PATH_LITERAL(".vb"), FILE_PATH_LITERAL(".vbe"),
28 file.MatchesExtension(FILE_PATH_LITERAL(".msi")) || 28 FILE_PATH_LITERAL(".vbs"), FILE_PATH_LITERAL(".js"),
29 file.MatchesExtension(FILE_PATH_LITERAL(".pif")) || 29 FILE_PATH_LITERAL(".jse"), FILE_PATH_LITERAL(".website"),
30 file.MatchesExtension(FILE_PATH_LITERAL(".reg")) || 30 FILE_PATH_LITERAL(".mht"), FILE_PATH_LITERAL(".mhtml"),
moheeb1 2015/07/08 20:25:30 could you please also add .wsf (windows script fi
31 file.MatchesExtension(FILE_PATH_LITERAL(".scr")) ||
32 file.MatchesExtension(FILE_PATH_LITERAL(".url")) ||
33 file.MatchesExtension(FILE_PATH_LITERAL(".vb")) ||
34 file.MatchesExtension(FILE_PATH_LITERAL(".vbs")) ||
35 file.MatchesExtension(FILE_PATH_LITERAL(".website")) ||
36 // Chrome extensions and android APKs are also reported. 31 // Chrome extensions and android APKs are also reported.
37 file.MatchesExtension(FILE_PATH_LITERAL(".crx")) || 32 FILE_PATH_LITERAL(".crx"), FILE_PATH_LITERAL(".apk"),
38 file.MatchesExtension(FILE_PATH_LITERAL(".apk")) ||
39 // Mac extensions. 33 // Mac extensions.
40 file.MatchesExtension(FILE_PATH_LITERAL(".dmg")) || 34 FILE_PATH_LITERAL(".dmg"), FILE_PATH_LITERAL(".pkg"),
41 file.MatchesExtension(FILE_PATH_LITERAL(".pkg")) || 35 FILE_PATH_LITERAL(".osx"), FILE_PATH_LITERAL(".app"),
42 file.MatchesExtension(FILE_PATH_LITERAL(".osx")) || 36 };
43 file.MatchesExtension(FILE_PATH_LITERAL(".app")) || 37 for (const auto& extension : kSupportedBinaryFileTypes)
44 // Archives _may_ contain binaries, we'll check in ExtractFileFeatures. 38 if (file.MatchesExtension(extension))
45 IsArchiveFile(file)); 39 return true;
40
41 // Archives _may_ contain binaries, we'll check in ExtractFileFeatures.
42 return IsArchiveFile(file);
46 } 43 }
47 44
48 ClientDownloadRequest::DownloadType GetDownloadType( 45 ClientDownloadRequest::DownloadType GetDownloadType(
49 const base::FilePath& file) { 46 const base::FilePath& file) {
50 DCHECK(IsBinaryFile(file)); 47 DCHECK(IsBinaryFile(file));
51 if (file.MatchesExtension(FILE_PATH_LITERAL(".apk"))) 48 if (file.MatchesExtension(FILE_PATH_LITERAL(".apk")))
52 return ClientDownloadRequest::ANDROID_APK; 49 return ClientDownloadRequest::ANDROID_APK;
53 else if (file.MatchesExtension(FILE_PATH_LITERAL(".crx"))) 50 else if (file.MatchesExtension(FILE_PATH_LITERAL(".crx")))
54 return ClientDownloadRequest::CHROME_EXTENSION; 51 return ClientDownloadRequest::CHROME_EXTENSION;
55 // For zip files, we use the ZIPPED_EXECUTABLE type since we will only send 52 // For zip files, we use the ZIPPED_EXECUTABLE type since we will only send
56 // the pingback if we find an executable inside the zip archive. 53 // the pingback if we find an executable inside the zip archive.
57 else if (file.MatchesExtension(FILE_PATH_LITERAL(".zip"))) 54 else if (file.MatchesExtension(FILE_PATH_LITERAL(".zip")))
58 return ClientDownloadRequest::ZIPPED_EXECUTABLE; 55 return ClientDownloadRequest::ZIPPED_EXECUTABLE;
59 else if (file.MatchesExtension(FILE_PATH_LITERAL(".dmg")) || 56 else if (file.MatchesExtension(FILE_PATH_LITERAL(".dmg")) ||
60 file.MatchesExtension(FILE_PATH_LITERAL(".pkg")) || 57 file.MatchesExtension(FILE_PATH_LITERAL(".pkg")) ||
61 file.MatchesExtension(FILE_PATH_LITERAL(".osx")) || 58 file.MatchesExtension(FILE_PATH_LITERAL(".osx")) ||
62 file.MatchesExtension(FILE_PATH_LITERAL(".app"))) 59 file.MatchesExtension(FILE_PATH_LITERAL(".app")))
63 return ClientDownloadRequest::MAC_EXECUTABLE; 60 return ClientDownloadRequest::MAC_EXECUTABLE;
64 return ClientDownloadRequest::WIN_EXECUTABLE; 61 return ClientDownloadRequest::WIN_EXECUTABLE;
65 } 62 }
66 63
67 } // namespace download_protection_util 64 } // namespace download_protection_util
68 } // namespace safe_browsing 65 } // namespace safe_browsing
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698