Changeset 222688 in webkit


Ignore:
Timestamp:
Sep 30, 2017 11:59:00 PM (7 years ago)
Author:
rniwa@webkit.org
Message:

Don't reveal file URL when pasting an image
https://bugs.webkit.org/show_bug.cgi?id=177710
<rdar://problem/34757924>

Reviewed by Wenson Hsieh.

Source/WebCore:

Fixed the bug by generalizing the code we had for drag & drop to hide string types when there is a file.

We don't hide string types when customPasteboardDataEnabled() is false to preserve the backwards compatiblity
with apps that are relying on being able to read files URLs in the pasteboard.

Test: editing/pasteboard/paste-image-does-not-reveal-file-url.html

  • dom/DataTransfer.cpp:

(WebCore::DataTransfer::getData const): Pretend there is no string data when there is a file in the pasteboard
custom pasteboard data is enabled.
(WebCore::DataTransfer::setData): Ditto.
(WebCore::DataTransfer::types const): Ditto.

  • dom/DataTransfer.h:

(WebCore::DataTransfer::forDrag const): Added for when drag & drop support is disabled at compilation time.
(WebCore::DataTransfer::forFileDrag const): Ditto.

  • platform/Pasteboard.h:
  • platform/StaticPasteboard.h:
  • platform/cocoa/PasteboardCocoa.mm:

(WebCore::Pasteboard::containsFiles): Added.

  • platform/gtk/PasteboardGtk.cpp:

(WebCore::Pasteboard::containsFiles): Added.

  • platform/win/PasteboardWin.cpp:

(WebCore::Pasteboard::containsFiles): Added.

  • platform/wpe/PasteboardWPE.cpp:

(WebCore::Pasteboard::containsFiles): Added.
(WebCore::Pasteboard::readFilenames): Annotated this function with notImplemented().

LayoutTests:

Added a regression test for pasting an image. We enable this protection only when custom data is enabled
to preserve the backwards compatibility.

  • editing/pasteboard/paste-image-does-not-reveal-file-url-expected.txt: Added.
  • editing/pasteboard/paste-image-does-not-reveal-file-url.html: Added.
