On Mac, dataTransfer claims to contain URL list when dropping files
authorrniwa@webkit.org <rniwa@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 20 Sep 2017 06:40:29 +0000 (06:40 +0000)
committerrniwa@webkit.org <rniwa@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 20 Sep 2017 06:40:29 +0000 (06:40 +0000)
https://bugs.webkit.org/show_bug.cgi?id=177219

Reviewed by Wenson Hsieh.

Source/WebCore:

Fixed the bug by removing code which was specifically adding local filenames as URLs in "text/uri-list"
when pasting or dropping files. Neither Chrome nor Firefox exhibit this behavior, and exposing local
filenames reveal sensitive information such as username.

Test: editing/pasteboard/datatransfer-types-dropping-text-file.html

* platform/mac/PasteboardMac.mm:
(WebCore::Pasteboard::readString):
(WebCore::addHTMLClipboardTypesForCocoaType):
(WebCore::absoluteURLsFromPasteboard): Deleted.

LayoutTests:

Added a regression test. For now, it only runs on Mac WK1.

* editing/pasteboard/datatransfer-types-dropping-text-file-expected.txt: Added.
* editing/pasteboard/datatransfer-types-dropping-text-file.html: Added.
* platform/ios/TestExpectations:
* platform/wk2/TestExpectations:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@222257 268f45cc-cd09-0410-ab3c-d52691b4dbfc

LayoutTests/ChangeLog
LayoutTests/editing/pasteboard/datatransfer-types-dropping-text-file-expected.txt [new file with mode: 0644]
LayoutTests/editing/pasteboard/datatransfer-types-dropping-text-file.html [new file with mode: 0644]
LayoutTests/platform/ios/TestExpectations
LayoutTests/platform/wk2/TestExpectations
Source/WebCore/ChangeLog
Source/WebCore/platform/mac/PasteboardMac.mm

index 8cfb878..9c2e271 100644 (file)
@@ -1,3 +1,17 @@
+2017-09-19  Ryosuke Niwa  <rniwa@webkit.org>
+
+        On Mac, dataTransfer claims to contain URL list when dropping files
+        https://bugs.webkit.org/show_bug.cgi?id=177219
+
+        Reviewed by Wenson Hsieh.
+
+        Added a regression test. For now, it only runs on Mac WK1.
+
+        * editing/pasteboard/datatransfer-types-dropping-text-file-expected.txt: Added.
+        * editing/pasteboard/datatransfer-types-dropping-text-file.html: Added.
+        * platform/ios/TestExpectations:
+        * platform/wk2/TestExpectations:
+
 2017-09-19  Simon Fraser  <simon.fraser@apple.com>
 
         Simplify compositing layer updating
diff --git a/LayoutTests/editing/pasteboard/datatransfer-types-dropping-text-file-expected.txt b/LayoutTests/editing/pasteboard/datatransfer-types-dropping-text-file-expected.txt
new file mode 100644 (file)
index 0000000..f0bfe88
--- /dev/null
@@ -0,0 +1,9 @@
+When dropping a file, dataTransfer.types must contain "Files" and not "text/uri-list". This test requires eventSender.beginDragWithFiles.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS dataTransfer.types.includes("Files") is true
+PASS dataTransfer.types.includes("text/uri-list") is false
+PASS dataTransfer.getData("url") is ""
+
diff --git a/LayoutTests/editing/pasteboard/datatransfer-types-dropping-text-file.html b/LayoutTests/editing/pasteboard/datatransfer-types-dropping-text-file.html
new file mode 100644 (file)
index 0000000..51b19b5
--- /dev/null
@@ -0,0 +1,32 @@
+<!DOCTYPE html>
+<html>
+<body>
+<div id="target" contentEditable="true" ondrop="check(event)"></div>
+<script src="../../resources/js-test-pre.js"></script>
+<script>
+description('When dropping a file, dataTransfer.types must contain "Files" and not "text/uri-list". This test requires eventSender.beginDragWithFiles.');
+
+function runTest() {
+    const target = document.getElementById('target');
+    eventSender.beginDragWithFiles(['../resources/abe.png']);
+    eventSender.mouseMoveTo(target.offsetLeft + 5, target.offsetTop + 5);
+    eventSender.mouseUp();
+}
+
+function check(event) {
+    dataTransfer = event.dataTransfer;
+    shouldBeTrue('dataTransfer.types.includes("Files")');
+    shouldBeFalse('dataTransfer.types.includes("text/uri-list")');
+    shouldBeEqualToString('dataTransfer.getData("url")', '');
+}
+
+if (window.eventSender)
+    runTest();
+else
+    testFailed('This test requires eventSender.beginDragWithFiles');
+
+var successfullyParsed = true;
+</script>
+<script src="../../resources/js-test-post.js"></script>
+</body>
+</html>
index 9fa0e77..a3e0de7 100644 (file)
@@ -388,6 +388,7 @@ editing/pasteboard/data-transfer-items-drag-drop-entry.html [ Skip ]
 editing/pasteboard/data-transfer-items-drag-drop-file.html [ Skip ]
 editing/pasteboard/data-transfer-items-drag-drop-string.html [ Skip ]
 editing/pasteboard/data-transfer-items-image-png.html [ Skip ]
