Skip to content

Commit

Permalink
Use a randomly-generated extension when creating a fake MimeClassInfo
Browse files Browse the repository at this point in the history
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 <masonf@chromium.org>
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] whatwg/html#6738
    [3] web-platform-tests/wpt#29559

    Bug: 1164635
  • Loading branch information
mariospr authored and mkarolin committed Sep 13, 2021
1 parent b4802ea commit 7208615
Showing 1 changed file with 8 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,14 @@ void FarblePlugins(DOMPluginArray* owner,
BraveSessionCache::From(*(frame->DomWindow()))
.GenerateRandomString("PLUGIN_1_DESCRIPTION", 32),
0, false);
Vector<String> fake_plugin_extensions_1{
BraveSessionCache::From(*(frame->DomWindow()))
.GenerateRandomString("PLUGIN_1_EXTENSION", 3)};
auto* fake_mime_info_1 = MakeGarbageCollected<MimeClassInfo>(
"",
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<DOMPlugin>(
frame->DomWindow(), *fake_plugin_info_1);
Expand All @@ -121,11 +124,14 @@ void FarblePlugins(DOMPluginArray* owner,
BraveSessionCache::From(*(frame->DomWindow()))
.GenerateRandomString("PLUGIN_2_DESCRIPTION", 31),
0, false);
Vector<String> fake_plugin_extensions_2{
BraveSessionCache::From(*(frame->DomWindow()))
.GenerateRandomString("PLUGIN_2_EXTENSION", 3)};
auto* fake_mime_info_2 = MakeGarbageCollected<MimeClassInfo>(
"",
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<DOMPlugin>(
frame->DomWindow(), *fake_plugin_info_2);
Expand Down

0 comments on commit 7208615

Please sign in to comment.