Location:
trunk
Files:
2 added
11 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r222687 r222688  
     12017-09-30  Ryosuke Niwa  <rniwa@webkit.org>
     2
     3        Don't reveal file URL when pasting an image
     4        https://bugs.webkit.org/show_bug.cgi?id=177710
     5        <rdar://problem/34757924>
     6
     7        Reviewed by Wenson Hsieh.
     8
     9        Added a regression test for pasting an image. We enable this protection only when custom data is enabled
     10        to preserve the backwards compatibility.
     11
     12        * editing/pasteboard/paste-image-does-not-reveal-file-url-expected.txt: Added.
     13        * editing/pasteboard/paste-image-does-not-reveal-file-url.html: Added.
     14
    1152017-09-30  Wenson Hsieh  <wenson_hsieh@apple.com>
    216
  • trunk/Source/WebCore/ChangeLog

    r222686 r222688  
     12017-09-30  Ryosuke Niwa  <rniwa@webkit.org>
     2
     3        Don't reveal file URL when pasting an image
     4        https://bugs.webkit.org/show_bug.cgi?id=177710
     5        <rdar://problem/34757924>
     6
     7        Reviewed by Wenson Hsieh.
     8
     9        Fixed the bug by generalizing the code we had for drag & drop to hide string types when there is a file.
     10
     11        We don't hide string types when customPasteboardDataEnabled() is false to preserve the backwards compatiblity
     12        with apps that are relying on being able to read files URLs in the pasteboard.
     13
     14        Test: editing/pasteboard/paste-image-does-not-reveal-file-url.html
     15
     16        * dom/DataTransfer.cpp:
     17        (WebCore::DataTransfer::getData const): Pretend there is no string data when there is a file in the pasteboard
     18        custom pasteboard data is enabled.
     19        (WebCore::DataTransfer::setData): Ditto.
     20        (WebCore::DataTransfer::types const): Ditto.
     21        * dom/DataTransfer.h:
     22        (WebCore::DataTransfer::forDrag const): Added for when drag & drop support is disabled at compilation time.
     23        (WebCore::DataTransfer::forFileDrag const): Ditto.
     24        * platform/Pasteboard.h:
     25        * platform/StaticPasteboard.h:
     26        * platform/cocoa/PasteboardCocoa.mm:
     27        (WebCore::Pasteboard::containsFiles): Added.
     28        * platform/gtk/PasteboardGtk.cpp:
     29        (WebCore::Pasteboard::containsFiles): Added.
     30        * platform/win/PasteboardWin.cpp:
     31        (WebCore::Pasteboard::containsFiles): Added.
     32        * platform/wpe/PasteboardWPE.cpp:
     33        (WebCore::Pasteboard::containsFiles): Added.
     34        (WebCore::Pasteboard::readFilenames): Annotated this function with notImplemented().
     35
    1362017-09-30  Sam Weinig  <sam@webkit.org>
    237
  • trunk/Source/WebCore/dom/DataTransfer.cpp

    r222680 r222688  
    138138        return String();
    139139
    140 #if ENABLE(DRAG_SUPPORT)
    141     if (forFileDrag() && m_pasteboard->readFilenames().size())
     140    if ((forFileDrag() || Settings::customPasteboardDataEnabled()) && m_pasteboard->containsFiles())
    142141        return { };
    143 #endif
    144142
    145143    auto normalizedType = normalizeType(type);
     
    154152        return;
    155153
    156 #if ENABLE(DRAG_SUPPORT)
    157     if (forFileDrag() && m_pasteboard->readFilenames().size())
    158         return;
    159 #endif
     154    if ((forFileDrag() || Settings::customPasteboardDataEnabled()) && m_pasteboard->containsFiles())
     155        return;
    160156
    161157    String normalizedType = normalizeType(type);
     
    176172    if (!canReadTypes())
    177173        return { };
    178 
    179     return Settings::customPasteboardDataEnabled() ? m_pasteboard->typesSafeForBindings() : m_pasteboard->typesForLegacyUnsafeBindings();
     174   
     175    if (!Settings::customPasteboardDataEnabled())
     176        return m_pasteboard->typesForLegacyUnsafeBindings();
     177
     178    if (m_pasteboard->containsFiles())
     179        return { "Files" };
     180    return m_pasteboard->typesSafeForBindings();
    180181}
    181182
  • trunk/Source/WebCore/dom/DataTransfer.h

    r222595 r222688  
    107107    bool forDrag() const { return m_type == Type::DragAndDropData || m_type == Type::DragAndDropFiles; }
    108108    bool forFileDrag() const { return m_type == Type::DragAndDropFiles; }
     109#else
     110    bool forDrag() const { return false; }
     111    bool forFileDrag() const { return false; }
    109112#endif
    110113
  • trunk/Source/WebCore/platform/Pasteboard.h

    r222680 r222688  
    216216    virtual void write(const PasteboardWebContent&);
    217217
     218    virtual bool containsFiles();
    218219    virtual Vector<String> readFilenames();
    219220    virtual bool canSmartReplace();
  • trunk/Source/WebCore/platform/StaticPasteboard.h

    r222680 r222688  
    5959    void write(const PasteboardWebContent&) final { }
    6060
     61    bool containsFiles() final { return false; }
    6162    Vector<String> readFilenames() final { return { }; }
    6263    bool canSmartReplace() final { return false; }
  • trunk/Source/WebCore/platform/cocoa/PasteboardCocoa.mm

    r222680 r222688  
    152152}
    153153
     154bool Pasteboard::containsFiles()
     155{
     156    if (!platformStrategies()->pasteboardStrategy()->getNumberOfFiles(m_pasteboardName)) {
     157        Vector<String> cocoaTypes;
     158        platformStrategies()->pasteboardStrategy()->getTypes(cocoaTypes, m_pasteboardName);
     159        if (cocoaTypes.findMatching([](const String& cocoaType) { return shouldTreatCocoaTypeAsFile(cocoaType); }) == notFound)
     160            return false;
     161    }
     162
     163    // Enforce changeCount ourselves for security. We check after reading instead of before to be
     164    // sure it doesn't change between our testing the change count and accessing the data.
     165    if (m_changeCount != platformStrategies()->pasteboardStrategy()->changeCount(m_pasteboardName))
     166        return false;
     167
     168    return true;
     169}
     170
    154171Vector<String> Pasteboard::typesSafeForBindings()
    155172{
  • trunk/Source/WebCore/platform/gtk/PasteboardGtk.cpp

    r222680 r222688  
    320320}
    321321
     322bool Pasteboard::containsFiles()
     323{
     324    return readFilenames().size();
     325}
     326
    322327Vector<String> Pasteboard::readFilenames()
    323328{
  • trunk/Source/WebCore/platform/win/PasteboardWin.cpp

    r222680 r222688  
    313313    notImplemented();
    314314    return { };
     315}
     316
     317bool Pasteboard::containsFiles()
     318{
     319    return readFilenames().size(); // FIXME: Make this code more efficient.
    315320}
    316321
  • trunk/Source/WebCore/platform/wpe/PasteboardWPE.cpp

    r222680 r222688  
    125125}
    126126
     127bool Pasteboard::containsFiles()
     128{
     129    notImplemented();
     130    return false;
     131}
     132
    127133Vector<String> Pasteboard::readFilenames()
    128134{
     135    notImplemented();
    129136    return Vector<String>();
    130137}
  • trunk/Tools/TestWebKitAPI/Tests/ios/DataInteractionTests.mm

    r222656 r222688  
    10371037{
    10381038    NSArray<NSString *> *expectedOutput = @[
    1039         @"Found data transfer item (kind: 'string', type: 'text/plain')",
    10401039        @"Found data transfer item (kind: 'file', type: 'text/plain')",
    10411040        @"FILE: /foo.txt ('text/plain', 28 bytes)"
     
    15581557    // File URLs should never be exposed directly to web content, so DataTransfer.getData should return an empty string here.
    15591558    checkJSONWithLogging([webView stringByEvaluatingJavaScript:@"output.value"], @{
    1560         @"dragover": @{ @"Files": @"", @"text/uri-list" : @"" },
    1561         @"drop": @{ @"Files": @"", @"text/uri-list" : @"" }
     1559        @"dragover": @{ @"Files": @"" },
     1560        @"drop": @{ @"Files": @"" }
    15621561    });
    15631562}
     
    15801579        [simulator runFrom:CGPointMake(300, 375) to:CGPointMake(50, 375)];
    15811580        checkJSONWithLogging([webView stringByEvaluatingJavaScript:@"output.value"], @{
    1582             @"dragover": @{ @"text/plain" : @"" },
    1583             @"drop": @{ @"text/plain" : @"" }
     1581            @"dragover": @{ @"Files" : @"" },
     1582            @"drop": @{ @"Files" : @"" }
    15841583        });
    15851584
Note: See TracChangeset for help on using the changeset viewer.