+editing/pasteboard/datatransfer-types-dropping-text-file.html [ Skip ]
 editing/pasteboard/drag-drop-copy-content.html [ Skip ]
 editing/pasteboard/drag-drop-input-textarea.html [ Skip ]
 editing/pasteboard/drag-drop-list.html [ Skip ]
index a9e74bb..3cf65cd 100644 (file)
@@ -565,6 +565,7 @@ platform/mac/fast/events/objc-event-api.html
 # WebKitTestRunner needs an implementation of eventSender.beginDragWithFiles
 # https://bugs.webkit.org/show_bug.cgi?id=64285
 editing/pasteboard/datatransfer-items-drop-plaintext-file.html
+editing/pasteboard/datatransfer-types-dropping-text-file.html
 editing/pasteboard/entries-api
 editing/pasteboard/file-drag-to-editable.html [ Skip ]
 editing/pasteboard/file-input-files-access.html
index ac9b294..26c771c 100644 (file)
@@ -1,3 +1,21 @@
+2017-09-19  Ryosuke Niwa  <rniwa@webkit.org>
+
+        On Mac, dataTransfer claims to contain URL list when dropping files
+        https://bugs.webkit.org/show_bug.cgi?id=177219
+
+        Reviewed by Wenson Hsieh.
+
+        Fixed the bug by removing code which was specifically adding local filenames as URLs in "text/uri-list"
+        when pasting or dropping files. Neither Chrome nor Firefox exhibit this behavior, and exposing local
+        filenames reveal sensitive information such as username.
+
+        Test: editing/pasteboard/datatransfer-types-dropping-text-file.html
+
+        * platform/mac/PasteboardMac.mm:
+        (WebCore::Pasteboard::readString):
+        (WebCore::addHTMLClipboardTypesForCocoaType):
+        (WebCore::absoluteURLsFromPasteboard): Deleted.
+
 2017-09-19  Simon Fraser  <simon.fraser@apple.com>
 
         Simplify compositing layer updating
index daa9f6a..df332b6 100644 (file)
@@ -507,44 +507,12 @@ static Vector<String> absoluteURLsFromPasteboardFilenames(const String& pasteboa
     return urls;
 }
 
-static Vector<String> absoluteURLsFromPasteboard(const String& pasteboardName, bool onlyFirstURL = false)
-{
-    // NOTE: We must always check [availableTypes containsObject:] before accessing pasteboard data
-    // or CoreFoundation will printf when there is not data of the corresponding type.
-    Vector<String> availableTypes;
-    Vector<String> absoluteURLs;
-    platformStrategies()->pasteboardStrategy()->getTypes(availableTypes, pasteboardName);
-
-    // Try NSFilenamesPboardType because it contains a list
-    if (availableTypes.contains(String(NSFilenamesPboardType))) {
-        absoluteURLs = absoluteURLsFromPasteboardFilenames(pasteboardName, onlyFirstURL);
-        if (!absoluteURLs.isEmpty())
-            return absoluteURLs;
-    }
-
-    // Fallback to NSURLPboardType (which is a single URL)
-    if (availableTypes.contains(String(NSURLPboardType))) {
-        absoluteURLs.append(platformStrategies()->pasteboardStrategy()->stringForType(String(NSURLPboardType), pasteboardName));
-        return absoluteURLs;
-    }
-
-    // No file paths on the pasteboard, return nil
-    return Vector<String>();
-}
-
 String Pasteboard::readString(const String& type)
 {
     const String& cocoaType = cocoaTypeFromHTMLClipboardType(type);
     String cocoaValue;
 
-    // Grab the value off the pasteboard corresponding to the cocoaType
-    if (cocoaType == String(NSURLPboardType)) {
-        // "url" and "text/url-list" both map to NSURLPboardType in cocoaTypeFromHTMLClipboardType(), "url" only wants the first URL
-        bool onlyFirstURL = equalLettersIgnoringASCIICase(type, "url");
-        Vector<String> absoluteURLs = absoluteURLsFromPasteboard(m_pasteboardName, onlyFirstURL);
-        for (size_t i = 0; i < absoluteURLs.size(); i++)
-            cocoaValue = i ? "\n" + absoluteURLs[i]: absoluteURLs[i];
-    } else if (cocoaType == String(NSStringPboardType))
+    if (cocoaType == String(NSStringPboardType))
         cocoaValue = [platformStrategies()->pasteboardStrategy()->stringForType(cocoaType, m_pasteboardName) precomposedStringWithCanonicalMapping];
     else if (!cocoaType.isEmpty())
         cocoaValue = platformStrategies()->pasteboardStrategy()->stringForType(cocoaType, m_pasteboardName);
@@ -583,12 +551,8 @@ static void addHTMLClipboardTypesForCocoaType(ListHashSet<String>& resultTypes,
         // However, this is not really an issue for us doing a sanity check here.
         Vector<String> fileList;
         platformStrategies()->pasteboardStrategy()->getPathnamesForType(fileList, String(NSFilenamesPboardType), pasteboardName);
-        if (!fileList.isEmpty()) {
-            // It is unknown if NSFilenamesPboardType always implies NSURLPboardType in Cocoa,
-            // but NSFilenamesPboardType should imply both 'text/uri-list' and 'Files'
-            resultTypes.add(ASCIILiteral("text/uri-list"));
+        if (!fileList.isEmpty())
             resultTypes.add(ASCIILiteral("Files"));
-        }
         return;
     }
     String utiType = utiTypeFromCocoaType(cocoaType);