From 7208615a0003fed878b1abb3fe628aad9a5779a6 Mon Sep 17 00:00:00 2001 From: Mario Sanchez Prada Date: Thu, 12 Aug 2021 14:07:28 +0200 Subject: [PATCH] Use a randomly-generated extension when creating a fake MimeClassInfo MimeClassInfo now requires to pass a list of extensions to the constructor, so we need to generate at least a random one to create the fake MimeClassInfo used for farbling purposes. Note that 3 browser tests failing likely because of this patch: BraveNavigatorPluginsFarblingBrowserTest.FarbleNavigatorPlugins BraveNavigatorPluginsFarblingBrowserTest.FarbleNavigatorPluginsBuiltin BraveNavigatorPluginsFarblingBrowserTest.FarbleNavigatorPluginsReset This is because of Chromium now enabling a feature that will return a hardcoded list via navigator.plugins which is incompatible with Brave's farbling code. That will be addressed in the next patch. Chromium change: https://source.chromium.org/chromium/chromium/src/+/fb96360c18b517bcc487c0de7235eec27e3adf5e commit fb96360c18b517bcc487c0de7235eec27e3adf5e Author: Mason Freed Date: Fri Aug 6 20:20:17 2021 +0000 Hard-code the list of plugins and mimetypes in navigator See [1] for a previous attempt to completely empty the navigator.plugins and navigator.mimeTypes APIs. That caused site breakage due to sites scanning for a PDF reader. This new attempt is discussed in significant detail in [2], and involves the hard-coding of a list of PDF viewers and mime types. The plugins/mimetypes lists will be empty if the user setting to download PDFs instead of viewing them (chrome://settings/content/pdfDocuments) is enabled. This is to ensure compat with sites that scan the plugins list for specific PDF plugins to decide on behavior. Prior to this CL, when the PDF viewer is disabled, the PDF viewer plugins are unloaded. Tests were copied mostly verbatim from [3], thanks @domenic. I2S: https://groups.google.com/a/chromium.org/g/blink-dev/c/bbxAGu90LgM [1] https://chromium-review.googlesource.com/c/chromium/src/+/2783393 [2] https://github.com/whatwg/html/pull/6738 [3] https://github.com/web-platform-tests/wpt/pull/29559 Bug: 1164635 --- .../blink/renderer/modules/plugins/dom_plugin_array.cc | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/chromium_src/third_party/blink/renderer/modules/plugins/dom_plugin_array.cc b/chromium_src/third_party/blink/renderer/modules/plugins/dom_plugin_array.cc index 00caab7ba084..f1b0531b39ae 100644 --- a/chromium_src/third_party/blink/renderer/modules/plugins/dom_plugin_array.cc +++ b/chromium_src/third_party/blink/renderer/modules/plugins/dom_plugin_array.cc @@ -103,11 +103,14 @@ void FarblePlugins(DOMPluginArray* owner, BraveSessionCache::From(*(frame->DomWindow())) .GenerateRandomString("PLUGIN_1_DESCRIPTION", 32), 0, false); + Vector fake_plugin_extensions_1{ + BraveSessionCache::From(*(frame->DomWindow())) + .GenerateRandomString("PLUGIN_1_EXTENSION", 3)}; auto* fake_mime_info_1 = MakeGarbageCollected( "", BraveSessionCache::From(*(frame->DomWindow())) .GenerateRandomString("MIME_1_DESCRIPTION", 32), - *fake_plugin_info_1); + *fake_plugin_info_1, fake_plugin_extensions_1); fake_plugin_info_1->AddMimeType(fake_mime_info_1); auto* fake_dom_plugin_1 = MakeGarbageCollected( frame->DomWindow(), *fake_plugin_info_1); @@ -121,11 +124,14 @@ void FarblePlugins(DOMPluginArray* owner, BraveSessionCache::From(*(frame->DomWindow())) .GenerateRandomString("PLUGIN_2_DESCRIPTION", 31), 0, false); + Vector fake_plugin_extensions_2{ + BraveSessionCache::From(*(frame->DomWindow())) + .GenerateRandomString("PLUGIN_2_EXTENSION", 3)}; auto* fake_mime_info_2 = MakeGarbageCollected( "", BraveSessionCache::From(*(frame->DomWindow())) .GenerateRandomString("MIME_2_DESCRIPTION", 32), - *fake_plugin_info_2); + *fake_plugin_info_2, fake_plugin_extensions_2); fake_plugin_info_2->AddMimeType(fake_mime_info_2); auto* fake_dom_plugin_2 = MakeGarbageCollected( frame->DomWindow(), *fake_plugin_info_2);