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

Side by Side Diff: chrome/browser/download/download_extensions.cc

Issue 1165893004: [Downloads] Prevent dangerous files from being opened automatically. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 6 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
« no previous file with comments | « chrome/browser/download/download_extensions.h ('k') | chrome/browser/download/download_prefs.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 <set> 5 #include <set>
6 #include <string> 6 #include <string>
7 7
8 #include "chrome/browser/download/download_extensions.h" 8 #include "chrome/browser/download/download_extensions.h"
9 9
10 #include "base/strings/string_util.h" 10 #include "base/strings/string_util.h"
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
50 * of those above. If you wish to allow use of your version of this file only 50 * of those above. If you wish to allow use of your version of this file only
51 * under the terms of either the GPL or the LGPL, and not to allow others to 51 * under the terms of either the GPL or the LGPL, and not to allow others to
52 * use your version of this file under the terms of the MPL, indicate your 52 * use your version of this file under the terms of the MPL, indicate your
53 * decision by deleting the provisions above and replace them with the notice 53 * decision by deleting the provisions above and replace them with the notice
54 * and other provisions required by the GPL or the LGPL. If you do not delete 54 * and other provisions required by the GPL or the LGPL. If you do not delete
55 * the provisions above, a recipient may use your version of this file under 55 * the provisions above, a recipient may use your version of this file under
56 * the terms of any one of the MPL, the GPL or the LGPL. 56 * the terms of any one of the MPL, the GPL or the LGPL.
57 * 57 *
58 * ***** END LICENSE BLOCK ***** */ 58 * ***** END LICENSE BLOCK ***** */
59 59
60 // When adding new entries to this list, also append the file extension to the 60 namespace {
61 // kDangerousFileTypes array in download_stats.cc. 61
62 static const struct Executables { 62 enum DownloadAutoOpenHint {
63 const char* extension; 63 ALLOW_AUTO_OPEN,
64 DownloadDangerLevel level; 64
65 } g_executables[] = { 65 // The file type should not be allowed to open automatically.
66 // Some files are dangerous on all platforms.
67 // 66 //
68 // Flash files downloaded locally can sometimes access the local filesystem. 67 // Criteria for disallowing a file type from opening automatically:
69 { "swf", DANGEROUS }, 68 //
70 { "spl", DANGEROUS }, 69 // Includes file types that upon opening may either:
71 // Chrome extensions should be obtained through the web store. 70 // * ... execute arbitrary or harmful code with user privileges.
72 { "crx", ALLOW_ON_USER_GESTURE }, 71 // * ... change configuration of the system to cause harmful behavior
72 // immediately or at some time in the future.
73 //
74 // Doesn't include file types that upon opening:
75 // * ... sufficiently warn the user about the fact that:
76 // - This file was downloaded from the internet.
77 // - Opening it can make specified changes to the system.
78 // (Note that any such warnings need to be displayed prior to the harmful
79 // logic being executed).
80 // * ... does nothing particularly dangerous, despite the act of downloading
81 // itself being dangerous (E.g. .local and .manifest files).
82 DISALLOW_AUTO_OPEN,
83 };
84
85 // Guidelines for adding a new dangerous file type:
86 //
87 // * Include a comment above the file type that:
88 // - Describes the file type.
89 // - Justifies why it is considered dangerous if this isn't obvious from the
90 // description.
91 // - Justifies why the file type is disallowed from auto opening, if
92 // necessary.
93 // * Add the file extension to the kDangerousFileTypes array in
94 // download_stats.cc.
95 //
96 // TODO(asanka): All file types listed below should have descriptions.
97 const struct FileType {
98 const char* extension; // Extension sans leading extension separator.
99 DownloadDangerLevel danger_level;
100 DownloadAutoOpenHint auto_open_hint;
101 } kDownloadFileTypes[] = {
102 // Some files are dangerous on all platforms.
103
104 // Flash files downloaded locally can sometimes access the local filesystem.
105 {"swf", DANGEROUS, DISALLOW_AUTO_OPEN},
106 {"spl", DANGEROUS, DISALLOW_AUTO_OPEN},
107
108 // Chrome extensions should be obtained through the web store. Allowed to
109 // open automatically because Chrome displays a prompt prior to
110 // installation.
111 {"crx", ALLOW_ON_USER_GESTURE, ALLOW_AUTO_OPEN},
73 112
74 // Windows, all file categories. 113 // Windows, all file categories.
75 #if defined(OS_WIN) 114 #if defined(OS_WIN)
76 { "ad", ALLOW_ON_USER_GESTURE }, 115 {"ad", ALLOW_ON_USER_GESTURE, ALLOW_AUTO_OPEN},
77 { "ade", ALLOW_ON_USER_GESTURE }, 116 {"ade", ALLOW_ON_USER_GESTURE, ALLOW_AUTO_OPEN},
78 { "adp", ALLOW_ON_USER_GESTURE }, 117 {"adp", ALLOW_ON_USER_GESTURE, ALLOW_AUTO_OPEN},
79 { "app", ALLOW_ON_USER_GESTURE }, 118 {"app", ALLOW_ON_USER_GESTURE, ALLOW_AUTO_OPEN},
80 { "application", ALLOW_ON_USER_GESTURE }, 119
81 { "asp", ALLOW_ON_USER_GESTURE }, 120 // Microsoft ClickOnce depolyment manifest. By default, opens with
82 { "asx", ALLOW_ON_USER_GESTURE }, 121 // dfshim.dll which should prompt the user before running untrusted code.
83 { "bas", ALLOW_ON_USER_GESTURE }, 122 {"application", ALLOW_ON_USER_GESTURE, ALLOW_AUTO_OPEN},
84 { "bat", ALLOW_ON_USER_GESTURE }, 123
85 { "cfg", DANGEROUS }, 124 // Active Server Pages source file.
86 { "chi", ALLOW_ON_USER_GESTURE }, 125 {"asp", ALLOW_ON_USER_GESTURE, ALLOW_AUTO_OPEN},
87 { "chm", ALLOW_ON_USER_GESTURE }, 126
88 { "cmd", ALLOW_ON_USER_GESTURE }, 127 // Advanced Stream Redirector. Contains a playlist of media files.
89 { "com", ALLOW_ON_USER_GESTURE }, 128 {"asx", ALLOW_ON_USER_GESTURE, ALLOW_AUTO_OPEN},
90 { "cpl", ALLOW_ON_USER_GESTURE }, 129
91 { "crt", ALLOW_ON_USER_GESTURE }, 130 // Microsoft Visual Basic source file. Opens by default in an editor.
92 { "dll", DANGEROUS }, 131 {"bas", ALLOW_ON_USER_GESTURE, ALLOW_AUTO_OPEN},
93 { "drv", DANGEROUS }, 132
94 { "exe", ALLOW_ON_USER_GESTURE }, 133 // Command script.
95 { "fxp", ALLOW_ON_USER_GESTURE }, 134 {"bat", ALLOW_ON_USER_GESTURE, DISALLOW_AUTO_OPEN},
96 { "grp", DANGEROUS }, 135
97 { "hlp", ALLOW_ON_USER_GESTURE }, 136 {"cfg", DANGEROUS, ALLOW_AUTO_OPEN},
98 { "hta", ALLOW_ON_USER_GESTURE }, 137
99 { "htt", ALLOW_ON_USER_GESTURE }, 138 // Windows Compiled HTML Help files.
100 { "inf", ALLOW_ON_USER_GESTURE }, 139 {"chi", ALLOW_ON_USER_GESTURE, ALLOW_AUTO_OPEN},
101 { "ini", DANGEROUS }, 140 {"chm", ALLOW_ON_USER_GESTURE, ALLOW_AUTO_OPEN},
102 { "ins", ALLOW_ON_USER_GESTURE }, 141
103 { "isp", ALLOW_ON_USER_GESTURE }, 142 // Command script.
104 { "js", ALLOW_ON_USER_GESTURE }, 143 {"cmd", ALLOW_ON_USER_GESTURE, DISALLOW_AUTO_OPEN},
105 { "jse", ALLOW_ON_USER_GESTURE }, 144
106 { "lnk", ALLOW_ON_USER_GESTURE }, 145 // Windows legacy executable.
107 { "local", DANGEROUS }, 146 {"com", ALLOW_ON_USER_GESTURE, DISALLOW_AUTO_OPEN},
108 { "mad", ALLOW_ON_USER_GESTURE }, 147
109 { "maf", ALLOW_ON_USER_GESTURE }, 148 // Control panel tool. Executable.
110 { "mag", ALLOW_ON_USER_GESTURE }, 149 {"cpl", ALLOW_ON_USER_GESTURE, DISALLOW_AUTO_OPEN},
111 { "mam", ALLOW_ON_USER_GESTURE }, 150
112 { "manifest", DANGEROUS }, 151 // Signed certificate file.
113 { "maq", ALLOW_ON_USER_GESTURE }, 152 {"crt", ALLOW_ON_USER_GESTURE, ALLOW_AUTO_OPEN},
114 { "mar", ALLOW_ON_USER_GESTURE }, 153
115 { "mas", ALLOW_ON_USER_GESTURE }, 154 // Windows executables.
116 { "mat", ALLOW_ON_USER_GESTURE }, 155 {"dll", DANGEROUS, DISALLOW_AUTO_OPEN},
117 { "mau", ALLOW_ON_USER_GESTURE }, 156 {"drv", DANGEROUS, DISALLOW_AUTO_OPEN},
118 { "mav", ALLOW_ON_USER_GESTURE }, 157 {"exe", ALLOW_ON_USER_GESTURE, DISALLOW_AUTO_OPEN},
119 { "maw", ALLOW_ON_USER_GESTURE }, 158
120 { "mda", ALLOW_ON_USER_GESTURE }, 159 {"fxp", ALLOW_ON_USER_GESTURE, ALLOW_AUTO_OPEN},
121 { "mdb", ALLOW_ON_USER_GESTURE }, 160 {"grp", DANGEROUS, ALLOW_AUTO_OPEN},
122 { "mde", ALLOW_ON_USER_GESTURE }, 161
123 { "mdt", ALLOW_ON_USER_GESTURE }, 162 // Windows legacy help file format.
124 { "mdw", ALLOW_ON_USER_GESTURE }, 163 {"hlp", ALLOW_ON_USER_GESTURE, ALLOW_AUTO_OPEN},
125 { "mdz", ALLOW_ON_USER_GESTURE }, 164
126 { "mht", ALLOW_ON_USER_GESTURE }, 165 // HTML Application. Executes as a fully trusted application.
127 { "mhtml", ALLOW_ON_USER_GESTURE }, 166 {"hta", ALLOW_ON_USER_GESTURE, DISALLOW_AUTO_OPEN},
128 { "mmc", ALLOW_ON_USER_GESTURE }, 167
129 { "mof", DANGEROUS }, 168 // Hypertext Template File. See https://support.microsoft.com/kb/181689.
130 { "msc", ALLOW_ON_USER_GESTURE }, 169 {"htt", ALLOW_ON_USER_GESTURE, DISALLOW_AUTO_OPEN},
131 { "msh", ALLOW_ON_USER_GESTURE }, 170
132 { "mshxml", ALLOW_ON_USER_GESTURE }, 171 // Device installation information.
133 { "msi", ALLOW_ON_USER_GESTURE }, 172 {"inf", ALLOW_ON_USER_GESTURE, DISALLOW_AUTO_OPEN},
134 { "msp", ALLOW_ON_USER_GESTURE }, 173
135 { "mst", ALLOW_ON_USER_GESTURE }, 174 // Generic configuration file.
136 { "ocx", DANGEROUS }, 175 {"ini", DANGEROUS, ALLOW_AUTO_OPEN},
137 { "ops", ALLOW_ON_USER_GESTURE }, 176
138 { "pcd", ALLOW_ON_USER_GESTURE }, 177 {"ins", ALLOW_ON_USER_GESTURE, ALLOW_AUTO_OPEN},
139 { "pif", ALLOW_ON_USER_GESTURE }, 178 {"isp", ALLOW_ON_USER_GESTURE, ALLOW_AUTO_OPEN},
140 { "plg", ALLOW_ON_USER_GESTURE }, 179
141 { "prf", ALLOW_ON_USER_GESTURE }, 180 // JavaScript file. May open using Windows Script Host with user level
142 { "prg", ALLOW_ON_USER_GESTURE }, 181 // privileges.
143 { "pst", ALLOW_ON_USER_GESTURE }, 182 {"js", ALLOW_ON_USER_GESTURE, DISALLOW_AUTO_OPEN},
144 { "reg", ALLOW_ON_USER_GESTURE }, 183 {"jse", ALLOW_ON_USER_GESTURE, DISALLOW_AUTO_OPEN},
145 { "scf", ALLOW_ON_USER_GESTURE }, 184
146 { "scr", ALLOW_ON_USER_GESTURE }, 185 // Shortcuts. May open anything.
147 { "sct", ALLOW_ON_USER_GESTURE }, 186 {"lnk", ALLOW_ON_USER_GESTURE, DISALLOW_AUTO_OPEN},
148 { "shb", ALLOW_ON_USER_GESTURE }, 187
149 { "shs", ALLOW_ON_USER_GESTURE }, 188 // .local files affect DLL search path for .exe file with same base name.
150 { "sys", DANGEROUS }, 189 {"local", DANGEROUS, ALLOW_AUTO_OPEN},
151 { "url", DANGEROUS }, 190
152 { "vb", ALLOW_ON_USER_GESTURE }, 191 {"mad", ALLOW_ON_USER_GESTURE, ALLOW_AUTO_OPEN},
153 { "vbe", ALLOW_ON_USER_GESTURE }, 192 {"maf", ALLOW_ON_USER_GESTURE, ALLOW_AUTO_OPEN},
154 { "vbs", ALLOW_ON_USER_GESTURE }, 193 {"mag", ALLOW_ON_USER_GESTURE, ALLOW_AUTO_OPEN},
155 { "vsd", ALLOW_ON_USER_GESTURE }, 194 {"mam", ALLOW_ON_USER_GESTURE, ALLOW_AUTO_OPEN},
156 { "vsmacros", ALLOW_ON_USER_GESTURE }, 195
157 { "vss", ALLOW_ON_USER_GESTURE }, 196 // While being a generic name, having a .manifest file with the same
158 { "vst", ALLOW_ON_USER_GESTURE }, 197 // basename as .exe file (foo.exe + foo.exe.manifest) changes the dll search
159 { "vsw", ALLOW_ON_USER_GESTURE }, 198 // order for the .exe file. Downloading this kind of file to the users'
160 { "website", DANGEROUS }, 199 // download directory is almost always the wrong thing to do.
161 { "ws", ALLOW_ON_USER_GESTURE }, 200 {"manifest", DANGEROUS, ALLOW_AUTO_OPEN},
162 { "wsc", ALLOW_ON_USER_GESTURE }, 201
163 { "wsf", ALLOW_ON_USER_GESTURE }, 202 {"maq", ALLOW_ON_USER_GESTURE, ALLOW_AUTO_OPEN},
164 { "wsh", ALLOW_ON_USER_GESTURE }, 203 {"mar", ALLOW_ON_USER_GESTURE, ALLOW_AUTO_OPEN},
165 { "xbap", DANGEROUS }, 204 {"mas", ALLOW_ON_USER_GESTURE, ALLOW_AUTO_OPEN},
205 {"mat", ALLOW_ON_USER_GESTURE, ALLOW_AUTO_OPEN},
206 {"mau", ALLOW_ON_USER_GESTURE, ALLOW_AUTO_OPEN},
207 {"mav", ALLOW_ON_USER_GESTURE, ALLOW_AUTO_OPEN},
208 {"maw", ALLOW_ON_USER_GESTURE, ALLOW_AUTO_OPEN},
209 {"mda", ALLOW_ON_USER_GESTURE, ALLOW_AUTO_OPEN},
210 {"mdb", ALLOW_ON_USER_GESTURE, ALLOW_AUTO_OPEN},
211 {"mde", ALLOW_ON_USER_GESTURE, ALLOW_AUTO_OPEN},
212 {"mdt", ALLOW_ON_USER_GESTURE, ALLOW_AUTO_OPEN},
213 {"mdw", ALLOW_ON_USER_GESTURE, ALLOW_AUTO_OPEN},
214 {"mdz", ALLOW_ON_USER_GESTURE, ALLOW_AUTO_OPEN},
215
216 // Multipart HTML.
217 {"mht", ALLOW_ON_USER_GESTURE, ALLOW_AUTO_OPEN},
218 {"mhtml", ALLOW_ON_USER_GESTURE, ALLOW_AUTO_OPEN},
219
220 {"mmc", ALLOW_ON_USER_GESTURE, ALLOW_AUTO_OPEN},
221 {"mof", DANGEROUS, ALLOW_AUTO_OPEN},
222
223 // Microsoft Management Console Snap-in. Contains executable code.
224 {"msc", ALLOW_ON_USER_GESTURE, DISALLOW_AUTO_OPEN},
225
226 {"msh", ALLOW_ON_USER_GESTURE, ALLOW_AUTO_OPEN},
227 {"mshxml", ALLOW_ON_USER_GESTURE, ALLOW_AUTO_OPEN},
228
229 // Windows Installer
230 {"msi", ALLOW_ON_USER_GESTURE, DISALLOW_AUTO_OPEN},
231 {"msp", ALLOW_ON_USER_GESTURE, DISALLOW_AUTO_OPEN},
232 {"mst", ALLOW_ON_USER_GESTURE, DISALLOW_AUTO_OPEN},
233
234 // ActiveX Control
235 {"ocx", DANGEROUS, ALLOW_AUTO_OPEN},
236
237 {"ops", ALLOW_ON_USER_GESTURE, ALLOW_AUTO_OPEN},
238 {"pcd", ALLOW_ON_USER_GESTURE, ALLOW_AUTO_OPEN},
239
240 // Program Information File. Originally intended to configure execution
241 // environment for legacy DOS files. They aren't meant to contain executable
242 // code. But Windows may execute a PIF file that is sniffed as a PE file.
243 {"pif", ALLOW_ON_USER_GESTURE, DISALLOW_AUTO_OPEN},
244
245 {"plg", ALLOW_ON_USER_GESTURE, ALLOW_AUTO_OPEN},
246 {"prf", ALLOW_ON_USER_GESTURE, ALLOW_AUTO_OPEN},
247 {"prg", ALLOW_ON_USER_GESTURE, ALLOW_AUTO_OPEN},
248 {"pst", ALLOW_ON_USER_GESTURE, ALLOW_AUTO_OPEN},
249
250 // Registry file. Opening may cause registry settings to change. Users still
251 // need to click through a prompt. So we could consider relaxing the
252 // DISALLOW_AUTO_OPEN restriction.
253 {"reg", ALLOW_ON_USER_GESTURE, DISALLOW_AUTO_OPEN},
254
255 {"scf", ALLOW_ON_USER_GESTURE, ALLOW_AUTO_OPEN},
256
257 // These are also executables.
258 {"scr", ALLOW_ON_USER_GESTURE, DISALLOW_AUTO_OPEN},
259
260 {"sct", ALLOW_ON_USER_GESTURE, ALLOW_AUTO_OPEN},
261 {"shb", ALLOW_ON_USER_GESTURE, ALLOW_AUTO_OPEN},
262 {"shs", ALLOW_ON_USER_GESTURE, ALLOW_AUTO_OPEN},
263
264 // System executable. Windows tries hard to prevent you from opening these
265 // types of files.
266 {"sys", DANGEROUS, DISALLOW_AUTO_OPEN},
267
268 // Internet Shortcut. See description for .website below.
269 {"url", DANGEROUS, DISALLOW_AUTO_OPEN},
270
271 {"vb", ALLOW_ON_USER_GESTURE, ALLOW_AUTO_OPEN},
272
273 // VBScript files. My open with Windows Script Host and execute with user
274 // privileges.
275 {"vbe", ALLOW_ON_USER_GESTURE, DISALLOW_AUTO_OPEN},
276 {"vbs", ALLOW_ON_USER_GESTURE, DISALLOW_AUTO_OPEN},
277
278 {"vsd", ALLOW_ON_USER_GESTURE, ALLOW_AUTO_OPEN},
279 {"vsmacros", ALLOW_ON_USER_GESTURE, ALLOW_AUTO_OPEN},
280 {"vss", ALLOW_ON_USER_GESTURE, ALLOW_AUTO_OPEN},
281 {"vst", ALLOW_ON_USER_GESTURE, ALLOW_AUTO_OPEN},
282 {"vsw", ALLOW_ON_USER_GESTURE, ALLOW_AUTO_OPEN},
283
284 // Internet Shortcut (new since IE9). Both .url and .website are .ini files
285 // that describe a shortcut that points to a URL. They can point at
286 // anything. Dropping a download of this type and opening it automatically
287 // can in effect sidestep origin restrictions etc.
288 {"website", DANGEROUS, DISALLOW_AUTO_OPEN},
289
290 // Windows Script Host related.
291 {"ws", ALLOW_ON_USER_GESTURE, DISALLOW_AUTO_OPEN},
292 {"wsc", ALLOW_ON_USER_GESTURE, DISALLOW_AUTO_OPEN},
293 {"wsf", ALLOW_ON_USER_GESTURE, DISALLOW_AUTO_OPEN},
294 {"wsh", ALLOW_ON_USER_GESTURE, DISALLOW_AUTO_OPEN},
295
296 // XAML Browser Application.
297 {"xbap", DANGEROUS, DISALLOW_AUTO_OPEN},
166 #endif // OS_WIN 298 #endif // OS_WIN
167 299
168 // Java. 300 // Java.
169 #if !defined(OS_CHROMEOS) 301 #if !defined(OS_CHROMEOS)
170 { "class", DANGEROUS }, 302 {"class", DANGEROUS, DISALLOW_AUTO_OPEN},
171 { "jar", DANGEROUS }, 303 {"jar", DANGEROUS, DISALLOW_AUTO_OPEN},
172 { "jnlp", DANGEROUS }, 304 {"jnlp", DANGEROUS, DISALLOW_AUTO_OPEN},
173 #endif 305 #endif
174 306
175 // Scripting languages. (Shells are handled below.) 307 // Scripting languages. (Shells are handled below.)
176 #if !defined(OS_CHROMEOS) && !defined(OS_ANDROID) 308 #if !defined(OS_CHROMEOS) && !defined(OS_ANDROID)
177 { "pl", ALLOW_ON_USER_GESTURE }, 309 {"pl", ALLOW_ON_USER_GESTURE, DISALLOW_AUTO_OPEN},
178 { "py", ALLOW_ON_USER_GESTURE }, 310 {"py", ALLOW_ON_USER_GESTURE, DISALLOW_AUTO_OPEN},
179 { "pyc", ALLOW_ON_USER_GESTURE }, 311 {"pyc", ALLOW_ON_USER_GESTURE, DISALLOW_AUTO_OPEN},
180 { "pyw", ALLOW_ON_USER_GESTURE }, 312 {"pyw", ALLOW_ON_USER_GESTURE, DISALLOW_AUTO_OPEN},
181 { "rb", ALLOW_ON_USER_GESTURE }, 313 {"rb", ALLOW_ON_USER_GESTURE, DISALLOW_AUTO_OPEN},
182 #endif 314 #endif
183 315
184 // Shell languages. (OS_ANDROID is OS_POSIX.) OS_WIN shells are handled above. 316 // Shell languages. (OS_ANDROID is OS_POSIX.) OS_WIN shells are handled above.
185 #if defined(OS_POSIX) 317 #if defined(OS_POSIX)
186 { "bash", ALLOW_ON_USER_GESTURE }, 318 {"bash", ALLOW_ON_USER_GESTURE, DISALLOW_AUTO_OPEN},
187 { "csh", ALLOW_ON_USER_GESTURE }, 319 {"csh", ALLOW_ON_USER_GESTURE, DISALLOW_AUTO_OPEN},
188 { "ksh", ALLOW_ON_USER_GESTURE }, 320 {"ksh", ALLOW_ON_USER_GESTURE, DISALLOW_AUTO_OPEN},
189 { "sh", ALLOW_ON_USER_GESTURE }, 321 {"sh", ALLOW_ON_USER_GESTURE, DISALLOW_AUTO_OPEN},
190 { "shar", ALLOW_ON_USER_GESTURE }, 322 {"shar", ALLOW_ON_USER_GESTURE, DISALLOW_AUTO_OPEN},
191 { "tcsh", ALLOW_ON_USER_GESTURE }, 323 {"tcsh", ALLOW_ON_USER_GESTURE, DISALLOW_AUTO_OPEN},
192 #endif 324 #endif
193 #if defined(OS_MACOSX) 325 #if defined(OS_MACOSX)
194 { "command", ALLOW_ON_USER_GESTURE }, 326 {"command", ALLOW_ON_USER_GESTURE, DISALLOW_AUTO_OPEN},
195 #endif 327 #endif
196 328
197 // Package management formats. OS_WIN package formats are handled above. 329 // Package management formats. OS_WIN package formats are handled above.
198 #if defined(OS_MACOSX) || defined(OS_LINUX) 330 #if defined(OS_MACOSX) || defined(OS_LINUX)
199 { "pkg", ALLOW_ON_USER_GESTURE }, 331 {"pkg", ALLOW_ON_USER_GESTURE, DISALLOW_AUTO_OPEN},
200 #endif 332 #endif
201 #if defined(OS_LINUX) 333 #if defined(OS_LINUX)
202 { "deb", ALLOW_ON_USER_GESTURE }, 334 {"deb", ALLOW_ON_USER_GESTURE, DISALLOW_AUTO_OPEN},
203 { "rpm", ALLOW_ON_USER_GESTURE }, 335 {"rpm", ALLOW_ON_USER_GESTURE, DISALLOW_AUTO_OPEN},
204 #endif 336 #endif
205 #if defined(OS_ANDROID) 337 #if defined(OS_ANDROID)
206 { "dex", ALLOW_ON_USER_GESTURE }, // Really an executable format. 338 {"dex", ALLOW_ON_USER_GESTURE, DISALLOW_AUTO_OPEN},
207 #endif 339 #endif
208 }; 340 };
209 341
210 DownloadDangerLevel GetFileDangerLevel(const base::FilePath& path) { 342 // FileType for files with an empty extension.
343 const FileType kEmptyFileType = {nullptr, NOT_DANGEROUS, DISALLOW_AUTO_OPEN};
344
345 // Default FileType for non-empty extensions that aren't in the list above.
346 const FileType kUnknownFileType = {nullptr, NOT_DANGEROUS, ALLOW_AUTO_OPEN};
347
348 const FileType& GetFileType(const base::FilePath& path) {
211 base::FilePath::StringType extension(path.FinalExtension()); 349 base::FilePath::StringType extension(path.FinalExtension());
212 if (extension.empty()) 350 if (extension.empty())
213 return NOT_DANGEROUS; 351 return kEmptyFileType;
214 if (!base::IsStringASCII(extension)) 352 if (!base::IsStringASCII(extension))
215 return NOT_DANGEROUS; 353 return kUnknownFileType;
216 #if defined(OS_WIN) 354 #if defined(OS_WIN)
217 std::string ascii_extension = base::UTF16ToASCII(extension); 355 std::string ascii_extension = base::UTF16ToASCII(extension);
218 #elif defined(OS_POSIX) 356 #elif defined(OS_POSIX)
219 std::string ascii_extension = extension; 357 std::string ascii_extension = extension;
220 #endif 358 #endif
221 359
222 // Strip out leading dot if it's still there 360 // Strip out leading dot if it's still there
223 if (ascii_extension[0] == base::FilePath::kExtensionSeparator) 361 if (ascii_extension[0] == base::FilePath::kExtensionSeparator)
224 ascii_extension.erase(0, 1); 362 ascii_extension.erase(0, 1);
225 363
226 for (size_t i = 0; i < arraysize(g_executables); ++i) { 364 for (const auto& file_type : kDownloadFileTypes) {
227 if (base::LowerCaseEqualsASCII(ascii_extension, g_executables[i].extension)) 365 if (base::LowerCaseEqualsASCII(ascii_extension, file_type.extension))
228 return g_executables[i].level; 366 return file_type;
229 } 367 }
230 return NOT_DANGEROUS; 368
369 return kUnknownFileType;
370 }
371
372 } // namespace
373
374 DownloadDangerLevel GetFileDangerLevel(const base::FilePath& path) {
375 return GetFileType(path).danger_level;
376 }
377
378 bool IsAllowedToOpenAutomatically(const base::FilePath& path) {
379 return GetFileType(path).auto_open_hint == ALLOW_AUTO_OPEN;
231 } 380 }
232 381
233 static const char* kExecutableWhiteList[] = { 382 static const char* kExecutableWhiteList[] = {
234 // JavaScript is just as powerful as EXE. 383 // JavaScript is just as powerful as EXE.
235 "text/javascript", 384 "text/javascript",
236 "text/javascript;version=*", 385 "text/javascript;version=*",
237 "text/html", 386 "text/html",
238 // Registry files can cause critical changes to the MS OS behavior. 387 // Registry files can cause critical changes to the MS OS behavior.
239 // Addition of this mimetype also addresses bug 7337. 388 // Addition of this mimetype also addresses bug 7337.
240 "text/x-registry", 389 "text/x-registry",
(...skipping 15 matching lines...) Expand all
256 return true; 405 return true;
257 } 406 }
258 for (size_t i = 0; i < arraysize(kExecutableBlackList); ++i) { 407 for (size_t i = 0; i < arraysize(kExecutableBlackList); ++i) {
259 if (net::MatchesMimeType(kExecutableBlackList[i], mime_type)) 408 if (net::MatchesMimeType(kExecutableBlackList[i], mime_type))
260 return false; 409 return false;
261 } 410 }
262 // We consider only other application types to be executable. 411 // We consider only other application types to be executable.
263 return net::MatchesMimeType("application/*", mime_type); 412 return net::MatchesMimeType("application/*", mime_type);
264 } 413 }
265 414
266
267 } // namespace download_util 415 } // namespace download_util
OLDNEW
« no previous file with comments | « chrome/browser/download/download_extensions.h ('k') | chrome/browser/download/download_prefs.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698