Bug 177710 - Don't reveal file URL when pasting an image
Summary: Don't reveal file URL when pasting an image
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: HTML Editing (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Ryosuke Niwa
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2017-09-30 17:50 PDT by Ryosuke Niwa
Modified: 2017-10-02 14:41 PDT (History)
10 users (show)

See Also:


Attachments
Fixes the bug (11.58 KB, patch)
2017-09-30 17:58 PDT, Ryosuke Niwa
no flags Details | Formatted Diff | Diff
Replaced 0 by false (11.58 KB, patch)
2017-09-30 21:28 PDT, Ryosuke Niwa
no flags Details | Formatted Diff | Diff
Patch for landing (14.12 KB, patch)
2017-09-30 23:20 PDT, Ryosuke Niwa
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Ryosuke Niwa 2017-09-30 17:50:39 PDT
When pasting an image, we shouldn't reveal its local file path in text/plain or text/uri-list.
In fact, we should just hide all non-file types as we do for drag & drop.
Comment 1 Radar WebKit Bug Importer 2017-09-30 17:51:58 PDT
<rdar://problem/34757924>
Comment 2 Ryosuke Niwa 2017-09-30 17:58:56 PDT
Created attachment 322305 [details]
Fixes the bug
Comment 3 Wenson Hsieh 2017-09-30 18:11:39 PDT
Comment on attachment 322305 [details]
Fixes the bug

View in context: https://bugs.webkit.org/attachment.cgi?id=322305&action=review

> Source/WebCore/platform/StaticPasteboard.h:61
> +    bool containsFiles() final { return 0; }

I prefer `return false`, since the return type is a bool.

> Source/WebCore/platform/cocoa/PasteboardCocoa.mm:163
> +    // Enforce changeCount ourselves for security. We check after reading instead of before to be

It seems this piece of code (and comment) keeps popping up in multiple places in this file :/ Now that we have a PasteboardCocoa.mm, it seems we should pull this out into a separate helper in this file?
Comment 4 Ryosuke Niwa 2017-09-30 21:27:08 PDT
(In reply to Wenson Hsieh from comment #3)
> Comment on attachment 322305 [details]
> Fixes the bug
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=322305&action=review
> 
> > Source/WebCore/platform/StaticPasteboard.h:61
> > +    bool containsFiles() final { return 0; }
> 
> I prefer `return false`, since the return type is a bool.

Oops, I meant to use "false" there.

> > Source/WebCore/platform/cocoa/PasteboardCocoa.mm:163
> > +    // Enforce changeCount ourselves for security. We check after reading instead of before to be
> 
> It seems this piece of code (and comment) keeps popping up in multiple
> places in this file :/ Now that we have a PasteboardCocoa.mm, it seems we
> should pull this out into a separate helper in this file?

Perhaps. We probably need a function that takes lambda to do this.
Comment 5 Ryosuke Niwa 2017-09-30 21:28:06 PDT
Created attachment 322312 [details]
Replaced 0 by false
Comment 6 Wenson Hsieh 2017-09-30 21:40:01 PDT
Comment on attachment 322312 [details]
Replaced 0 by false

View in context: https://bugs.webkit.org/attachment.cgi?id=322312&action=review

> Source/WebCore/dom/DataTransfer.cpp:178
> +    if (m_pasteboard->containsFiles())

Heads up: with this change, we might need to rebaseline the API test DataInteractionTests.DataTransferGetDataWhenDroppingImageWithFileURL to remove the @"text/uri-list": @"" expectation.
Comment 7 Ryosuke Niwa 2017-09-30 21:40:37 PDT
(In reply to Wenson Hsieh from comment #6)
> Comment on attachment 322312 [details]
> Replaced 0 by false
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=322312&action=review
> 
> > Source/WebCore/dom/DataTransfer.cpp:178
> > +    if (m_pasteboard->containsFiles())
> 
> Heads up: with this change, we might need to rebaseline the API test
> DataInteractionTests.DataTransferGetDataWhenDroppingImageWithFileURL to
> remove the @"text/uri-list": @"" expectation.

Oh that's a good point. Let me check that...
Comment 8 Ryosuke Niwa 2017-09-30 23:00:01 PDT
Looks like there's a slight issue with PlatformPasteboard::numberOfFiles() in iOS. We need to replace numberOfFiles with droppedFileURLs's size instead. It claims to have a file even when it's just a text content and won't return a file URL.
Comment 9 Wenson Hsieh 2017-09-30 23:09:44 PDT
(In reply to Ryosuke Niwa from comment #8)
> Looks like there's a slight issue with PlatformPasteboard::numberOfFiles()
> in iOS. We need to replace numberOfFiles with droppedFileURLs's size
> instead. It claims to have a file even when it's just a text content and
> won't return a file URL.

Hmm...-droppedFileURLs will return 0 prior to the drop. If we just return -droppedFileURLs in PlatformPasteboard::numberOfFiles, I suspect that we would break  uploading by dropping into inputs of type file.
Comment 10 Ryosuke Niwa 2017-09-30 23:14:26 PDT
Actually, I think I was misreading the test. DataTransferGetDataWhenDroppingRespectsPresentationStyle should return "Files" now because it's doing registerFileRepresentationForTypeIdentifier.
Comment 11 Ryosuke Niwa 2017-09-30 23:17:20 PDT
Rather, the actual observation is that there are two test cases in DataTransferGetDataWhenDroppingRespectsPresentationStyle, and the one with UIPreferredPresentationStyleAttachment needs to be rebaselined.
Comment 12 Wenson Hsieh 2017-09-30 23:19:08 PDT
(In reply to Ryosuke Niwa from comment #11)
> Rather, the actual observation is that there are two test cases in
> DataTransferGetDataWhenDroppingRespectsPresentationStyle, and the one with
> UIPreferredPresentationStyleAttachment needs to be rebaselined.

Yes, that's correct. A bit more detail: this test involves two parts: (1) dropping an item provider containing text, with UIPreferredPresentationStyleAttachment set and (2) dropping an item provider containing text, with UIPreferredPresentationStyleInline set. The fact that -registerFileRepresentationForTypeIdentifier is used to supply the data is actually not important.

The former simulates dropping a text file (e.g. from Files.app) while the latter involves dropping a text selection. I would expect "Files" to appear in the list of types in the former case, but not the latter.
Comment 13 Ryosuke Niwa 2017-09-30 23:20:11 PDT
Created attachment 322313 [details]
Patch for landing
Comment 14 WebKit Commit Bot 2017-09-30 23:59:03 PDT
Comment on attachment 322313 [details]
Patch for landing

Clearing flags on attachment: 322313

Committed r222688: <http://trac.webkit.org/changeset/222688>
Comment 15 WebKit Commit Bot 2017-09-30 23:59:05 PDT
All reviewed patches have been landed.  Closing bug.
Comment 16 Ryan Haddad 2017-10-02 11:12:00 PDT
API test DataInteractionTests.ExternalSourceDataTransferItemGetPlainTextFileAsEntry is failing on iOS after this change:

/Volumes/Data/slave/ios-simulator-11-release/build/Tools/TestWebKitAPI/Tests/ios/DataInteractionTests.mm:1063
Value of: [webView stringByEvaluatingJavaScript:@"output.value"]
  Actual: "Found data transfer item (kind: 'string', type: 'text/plain')
Found data transfer item (kind: 'file', type: 'text/plain')
FILE: /foo.txt ('text/plain', 28 bytes)"
Expected: [expectedOutput componentsJoinedByString:@"\n"]
Which is: "Found data transfer item (kind: 'file', type: 'text/plain')
FILE: /foo.txt ('text/plain', 28 bytes)"

https://build.webkit.org/builders/Apple%20iOS%2011%20Simulator%20Release%20WK2%20%28Tests%29/builds/219
Comment 17 Wenson Hsieh 2017-10-02 12:06:04 PDT
(In reply to Ryan Haddad from comment #16)
> API test
> DataInteractionTests.ExternalSourceDataTransferItemGetPlainTextFileAsEntry
> is failing on iOS after this change:
> 
> /Volumes/Data/slave/ios-simulator-11-release/build/Tools/TestWebKitAPI/Tests/
> ios/DataInteractionTests.mm:1063
> Value of: [webView stringByEvaluatingJavaScript:@"output.value"]
>   Actual: "Found data transfer item (kind: 'string', type: 'text/plain')
> Found data transfer item (kind: 'file', type: 'text/plain')
> FILE: /foo.txt ('text/plain', 28 bytes)"
> Expected: [expectedOutput componentsJoinedByString:@"\n"]
> Which is: "Found data transfer item (kind: 'file', type: 'text/plain')
> FILE: /foo.txt ('text/plain', 28 bytes)"
> 
> https://build.webkit.org/builders/
> Apple%20iOS%2011%20Simulator%20Release%20WK2%20%28Tests%29/builds/219

I suspect this is because the custom pasteboard data is not enabled for these iOS 11 bots; we should ifdef this test out, like the other DataTransfer(Get|Set)Data tests in this file. We still have coverage on internal bots, and API tests are not run in EWS anyways.
Comment 18 Ryosuke Niwa 2017-10-02 14:41:49 PDT
The API tests have been skipped in https://trac.webkit.org/changeset/222743.