disable-download-quarantine.patch 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  1. # Disables file download quarantining
  2. --- a/content/browser/renderer_host/pepper/pepper_file_io_host.cc
  3. +++ b/content/browser/renderer_host/pepper/pepper_file_io_host.cc
  4. @@ -432,7 +432,7 @@ void PepperFileIOHost::OnLocalFileOpened
  5. ppapi::host::ReplyMessageContext reply_context,
  6. const base::FilePath& path,
  7. base::File::Error error_code) {
  8. -#if defined(OS_WIN) || defined(OS_LINUX)
  9. +#if 0
  10. // Quarantining a file before its contents are available is only supported on
  11. // Windows and Linux.
  12. if (!FileOpenForWrite(open_flags_) || error_code != base::File::FILE_OK) {
  13. @@ -452,7 +452,7 @@ void PepperFileIOHost::OnLocalFileOpened
  14. #endif
  15. }
  16. -#if defined(OS_WIN) || defined(OS_LINUX)
  17. +#if 0
  18. void PepperFileIOHost::OnLocalFileQuarantined(
  19. ppapi::host::ReplyMessageContext reply_context,
  20. const base::FilePath& path,
  21. --- a/content/browser/renderer_host/pepper/pepper_file_io_host.h
  22. +++ b/content/browser/renderer_host/pepper/pepper_file_io_host.h
  23. @@ -15,7 +15,6 @@
  24. #include "base/macros.h"
  25. #include "base/memory/ref_counted.h"
  26. #include "base/memory/weak_ptr.h"
  27. -#include "components/download/quarantine/quarantine.h"
  28. #include "content/browser/renderer_host/pepper/browser_ppapi_host_impl.h"
  29. #include "ipc/ipc_listener.h"
  30. #include "ipc/ipc_platform_file.h"
  31. @@ -92,10 +91,6 @@ class PepperFileIOHost : public ppapi::h
  32. const base::FilePath& path,
  33. base::File::Error error_code);
  34. - void OnLocalFileQuarantined(ppapi::host::ReplyMessageContext reply_context,
  35. - const base::FilePath& path,
  36. - download::QuarantineFileResult quarantine_result);
  37. -
  38. void SendFileOpenReply(ppapi::host::ReplyMessageContext reply_context,
  39. base::File::Error error_code);
  40. --- a/content/browser/BUILD.gn
  41. +++ b/content/browser/BUILD.gn
  42. @@ -52,7 +52,6 @@ jumbo_source_set("browser") {
  43. "//components/discardable_memory/service",
  44. "//components/download/database",
  45. "//components/download/public/common:public",
  46. - "//components/download/quarantine",
  47. "//components/filename_generation",
  48. "//components/link_header_util",
  49. "//components/metrics",
  50. --- a/components/download/internal/common/base_file.cc
  51. +++ b/components/download/internal/common/base_file.cc
  52. @@ -23,7 +23,6 @@
  53. #include "components/download/public/common/download_interrupt_reasons_utils.h"
  54. #include "components/download/public/common/download_item.h"
  55. #include "components/download/public/common/download_stats.h"
  56. -#include "components/download/quarantine/quarantine.h"
  57. #include "crypto/secure_hash.h"
  58. #include "services/service_manager/public/cpp/connector.h"
  59. @@ -523,129 +522,12 @@ DownloadInterruptReason BaseFile::Publis
  60. }
  61. #endif // defined(OS_ANDROID)
  62. -namespace {
  63. -
  64. -DownloadInterruptReason QuarantineFileResultToReason(
  65. - quarantine::mojom::QuarantineFileResult result) {
  66. - switch (result) {
  67. - case quarantine::mojom::QuarantineFileResult::OK:
  68. - return DOWNLOAD_INTERRUPT_REASON_NONE;
  69. - case quarantine::mojom::QuarantineFileResult::VIRUS_INFECTED:
  70. - return DOWNLOAD_INTERRUPT_REASON_FILE_VIRUS_INFECTED;
  71. - case quarantine::mojom::QuarantineFileResult::SECURITY_CHECK_FAILED:
  72. - return DOWNLOAD_INTERRUPT_REASON_FILE_SECURITY_CHECK_FAILED;
  73. - case quarantine::mojom::QuarantineFileResult::BLOCKED_BY_POLICY:
  74. - return DOWNLOAD_INTERRUPT_REASON_FILE_BLOCKED;
  75. - case quarantine::mojom::QuarantineFileResult::ACCESS_DENIED:
  76. - return DOWNLOAD_INTERRUPT_REASON_FILE_ACCESS_DENIED;
  77. -
  78. - case quarantine::mojom::QuarantineFileResult::FILE_MISSING:
  79. - // Don't have a good interrupt reason here. This return code means that
  80. - // the file at |full_path_| went missing before QuarantineFile got to
  81. - // look at it. Not expected to happen, but we've seen instances where a
  82. - // file goes missing immediately after BaseFile closes the handle.
  83. - //
  84. - // Intentionally using a different error message than
  85. - // SECURITY_CHECK_FAILED in order to distinguish the two.
  86. - return DOWNLOAD_INTERRUPT_REASON_FILE_FAILED;
  87. -
  88. - case quarantine::mojom::QuarantineFileResult::ANNOTATION_FAILED:
  89. - // This means that the mark-of-the-web couldn't be applied. The file is
  90. - // already on the file system under its final target name.
  91. - //
  92. - // Causes of failed annotations typically aren't transient. E.g. the
  93. - // target file system may not support extended attributes or alternate
  94. - // streams. We are going to allow these downloads to progress on the
  95. - // assumption that failures to apply MOTW can't reliably be introduced
  96. - // remotely.
  97. - return DOWNLOAD_INTERRUPT_REASON_NONE;
  98. - }
  99. - return DOWNLOAD_INTERRUPT_REASON_FILE_FAILED;
  100. -}
  101. -
  102. -// Given a source and a referrer, determines the "safest" URL that can be used
  103. -// to determine the authority of the download source. Returns an empty URL if no
  104. -// HTTP/S URL can be determined for the <|source_url|, |referrer_url|> pair.
  105. -GURL GetEffectiveAuthorityURL(const GURL& source_url,
  106. - const GURL& referrer_url) {
  107. - if (source_url.is_valid()) {
  108. - // http{,s} has an authority and are supported.
  109. - if (source_url.SchemeIsHTTPOrHTTPS())
  110. - return source_url;
  111. -
  112. - // If the download source is file:// ideally we should copy the MOTW from
  113. - // the original file, but given that Chrome/Chromium places strict
  114. - // restrictions on which schemes can reference file:// URLs, this code is
  115. - // going to assume that at this point it's okay to treat this download as
  116. - // being from the local system.
  117. - if (source_url.SchemeIsFile())
  118. - return source_url;
  119. -
  120. - // ftp:// has an authority.
  121. - if (source_url.SchemeIs(url::kFtpScheme))
  122. - return source_url;
  123. - }
  124. -
  125. - if (referrer_url.is_valid() && referrer_url.SchemeIsHTTPOrHTTPS())
  126. - return referrer_url;
  127. -
  128. - return GURL();
  129. -}
  130. -
  131. -} // namespace
  132. -
  133. -#if defined(OS_WIN) || defined(OS_MACOSX) || defined(OS_LINUX)
  134. -
  135. -DownloadInterruptReason BaseFile::AnnotateWithSourceInformationSync(
  136. - const std::string& client_guid,
  137. - const GURL& source_url,
  138. - const GURL& referrer_url) {
  139. - DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
  140. - DCHECK(!detached_);
  141. - DCHECK(!full_path_.empty());
  142. -
  143. - CONDITIONAL_TRACE(BEGIN0("download", "DownloadFileAnnotate"));
  144. - QuarantineFileResult result = QuarantineFile(
  145. - full_path_, GetEffectiveAuthorityURL(source_url, referrer_url),
  146. - referrer_url, client_guid);
  147. - CONDITIONAL_TRACE(END0("download", "DownloadFileAnnotate"));
  148. -
  149. - return QuarantineFileResultToReason(result);
  150. -}
  151. -#else // !OS_WIN && !OS_MACOSX && !OS_LINUX
  152. DownloadInterruptReason BaseFile::AnnotateWithSourceInformationSync(
  153. const std::string& client_guid,
  154. const GURL& source_url,
  155. const GURL& referrer_url) {
  156. return DOWNLOAD_INTERRUPT_REASON_NONE;
  157. }
  158. -#endif
  159. -
  160. -void BaseFile::OnFileQuarantined(
  161. - bool connection_error,
  162. - quarantine::mojom::QuarantineFileResult result) {
  163. - base::UmaHistogramBoolean("Download.QuarantineService.ConnectionError",
  164. - connection_error);
  165. -
  166. - DCHECK(on_annotation_done_callback_);
  167. - quarantine_service_.reset();
  168. - std::move(on_annotation_done_callback_)
  169. - .Run(QuarantineFileResultToReason(result));
  170. -}
  171. -
  172. -void BaseFile::OnQuarantineServiceError(const GURL& source_url,
  173. - const GURL& referrer_url) {
  174. -#if defined(OS_WIN)
  175. - if (base::FeatureList::IsEnabled(quarantine::kOutOfProcessQuarantine)) {
  176. - OnFileQuarantined(/*connection_error=*/true,
  177. - quarantine::SetInternetZoneIdentifierDirectly(
  178. - full_path_, source_url, referrer_url));
  179. - return;
  180. - }
  181. -#endif // defined(OS_WIN)
  182. -
  183. - CHECK(false) << "In-process quarantine service should not have failed.";
  184. -}
  185. void BaseFile::AnnotateWithSourceInformation(
  186. const std::string& client_guid,
  187. @@ -653,31 +535,8 @@ void BaseFile::AnnotateWithSourceInforma
  188. const GURL& referrer_url,
  189. std::unique_ptr<service_manager::Connector> connector,
  190. OnAnnotationDoneCallback on_annotation_done_callback) {
  191. - GURL authority_url = GetEffectiveAuthorityURL(source_url, referrer_url);
  192. - if (!connector) {
  193. -#if defined(OS_WIN)
  194. - QuarantineFileResult result = quarantine::SetInternetZoneIdentifierDirectly(
  195. - full_path_, authority_url, referrer_url);
  196. -#else
  197. - QuarantineFileResult result = QuarantineFileResult::ANNOTATION_FAILED;
  198. -#endif
  199. - std::move(on_annotation_done_callback)
  200. - .Run(QuarantineFileResultToReason(result));
  201. - } else {
  202. - connector->BindInterface(quarantine::mojom::kServiceName,
  203. - mojo::MakeRequest(&quarantine_service_));
  204. -
  205. - on_annotation_done_callback_ = std::move(on_annotation_done_callback);
  206. -
  207. - quarantine_service_.set_connection_error_handler(base::BindOnce(
  208. - &BaseFile::OnQuarantineServiceError, weak_factory_.GetWeakPtr(),
  209. - authority_url, referrer_url));
  210. -
  211. - quarantine_service_->QuarantineFile(
  212. - full_path_, authority_url, referrer_url, client_guid,
  213. - base::BindOnce(&BaseFile::OnFileQuarantined, weak_factory_.GetWeakPtr(),
  214. - false));
  215. - }
  216. + std::move(on_annotation_done_callback)
  217. + .Run(DOWNLOAD_INTERRUPT_REASON_NONE);
  218. }
  219. } // namespace download