summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--chrome/browser/download/download_util.cc29
-rw-r--r--chrome/browser/download/download_util_unittest.cc30
2 files changed, 14 insertions, 45 deletions
diff --git a/chrome/browser/download/download_util.cc b/chrome/browser/download/download_util.cc
index fdb2f22..4269fc9 100644
--- a/chrome/browser/download/download_util.cc
+++ b/chrome/browser/download/download_util.cc
@@ -127,46 +127,29 @@ bool DownloadPathIsDangerous(const FilePath& download_path) {
void GenerateExtension(const FilePath& file_name,
const std::string& mime_type,
FilePath::StringType* generated_extension) {
- // We're worried about three things here:
+ // We're worried about two things here:
//
- // 1) Security. Many sites let users upload content, such as buddy icons, to
- // their web sites. We want to mitigate the case where an attacker
- // supplies a malicious executable with an executable file extension but an
- // honest site serves the content with a benign content type, such as
- // image/jpeg.
- //
- // 2) Usability. If the site fails to provide a file extension, we want to
+ // 1) Usability. If the site fails to provide a file extension, we want to
// guess a reasonable file extension based on the content type.
//
- // 3) Shell integration. Some file extensions automatically integrate with
+ // 2) Shell integration. Some file extensions automatically integrate with
// the shell. We block these extensions to prevent a malicious web site
// from integrating with the user's shell.
- static const FilePath::CharType default_extension[] =
- FILE_PATH_LITERAL("download");
-
// See if our file name already contains an extension.
FilePath::StringType extension = file_name.Extension();
if (!extension.empty())
extension.erase(extension.begin()); // Erase preceding '.'.
#if defined(OS_WIN)
+ static const FilePath::CharType default_extension[] =
+ FILE_PATH_LITERAL("download");
+
// Rename shell-integrated extensions.
if (win_util::IsShellIntegratedExtension(extension))
extension.assign(default_extension);
#endif
- if (IsExecutableExtension(extension) && !IsExecutableMimeType(mime_type)) {
- // We want to be careful about executable extensions. The worry here is
- // that a trusted web site could be tricked into dropping an executable file
- // on the user's filesystem.
- if (!net::GetPreferredExtensionForMimeType(mime_type, &extension)) {
- // We couldn't find a good extension for this content type. Use a dummy
- // extension instead.
- extension.assign(default_extension);
- }
- }
-
if (extension.empty())
net::GetPreferredExtensionForMimeType(mime_type, &extension);
diff --git a/chrome/browser/download/download_util_unittest.cc b/chrome/browser/download/download_util_unittest.cc
index 823826e..1a905b1 100644
--- a/chrome/browser/download/download_util_unittest.cc
+++ b/chrome/browser/download/download_util_unittest.cc
@@ -100,32 +100,22 @@ const struct {
{"filename=evil.exe",
"http://www.goodguy.com/evil.exe",
"image/jpeg",
- L"evil.jpg"},
+ L"evil.exe"},
{"filename=ok.exe",
"http://www.goodguy.com/ok.exe",
"binary/octet-stream",
L"ok.exe"},
- {"filename=evil.exe.exe",
- "http://www.goodguy.com/evil.exe.exe",
+ {"filename=evil.dll",
+ "http://www.goodguy.com/evil.dll",
"dance/party",
- L"evil.exe.download"},
+ L"evil.dll"},
- {"filename=evil.exe",
- "http://www.goodguy.com/evil.exe",
- "application/xml",
- L"evil.xml"},
-
- {"filename=evil.exe",
- "http://www.goodguy.com/evil.exe",
- "application/html+xml",
- L"evil.download"},
-
- {"filename=evil.exe",
+ {"filename=evil",
"http://www.goodguy.com/evil.exe",
"application/rss+xml",
- L"evil.download"},
+ L"evil"},
// Test truncation of trailing dots and spaces
{"filename=evil.exe ",
@@ -512,7 +502,7 @@ const struct {
{ FILE_PATH_LITERAL("C:\\bar.html"),
"image/png",
- FILE_PATH_LITERAL("C:\\bar.png") },
+ FILE_PATH_LITERAL("C:\\bar.html") },
{ FILE_PATH_LITERAL("C:\\bar"),
"image/png",
FILE_PATH_LITERAL("C:\\bar.png") },
@@ -522,7 +512,7 @@ const struct {
FILE_PATH_LITERAL("C:\\foo\\bar.exe") },
{ FILE_PATH_LITERAL("C:\\foo\\bar.exe"),
"image/gif",
- FILE_PATH_LITERAL("C:\\foo\\bar.gif") },
+ FILE_PATH_LITERAL("C:\\foo\\bar.exe") },
{ FILE_PATH_LITERAL("C:\\foo\\google.com"),
"text/html",
@@ -554,11 +544,7 @@ const struct {
{ FILE_PATH_LITERAL("/foo/bar.exe"),
"image/gif",
-#if defined(OS_MACOSX)
FILE_PATH_LITERAL("/foo/bar.exe") },
-#else
- FILE_PATH_LITERAL("/foo/bar.gif") },
-#endif
{ FILE_PATH_LITERAL("/foo/google.com"),
"text/html",