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

Side by Side Diff: content/browser/download/save_package.cc

Issue 2060923002: Neutralize dangerous subresource files during Save Page. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@save-package-cleanup-1
Patch Set: Add a DCHECK to verify that sanitization doesn't affect containing directory. Created 4 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
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 "content/browser/download/save_package.h" 5 #include "content/browser/download/save_package.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 431 matching lines...) Expand 10 before | Expand all | Expand 10 after
442 // TODO(jungshik): Figure out the referrer charset when having one 442 // TODO(jungshik): Figure out the referrer charset when having one
443 // makes sense and pass it to GenerateFileName. 443 // makes sense and pass it to GenerateFileName.
444 base::FilePath file_path = net::GenerateFileName(url, 444 base::FilePath file_path = net::GenerateFileName(url,
445 disposition, 445 disposition,
446 std::string(), 446 std::string(),
447 std::string(), 447 std::string(),
448 std::string(), 448 std::string(),
449 kDefaultSaveName); 449 kDefaultSaveName);
450 450
451 DCHECK(!file_path.empty()); 451 DCHECK(!file_path.empty());
452 if (need_html_ext)
453 file_path = file_path.ReplaceExtension(kDefaultHtmlExtension);
Nathan Parker 2016/06/13 21:15:00 Does this remove the existing extension? Might th
asanka 2016/06/14 21:24:07 Indeed. Now using .AddExtension() instead.
454
455 download_manager_->GetDelegate()->SanitizeSaveItemFilename(&file_path);
456
457 DCHECK_EQ(file_path.DirName().value(), base::FilePath::kCurrentDirectory)
458 << "Sanitization shouldn't change containing directory";
459
452 base::FilePath::StringType base_name = 460 base::FilePath::StringType base_name =
453 file_path.RemoveExtension().BaseName().value(); 461 file_path.RemoveExtension().BaseName().value();
454 base::FilePath::StringType file_name_ext = file_path.Extension(); 462 base::FilePath::StringType file_name_ext = file_path.Extension();
455 463
456 // If it is HTML resource, use ".html" as its extension.
457 if (need_html_ext) {
458 file_name_ext = FILE_PATH_LITERAL(".");
459 file_name_ext.append(kDefaultHtmlExtension);
460 }
461
462 // Need to make sure the suggested file name is not too long. 464 // Need to make sure the suggested file name is not too long.
463 uint32_t max_path = GetMaxPathLengthForDirectory(saved_main_directory_path_); 465 uint32_t max_path = GetMaxPathLengthForDirectory(saved_main_directory_path_);
464 466
465 // Get safe pure file name. 467 // Get safe pure file name.
466 if (!TruncateBaseNameToFitPathConstraints( 468 if (!TruncateBaseNameToFitPathConstraints(
467 saved_main_directory_path_, file_name_ext, max_path, &base_name)) 469 saved_main_directory_path_, file_name_ext, max_path, &base_name))
468 return false; 470 return false;
469 471
470 base::FilePath::StringType file_name = base_name + file_name_ext; 472 base::FilePath::StringType file_name = base_name + file_name_ext;
471 473
(...skipping 1036 matching lines...) Expand 10 before | Expand all | Expand 10 after
1508 } 1510 }
1509 1511
1510 void SavePackage::FinalizeDownloadEntry() { 1512 void SavePackage::FinalizeDownloadEntry() {
1511 DCHECK(download_); 1513 DCHECK(download_);
1512 1514
1513 download_manager_->OnSavePackageSuccessfullyFinished(download_); 1515 download_manager_->OnSavePackageSuccessfullyFinished(download_);
1514 RemoveObservers(); 1516 RemoveObservers();
1515 } 1517 }
1516 1518
1517 } // namespace content 1519 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698