disable-download-quarantine.patch 9.1 KB

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