Changeset 223195 in webkit
- Timestamp:
- Oct 11, 2017, 12:01:10 PM (8 years ago)
- Location:
- trunk
- Files:
-
- 14 added
- 42 edited
-
LayoutTests/ChangeLog (modified) (1 diff)
-
LayoutTests/TestExpectations (modified) (1 diff)
-
LayoutTests/editing/pasteboard/data-transfer-get-data-on-copying-pasting-malformed-url-in-same-document-expected.txt (added)
-
LayoutTests/editing/pasteboard/data-transfer-get-data-on-copying-pasting-malformed-url-in-same-document.html (added)
-
LayoutTests/editing/pasteboard/data-transfer-get-data-on-drop-custom-expected.txt (modified) (1 diff)
-
LayoutTests/editing/pasteboard/data-transfer-get-data-on-paste-custom-expected.txt (modified) (1 diff)
-
LayoutTests/editing/pasteboard/data-transfer-set-data-ignore-copied-walformed-url-in-null-expected.txt (added)
-
LayoutTests/editing/pasteboard/data-transfer-set-data-ignore-copied-walformed-url-in-null-origin-expected.txt (added)
-
LayoutTests/editing/pasteboard/data-transfer-set-data-ignore-copied-walformed-url-in-null-origin.html (added)
-
LayoutTests/editing/pasteboard/data-transfer-set-data-sanitlize-url-when-copying-in-null-origin-expected.txt (added)
-
LayoutTests/editing/pasteboard/data-transfer-set-data-sanitlize-url-when-copying-in-null-origin.html (added)
-
LayoutTests/editing/pasteboard/data-transfer-set-data-sanitlize-url-when-dragging-in-null-origin-expected.txt (added)
-
LayoutTests/editing/pasteboard/data-transfer-set-data-sanitlize-url-when-dragging-in-null-origin.html (added)
-
LayoutTests/editing/pasteboard/dataTransfer-setData-getData-expected.txt (modified) (1 diff)
-
LayoutTests/editing/pasteboard/dataTransfer-setData-getData.html (modified) (4 diffs)
-
LayoutTests/http/tests/security/clipboard/copy-paste-url-across-origin-sanitizes-url-expected.txt (added)
-
LayoutTests/http/tests/security/clipboard/copy-paste-url-across-origin-sanitizes-url.html (added)
-
LayoutTests/http/tests/security/clipboard/resources/copy.html (added)
-
LayoutTests/platform/mac-wk1/TestExpectations (modified) (1 diff)
-
LayoutTests/platform/win/TestExpectations (modified) (1 diff)
-
Source/WebCore/ChangeLog (modified) (1 diff)
-
Source/WebCore/dom/DataTransfer.cpp (modified) (10 diffs)
-
Source/WebCore/dom/DataTransfer.h (modified) (3 diffs)
-
Source/WebCore/dom/Document.cpp (modified) (2 diffs)
-
Source/WebCore/dom/Document.h (modified) (2 diffs)
-
Source/WebCore/editing/Editor.cpp (modified) (4 diffs)
-
Source/WebCore/page/DragController.cpp (modified) (1 diff)
-
Source/WebCore/page/EventHandler.cpp (modified) (3 diffs)
-
Source/WebCore/platform/Pasteboard.h (modified) (5 diffs)
-
Source/WebCore/platform/PasteboardStrategy.h (modified) (1 diff)
-
Source/WebCore/platform/PlatformPasteboard.h (modified) (1 diff)
-
Source/WebCore/platform/StaticPasteboard.cpp (modified) (2 diffs)
-
Source/WebCore/platform/StaticPasteboard.h (modified) (2 diffs)
-
Source/WebCore/platform/cocoa/PasteboardCocoa.mm (modified) (2 diffs)
-
Source/WebCore/platform/gtk/PasteboardGtk.cpp (modified) (2 diffs)
-
Source/WebCore/platform/gtk/PlatformPasteboardGtk.cpp (modified) (1 diff)
-
Source/WebCore/platform/ios/PlatformPasteboardIOS.mm (modified) (6 diffs)
-
Source/WebCore/platform/mac/PlatformPasteboardMac.mm (modified) (1 diff)
-
Source/WebCore/platform/win/PasteboardWin.cpp (modified) (2 diffs)
-
Source/WebCore/platform/wpe/PasteboardWPE.cpp (modified) (2 diffs)
-
Source/WebCore/platform/wpe/PlatformPasteboardWPE.cpp (modified) (1 diff)
-
Source/WebKit/ChangeLog (modified) (1 diff)
-
Source/WebKit/UIProcess/Cocoa/WebPasteboardProxyCocoa.mm (modified) (1 diff)
-
Source/WebKit/UIProcess/WebPasteboardProxy.cpp (modified) (1 diff)
-
Source/WebKit/UIProcess/WebPasteboardProxy.h (modified) (1 diff)
-
Source/WebKit/UIProcess/WebPasteboardProxy.messages.in (modified) (1 diff)
-
Source/WebKit/WebProcess/WebCoreSupport/WebPlatformStrategies.cpp (modified) (1 diff)
-
Source/WebKit/WebProcess/WebCoreSupport/WebPlatformStrategies.h (modified) (1 diff)
-
Source/WebKitLegacy/mac/ChangeLog (modified) (1 diff)
-
Source/WebKitLegacy/mac/WebCoreSupport/WebPlatformStrategies.h (modified) (1 diff)
-
Source/WebKitLegacy/mac/WebCoreSupport/WebPlatformStrategies.mm (modified) (1 diff)
-
Tools/ChangeLog (modified) (1 diff)
-
Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj (modified) (6 diffs)
-
Tools/TestWebKitAPI/Tests/WebKitCocoa/CopyURL.mm (added)
-
Tools/TestWebKitAPI/Tests/WebKitCocoa/copy-url.html (added)
-
Tools/TestWebKitAPI/Tests/ios/DataInteractionTests.mm (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/LayoutTests/ChangeLog
r223193 r223195 1 2017-10-11 Ryosuke Niwa <rniwa@webkit.org> 2 3 Sanitize URL in pasteboard for other applications and cross origin content 4 https://bugs.webkit.org/show_bug.cgi?id=178060 5 <rdar://problem/34874518> 6 7 Reviewed by Wenson Hsieh. 8 9 Added tests for copying & pasting URLs. URLs should be %-escaped and any invalid URL should be stripped away and 10 invisible to a cross-origin content or a null origin document but the same origin content should have access to 11 its original form. 12 13 * TestExpectations: 14 * editing/pasteboard/data-transfer-get-data-on-copying-pasting-malformed-url-in-same-document-expected.txt: Added. 15 * editing/pasteboard/data-transfer-get-data-on-copying-pasting-malformed-url-in-same-document.html: Added. 16 * editing/pasteboard/data-transfer-get-data-on-drop-custom-expected.txt: Rebaselined. We no longer normalize 17 "https://www.apple.com" into "https://www.apple.com/" by NSURL / UIPasteboard within the same origin content. 18 * editing/pasteboard/data-transfer-get-data-on-paste-custom-expected.txt: Ditto. 19 * editing/pasteboard/data-transfer-set-data-ignore-copied-walformed-url-in-null-expected.txt: Added. 20 * editing/pasteboard/data-transfer-set-data-ignore-copied-walformed-url-in-null-origin-expected.txt: Added. 21 * editing/pasteboard/data-transfer-set-data-ignore-copied-walformed-url-in-null-origin.html: Added. 22 * editing/pasteboard/data-transfer-set-data-sanitlize-url-when-copying-in-null-origin-expected.txt: Added. 23 * editing/pasteboard/data-transfer-set-data-sanitlize-url-when-copying-in-null-origin.html: Added. 24 * editing/pasteboard/data-transfer-set-data-sanitlize-url-when-dragging-in-null-origin-expected.txt: Added. 25 * editing/pasteboard/data-transfer-set-data-sanitlize-url-when-dragging-in-null-origin.html: Added. 26 * editing/pasteboard/dataTransfer-setData-getData-expected.txt: Rebaselined. More test cases are passing. 27 * editing/pasteboard/dataTransfer-setData-getData.html: Updated expectations as the original URL is now preserved. 28 * http/tests/security/clipboard/copy-paste-url-across-origin-sanitizes-url-expected.txt: Added. 29 * http/tests/security/clipboard/copy-paste-url-across-origin-sanitizes-url.html: Added. 30 * http/tests/security/clipboard/resources/copy.html: Added. 31 * platform/mac-wk1/TestExpectations: 32 1 33 2017-10-11 Andy Estes <aestes@apple.com> 2 34 -
trunk/LayoutTests/TestExpectations
r223076 r223195 75 75 editing/pasteboard/data-transfer-get-data-on-drop-url.html [ Skip ] 76 76 editing/pasteboard/data-transfer-is-unique-for-dragenter-and-dragleave.html [ Skip ] 77 editing/pasteboard/data-transfer-set-data-sanitlize-url-when-dragging-in-null-origin.html [ Skip ] 77 78 editing/pasteboard/drag-end-crash-accessing-item-list.html [ Skip ] 78 79 editing/pasteboard/data-transfer-item-list-add-file-on-drag.html [ Skip ] -
trunk/LayoutTests/editing/pasteboard/data-transfer-get-data-on-drop-custom-expected.txt
r222595 r223195 15 15 "text/html": "<b>年年年</b>", 16 16 "bar/מקור השם עברית": "<i>מקור השם עברית</i>", 17 "text/uri-list": "https://www.apple.com /",17 "text/uri-list": "https://www.apple.com", 18 18 "baz/年年年": "https://www.webkit.org", 19 19 "text/rtf": "AAAAAAAAAAA" -
trunk/LayoutTests/editing/pasteboard/data-transfer-get-data-on-paste-custom-expected.txt
r222595 r223195 6 6 "text/html": "<b>年年年</b>", 7 7 "bar/מקור השם עברית": "<i>מקור השם עברית</i>", 8 "text/uri-list": "https://www.apple.com /",8 "text/uri-list": "https://www.apple.com", 9 9 "baz/年年年": "https://www.webkit.org", 10 10 "text/rtf": "AAAAAAAAAAA" -
trunk/LayoutTests/editing/pasteboard/dataTransfer-setData-getData-expected.txt
r223167 r223195 6 6 --- Test set/get 'URL': 7 7 PASS getDataResultType is "string" 8 PASS getDataResult is "http://test.com /"8 PASS getDataResult is "http://test.com" 9 9 --- Test set/get 'URL' with multiple URLs: 10 10 PASS getDataResultType is "string" 11 FAIL getDataResult should be http://test.com/. Was . 11 FAIL getDataResult should be http://test.com. Was http://test.com 12 http://check.com. 12 13 --- Test set/get 'text/uri-list': 13 14 PASS getDataResultType is "string" 14 FAIL getDataResult should be http://test.com 15 http://check.com. Was . 15 PASS getDataResult is "http://test.com\r\nhttp://check.com" 16 16 --- Test set/get 'text/uri-list' using '\n': 17 17 PASS getDataResultType is "string" 18 FAIL getDataResult should be http://test.com 19 http://check.com. Was . 18 PASS getDataResult is "http://test.com\nhttp://check.com" 20 19 --- Test set 'text/uri-list', get 'URL': 21 20 PASS getDataResultType is "string" 22 FAIL getDataResult should be http://test.com/. Was . 21 FAIL getDataResult should be http://test.com. Was http://test.com 22 http://check.com. 23 23 --- Test set 'URL', get 'text/uri-list': 24 24 PASS getDataResultType is "string" 25 FAIL getDataResult should be http://test.com 26 http://check.com. Was . 25 PASS getDataResult is "http://test.com\r\nhttp://check.com" 27 26 --- Test set 'text/uri-list', get 'URL', using only '\n': 28 27 PASS getDataResultType is "string" 29 FAIL getDataResult should be http://test.com/. Was . 28 FAIL getDataResult should be http://test.com. Was http://test.com 29 http://check.com. 30 30 --- Test set/get 'text/uri-list' with comments: 31 31 PASS getDataResultType is "string" 32 FAIL getDataResult should be # comment 33 http://test.com 34 http://check.com. Was . 32 PASS getDataResult is "# comment\r\nhttp://test.com\r\nhttp://check.com" 35 33 --- Test set 'text/uri-list', get 'URL' with comments: 36 34 PASS getDataResultType is "string" 37 FAIL getDataResult should be http://test.com/. Was . 35 FAIL getDataResult should be http://test.com. Was # comment 36 http://test.com 37 http://check.com. 38 38 --- Test set 'text/uri-list', get 'URL' with only comments: 39 39 PASS getDataResultType is "string" 40 PASS getDataResult is "" 40 FAIL getDataResult should be . Was # comment 41 # comment 2 42 # comment 3. 41 43 --- Test set/get 'text/plain': 42 44 PASS getDataResultType is "string" -
trunk/LayoutTests/editing/pasteboard/dataTransfer-setData-getData.html
r217390 r223195 86 86 debug("--- Test set/get 'URL':"); 87 87 test("URL", "http://test.com", 88 "URL", "http://test.com /");88 "URL", "http://test.com"); 89 89 90 90 debug("--- Test set/get 'URL' with multiple URLs:"); 91 91 test("URL", "http://test.com\r\nhttp://check.com", 92 "URL", "http://test.com /");92 "URL", "http://test.com"); 93 93 94 94 debug("--- Test set/get 'text/uri-list':"); … … 102 102 debug("--- Test set 'text/uri-list', get 'URL':"); 103 103 test("text/uri-list", "http://test.com\r\nhttp://check.com", 104 "URL", "http://test.com /");104 "URL", "http://test.com"); 105 105 106 106 debug("--- Test set 'URL', get 'text/uri-list':"); … … 110 110 debug("--- Test set 'text/uri-list', get 'URL', using only '\\n':"); 111 111 test("text/uri-list", "http://test.com\nhttp://check.com", 112 "URL", "http://test.com /");112 "URL", "http://test.com"); 113 113 114 114 debug("--- Test set/get 'text/uri-list' with comments:"); … … 118 118 debug("--- Test set 'text/uri-list', get 'URL' with comments:"); 119 119 test("text/uri-list", "# comment\r\nhttp://test.com\r\nhttp://check.com", 120 "URL", "http://test.com /");120 "URL", "http://test.com"); 121 121 122 122 debug("--- Test set 'text/uri-list', get 'URL' with only comments:"); -
trunk/LayoutTests/platform/mac-wk1/TestExpectations
r223189 r223195 13 13 editing/pasteboard/data-transfer-get-data-on-drop-url.html [ Pass ] 14 14 editing/pasteboard/data-transfer-is-unique-for-dragenter-and-dragleave.html [ Pass ] 15 editing/pasteboard/data-transfer-set-data-sanitlize-url-when-dragging-in-null-origin.html [ Pass ] 15 16 editing/pasteboard/drag-end-crash-accessing-item-list.html [ Pass ] 16 17 editing/pasteboard/data-transfer-item-list-add-file-on-drag.html [ Pass ] -
trunk/LayoutTests/platform/win/TestExpectations
r223189 r223195 1133 1133 [ Debug ] editing/selection/4983858.html [ Skip ] # Debug Assertion 1134 1134 [ Debug ] editing/selection/4975120.html [ Skip ] # Debug Assertion 1135 1136 # Custom pasteboard data is not supported on Windows. 1137 http/tests/security/clipboard/copy-paste-url-across-origin-sanitizes-url.html 1135 1138 1136 1139 webkit.org/b/140783 [ Release ] editing/pasteboard/copy-standalone-image.html [ Failure ImageOnlyFailure ] -
trunk/Source/WebCore/ChangeLog
r223194 r223195 1 2017-10-11 Ryosuke Niwa <rniwa@webkit.org> 2 3 Sanitize URL in pasteboard for other applications and cross origin content 4 https://bugs.webkit.org/show_bug.cgi?id=178060 5 <rdar://problem/34874518> 6 7 Reviewed by Wenson Hsieh. 8 9 This patch introduces the sanitization of URL when written from a web content to prevent web content from 10 exploiting the URL parser of other applications in the system particularly of those that actively monitor 11 system pasteboard (a.k.a. clipboard on non-Cocoa platforms) and decode or otherwise process URLs. 12 13 Because the Web compatibility requires that DataTransfer exposes the original URL to any document in the 14 same origin as the one which wrote the URL into the pasteboard, we store a string which uniquely identifies 15 the origin of an originating document into our custom pasteboard data. Note that we expose any URL which 16 didn't come from WebKit since we don't expect URLs to reveal privacy sensitive information. We use UUID for 17 the origin identifier of a null origin document. 18 19 An alternative approach is to store the pasteboard data from the same origin into the document and invalidate 20 it when the system pasteboard changes. However, Pasteboard object cannot know about Document (as Pasteboard 21 is a platform object and Document is a WebCore object), this turns out be quite tricky as there are multiple 22 places where we create Pasteboard objects, and they all need to be aware of this special same origin 23 Pasteboard object that hangs off of Document. Also, this approach would result in the same origin code paths 24 to diverge between null origin and non-null origin documents. 25 26 Tests: editing/pasteboard/data-transfer-get-data-on-copying-pasting-malformed-url-in-same-document.html 27 editing/pasteboard/data-transfer-set-data-ignore-copied-walformed-url-in-null-origin.html 28 editing/pasteboard/data-transfer-set-data-sanitlize-url-when-copying-in-null-origin.html 29 editing/pasteboard/data-transfer-set-data-sanitlize-url-when-dragging-in-null-origin.html 30 http/tests/security/clipboard/copy-paste-url-across-origin-sanitizes-url.html 31 CopyURL.ValidURL 32 CopyURL.UnescapedURL 33 CopyURL.MalformedURL 34 DataInteractionTests.DataTransferSetDataValidURL 35 DataInteractionTests.DataTransferSetDataUnescapedURL 36 DataInteractionTests.DataTransferSetDataInvalidURL 37 38 * dom/DataTransfer.cpp: 39 (WebCore::originForDocument): Extracted from createForCopyAndPaste. 40 (WebCore::DataTransfer::createForCopyAndPaste): 41 (WebCore::DataTransfer::getDataForItem const): Read the URL from the custom data when the originating content 42 is of the same origin. When the originating content is cross origin, or there is no custom data (e.g. written 43 by another native application; or sanitization didn't result in any difference), then callback to native value. 44 (WebCore::DataTransfer::setDataFromItemList): Sanitize the URL before writing it to the native pasteboard. 45 Store the original value if the sanitization resulted in any difference. 46 (WebCore::DataTransfer::types const): 47 (WebCore::DataTransfer::commitToPasteboard): Moved the code to write custom data to Pasteboard since we need 48 to write the origin string with it. 49 (WebCore::DataTransfer::createForDragStartEvent): Added Document as an argument to compute the origin string. 50 (WebCore::DataTransfer::createForDrop): Ditto. 51 (WebCore::DataTransfer::createForUpdatingDropTarget): 52 (WebCore::DataTransfer::moveDragState): 53 * dom/DataTransfer.h: 54 * dom/Document.cpp: 55 (WebCore::Document::uniqueIdentifier): Added. See above. 56 * dom/Document.h: 57 * editing/Editor.cpp: 58 (WebCore::createDataTransferForClipboardEvent): 59 (WebCore::dispatchClipboardEvent): 60 * page/DragController.cpp: 61 (WebCore::DragController::dispatchTextInputEventFor): 62 * page/EventHandler.cpp: 63 (WebCore::EventHandler::performDragAndDrop): 64 (WebCore::EventHandler::handleDrag): 65 * platform/Pasteboard.h: 66 * platform/PasteboardStrategy.h: 67 * platform/PlatformPasteboard.h: 68 * platform/StaticPasteboard.cpp: 69 (WebCore::StaticPasteboard::takeCustomData): Moved the logic to write to native pasteboard to DataTransfer. 70 * platform/StaticPasteboard.h: 71 * platform/cocoa/PasteboardCocoa.mm: 72 (WebCore::Pasteboard::typesSafeForBindings): 73 (WebCore::Pasteboard::readStringInCustomData): Rewritten using readCustomData. See below. 74 (WebCore::Pasteboard::readOrigin): Added. 75 (WebCore::Pasteboard::readCustomData): Added. Populates the cache. Because a single Pasteboard object is never 76 allowed to read values once its content is updated by other applications, we can permanently cache the result. 77 * platform/gtk/PasteboardGtk.cpp: 78 (WebCore::Pasteboard::typesSafeForBindings): Now takes the unused origin string. 79 (WebCore::Pasteboard::readOrigin): Added. 80 * platform/gtk/PlatformPasteboardGtk.cpp: 81 (WebCore::PlatformPasteboard::typesSafeForDOMToReadAndWrite const): Now takes the unused origin string. 82 * platform/ios/PlatformPasteboardIOS.mm: 83 (WebCore::originKeyKeyForTeamData): Added. 84 (WebCore::customTypesKeyForTeamData): Added. Replaces the use of PasteboardCustomData::cocoaType() in the team 85 data for clarity since the team data key isn't same as the pasteboard type. We don't have to worry about the 86 backwards compatibility since drag & drop session doesn't persist across iOS upgrades, and there is no publicly 87 released iOS with this team data support. 88 (WebCore::PlatformPasteboard::typesSafeForDOMToReadAndWrite const): Read the origin string and the custom data 89 off the team data. Don't expose custom types that are written by cross origin documents. 90 (WebCore::PlatformPasteboard::write): Add the orign string with custom pasteboard types in the team data. 91 (WebCore::PlatformPasteboard::readURL): Fixed a bug that this function was not reading NSURL when UIPasteboard 92 serializes NSURL as a plist. This code is exercised by CopyURL.ValidURL. 93 * platform/mac/PlatformPasteboardMac.mm: 94 (WebCore::PlatformPasteboard::typesSafeForDOMToReadAndWrite const): Don't add custom pasteboard types that are 95 added by cross origin documents. 96 * platform/win/PasteboardWin.cpp: 97 (WebCore::Pasteboard::typesSafeForBindings): Now takes the unused origin string. 98 (WebCore::Pasteboard::readOrigin): Added. 99 * platform/wpe/PasteboardWPE.cpp: 100 (WebCore::Pasteboard::typesSafeForBindings): Now takes the unused origin string. 101 (WebCore::Pasteboard::readOrigin): Added. 102 * platform/wpe/PlatformPasteboardWPE.cpp: 103 (WebCore::PlatformPasteboard::typesSafeForDOMToReadAndWrite const): Now takes the unused origin string. 104 1 105 2017-10-11 Antti Koivisto <antti@apple.com> 2 106 -
trunk/Source/WebCore/dom/DataTransfer.cpp
r223034 r223195 42 42 #include "Settings.h" 43 43 #include "StaticPasteboard.h" 44 #include "URLParser.h" 44 45 #include "WebCorePasteboardFileReader.h" 45 46 … … 78 79 } 79 80 80 Ref<DataTransfer> DataTransfer::createForCopyAndPaste(StoreMode storeMode, std::unique_ptr<Pasteboard>&& pasteboard) 81 { 82 return adoptRef(*new DataTransfer(storeMode, WTFMove(pasteboard))); 81 static String originIdentifierForDocument(Document& document) 82 { 83 auto origin = document.securityOrigin().toString(); 84 if (origin == "null") 85 return document.uniqueIdentifier(); 86 return origin; 87 } 88 89 Ref<DataTransfer> DataTransfer::createForCopyAndPaste(Document& document, StoreMode storeMode, std::unique_ptr<Pasteboard>&& pasteboard) 90 { 91 auto dataTransfer = adoptRef(*new DataTransfer(storeMode, WTFMove(pasteboard))); 92 dataTransfer->m_originIdentifier = originIdentifierForDocument(document); 93 return dataTransfer; 83 94 } 84 95 … … 122 133 } 123 134 124 static bool shouldReadOrWriteTypeAsCustomData(const String& type)125 {126 return Settings::customPasteboardDataEnabled() && !Pasteboard::isSafeTypeForDOMToReadAndWrite(type);127 }128 129 135 void DataTransfer::clearData(const String& type) 130 136 { … … 150 156 151 157 auto lowercaseType = stripLeadingAndTrailingHTMLSpaces(type).convertToASCIILowercase(); 152 if (shouldReadOrWriteTypeAsCustomData(lowercaseType)) 153 return m_pasteboard->readStringInCustomData(lowercaseType); 154 return m_pasteboard->readString(lowercaseType); 158 if (!Settings::customPasteboardDataEnabled()) 159 return m_pasteboard->readString(lowercaseType); 160 161 bool isSameOrigin = false; 162 if (is<StaticPasteboard>(*m_pasteboard)) { 163 // StaticPasteboard is only used to stage data written by websites before being committed to the system pasteboard. 164 isSameOrigin = true; 165 } else if (!m_originIdentifier.isNull()) { 166 String originOfPasteboard = m_pasteboard->readOrigin(); 167 isSameOrigin = m_originIdentifier == originOfPasteboard; 168 } 169 170 if (!isSameOrigin) { 171 if (!Pasteboard::isSafeTypeForDOMToReadAndWrite(lowercaseType)) 172 return { }; 173 return m_pasteboard->readString(lowercaseType); 174 } 175 176 String value = m_pasteboard->readStringInCustomData(lowercaseType); 177 if (value.isNull() && Pasteboard::isSafeTypeForDOMToReadAndWrite(lowercaseType)) 178 value = m_pasteboard->readString(lowercaseType); 179 return value; 155 180 } 156 181 … … 179 204 RELEASE_ASSERT(is<StaticPasteboard>(*m_pasteboard)); 180 205 181 if (shouldReadOrWriteTypeAsCustomData(type)) 206 if (!Settings::customPasteboardDataEnabled()) { 207 m_pasteboard->writeString(type, data); 208 return; 209 } 210 211 String sanitizedData; 212 if (type == "text/uri-list") { 213 auto url = URLParser(data).result(); 214 if (url.isValid()) 215 sanitizedData = url.string(); 216 } else if (type == "text/plain") 217 sanitizedData = data; // Nothing to sanitize. 218 219 if (sanitizedData != data) 182 220 downcast<StaticPasteboard>(*m_pasteboard).writeStringInCustomData(type, data); 183 else 184 m_pasteboard->writeString(type, data); 221 222 if (Pasteboard::isSafeTypeForDOMToReadAndWrite(type) && !sanitizedData.isNull()) 223 m_pasteboard->writeString(type, sanitizedData); 185 224 } 186 225 … … 237 276 238 277 if (m_pasteboard->containsFiles()) { 239 ASSERT(!m_pasteboard->typesSafeForBindings( ).contains("Files"));278 ASSERT(!m_pasteboard->typesSafeForBindings(m_originIdentifier).contains("Files")); 240 279 return addFilesType == AddFilesType::Yes ? Vector<String> { ASCIILiteral("Files") } : Vector<String> { }; 241 280 } 242 281 243 auto types = m_pasteboard->typesSafeForBindings( );282 auto types = m_pasteboard->typesSafeForBindings(m_originIdentifier); 244 283 ASSERT(!types.contains("Files")); 245 284 return types; … … 323 362 } 324 363 364 void DataTransfer::commitToPasteboard(Pasteboard& nativePasteboard) 365 { 366 ASSERT(is<StaticPasteboard>(*m_pasteboard) && !is<StaticPasteboard>(nativePasteboard)); 367 PasteboardCustomData customData = downcast<StaticPasteboard>(*m_pasteboard).takeCustomData(); 368 if (Settings::customPasteboardDataEnabled()) { 369 customData.origin = m_originIdentifier; 370 nativePasteboard.writeCustomData(customData); 371 return; 372 } 373 374 for (auto& entry : customData.platformData) 375 nativePasteboard.writeString(entry.key, entry.value); 376 for (auto& entry : customData.sameOriginCustomData) 377 nativePasteboard.writeString(entry.key, entry.value); 378 } 379 325 380 #if !ENABLE(DRAG_SUPPORT) 326 381 … … 354 409 } 355 410 356 Ref<DataTransfer> DataTransfer::createForDragStartEvent() 357 { 358 return adoptRef(*new DataTransfer(StoreMode::ReadWrite, std::make_unique<StaticPasteboard>(), Type::DragAndDropData)); 359 } 360 361 Ref<DataTransfer> DataTransfer::createForDrop(std::unique_ptr<Pasteboard>&& pasteboard, DragOperation sourceOperation, bool draggingFiles) 411 Ref<DataTransfer> DataTransfer::createForDragStartEvent(Document& document) 412 { 413 auto dataTransfer = adoptRef(*new DataTransfer(StoreMode::ReadWrite, std::make_unique<StaticPasteboard>(), Type::DragAndDropData)); 414 dataTransfer->m_originIdentifier = originIdentifierForDocument(document); 415 return dataTransfer; 416 } 417 418 Ref<DataTransfer> DataTransfer::createForDrop(Document& document, std::unique_ptr<Pasteboard>&& pasteboard, DragOperation sourceOperation, bool draggingFiles) 362 419 { 363 420 auto dataTransfer = adoptRef(*new DataTransfer(DataTransfer::StoreMode::Readonly, WTFMove(pasteboard), draggingFiles ? Type::DragAndDropFiles : Type::DragAndDropData)); 364 421 dataTransfer->setSourceOperation(sourceOperation); 422 dataTransfer->m_originIdentifier = originIdentifierForDocument(document); 365 423 return dataTransfer; 366 424 } … … 377 435 auto dataTransfer = adoptRef(*new DataTransfer(mode, WTFMove(pasteboard), draggingFiles ? Type::DragAndDropFiles : Type::DragAndDropData)); 378 436 dataTransfer->setSourceOperation(sourceOperation); 437 dataTransfer->m_originIdentifier = originIdentifierForDocument(document); 379 438 return dataTransfer; 380 439 } … … 590 649 // contain data that was in the static pasteboard. 591 650 m_pasteboard->clear(); 592 downcast<StaticPasteboard>(other->pasteboard()).commitToPasteboard(*m_pasteboard);651 other->commitToPasteboard(*m_pasteboard); 593 652 594 653 m_dropEffect = other->m_dropEffect; -
trunk/Source/WebCore/dom/DataTransfer.h
r223034 r223195 46 46 enum class StoreMode { Invalid, ReadWrite, Readonly, Protected }; 47 47 48 static Ref<DataTransfer> createForCopyAndPaste( StoreMode, std::unique_ptr<Pasteboard>&&);48 static Ref<DataTransfer> createForCopyAndPaste(Document&, StoreMode, std::unique_ptr<Pasteboard>&&); 49 49 static Ref<DataTransfer> createForInputEvent(const String& plainText, const String& htmlText); 50 50 … … 83 83 84 84 Pasteboard& pasteboard() { return *m_pasteboard; } 85 void commitToPasteboard(Pasteboard&); 85 86 86 87 #if ENABLE(DRAG_SUPPORT) 87 88 static Ref<DataTransfer> createForDrag(); 88 static Ref<DataTransfer> createForDragStartEvent( );89 static Ref<DataTransfer> createForDrop( std::unique_ptr<Pasteboard>&&, DragOperation, bool draggingFiles);89 static Ref<DataTransfer> createForDragStartEvent(Document&); 90 static Ref<DataTransfer> createForDrop(Document&, std::unique_ptr<Pasteboard>&&, DragOperation, bool draggingFiles); 90 91 static Ref<DataTransfer> createForUpdatingDropTarget(Document&, std::unique_ptr<Pasteboard>&&, DragOperation, bool draggingFiles); 91 92 … … 125 126 Vector<Ref<File>> filesFromPasteboardAndItemList() const; 126 127 128 String m_originIdentifier; 127 129 StoreMode m_storeMode; 128 130 std::unique_ptr<Pasteboard> m_pasteboard; -
trunk/Source/WebCore/dom/Document.cpp
r223149 r223195 214 214 #include <wtf/SetForScope.h> 215 215 #include <wtf/SystemTracing.h> 216 #include <wtf/UUID.h> 216 217 #include <wtf/text/StringBuffer.h> 217 218 #include <yarr/RegularExpression.h> … … 5304 5305 #endif 5305 5306 5307 String Document::uniqueIdentifier() 5308 { 5309 if (!m_uniqueIdentifier) 5310 m_uniqueIdentifier = "null:" + createCanonicalUUIDString(); 5311 return m_uniqueIdentifier; 5312 } 5313 5306 5314 ExceptionOr<Ref<XPathExpression>> Document::createExpression(const String& expression, RefPtr<XPathNSResolver>&& resolver) 5307 5315 { -
trunk/Source/WebCore/dom/Document.h
r223049 r223195 958 958 uint64_t domTreeVersion() const { return m_domTreeVersion; } 959 959 960 String uniqueIdentifier(); 961 960 962 // XPathEvaluator methods 961 963 WEBCORE_EXPORT ExceptionOr<Ref<XPathExpression>> createExpression(const String& expression, RefPtr<XPathNSResolver>&&); … … 1518 1520 uint64_t m_domTreeVersion; 1519 1521 static uint64_t s_globalTreeVersion; 1520 1522 1523 String m_uniqueIdentifier; 1524 1521 1525 HashSet<NodeIterator*> m_nodeIterators; 1522 1526 HashSet<Range*> m_ranges; -
trunk/Source/WebCore/editing/Editor.cpp
r222956 r223195 346 346 } 347 347 348 static Ref<DataTransfer> createDataTransferForClipboardEvent( ClipboardEventKind kind)348 static Ref<DataTransfer> createDataTransferForClipboardEvent(Document& document, ClipboardEventKind kind) 349 349 { 350 350 switch (kind) { 351 351 case ClipboardEventKind::Copy: 352 352 case ClipboardEventKind::Cut: 353 return DataTransfer::createForCopyAndPaste( DataTransfer::StoreMode::ReadWrite, std::make_unique<StaticPasteboard>());353 return DataTransfer::createForCopyAndPaste(document, DataTransfer::StoreMode::ReadWrite, std::make_unique<StaticPasteboard>()); 354 354 case ClipboardEventKind::PasteAsPlainText: 355 355 if (Settings::customPasteboardDataEnabled()) { … … 358 358 auto pasteboard = std::make_unique<StaticPasteboard>(); 359 359 pasteboard->writeString(plainTextType, plainText); 360 return DataTransfer::createForCopyAndPaste( DataTransfer::StoreMode::Readonly, WTFMove(pasteboard));360 return DataTransfer::createForCopyAndPaste(document, DataTransfer::StoreMode::Readonly, WTFMove(pasteboard)); 361 361 } 362 362 FALLTHROUGH; 363 363 case ClipboardEventKind::Paste: 364 return DataTransfer::createForCopyAndPaste( DataTransfer::StoreMode::Readonly, Pasteboard::createForCopyAndPaste());364 return DataTransfer::createForCopyAndPaste(document, DataTransfer::StoreMode::Readonly, Pasteboard::createForCopyAndPaste()); 365 365 case ClipboardEventKind::BeforeCopy: 366 366 case ClipboardEventKind::BeforeCut: 367 367 case ClipboardEventKind::BeforePaste: 368 return DataTransfer::createForCopyAndPaste( DataTransfer::StoreMode::Invalid, std::make_unique<StaticPasteboard>());368 return DataTransfer::createForCopyAndPaste(document, DataTransfer::StoreMode::Invalid, std::make_unique<StaticPasteboard>()); 369 369 } 370 370 ASSERT_NOT_REACHED(); 371 return DataTransfer::createForCopyAndPaste( DataTransfer::StoreMode::Invalid, std::make_unique<StaticPasteboard>());371 return DataTransfer::createForCopyAndPaste(document, DataTransfer::StoreMode::Invalid, std::make_unique<StaticPasteboard>()); 372 372 } 373 373 … … 381 381 return true; 382 382 383 auto dataTransfer = createDataTransferForClipboardEvent( kind);383 auto dataTransfer = createDataTransferForClipboardEvent(target->document(), kind); 384 384 385 385 ClipboardEvent::Init init; … … 394 394 auto pasteboard = Pasteboard::createForCopyAndPaste(); 395 395 pasteboard->clear(); 396 d owncast<StaticPasteboard>(dataTransfer->pasteboard()).commitToPasteboard(*pasteboard);396 dataTransfer->commitToPasteboard(*pasteboard); 397 397 } 398 398 -
trunk/Source/WebCore/page/DragController.cpp
r223031 r223195 507 507 String text = m_page.dragCaretController().isContentRichlyEditable() ? emptyString() : dragData.asPlainText(); 508 508 Element* target = innerFrame->editor().findEventTargetFrom(m_page.dragCaretController().caretPosition()); 509 // FIXME: What guarantees target is not null? 509 510 return target->dispatchEvent(TextEvent::createForDrop(innerFrame->document()->domWindow(), text)); 510 511 } -
trunk/Source/WebCore/page/EventHandler.cpp
r223031 r223195 2390 2390 preventedDefault = targetFrame->eventHandler().performDragAndDrop(event, WTFMove(pasteboard), sourceOperation, draggingFiles); 2391 2391 } else if (m_dragTarget) { 2392 auto dataTransfer = DataTransfer::createForDrop( WTFMove(pasteboard), sourceOperation, draggingFiles);2392 auto dataTransfer = DataTransfer::createForDrop(m_dragTarget->document(), WTFMove(pasteboard), sourceOperation, draggingFiles); 2393 2393 preventedDefault = dispatchDragEvent(eventNames().dropEvent, *m_dragTarget, event, dataTransfer); 2394 2394 dataTransfer->makeInvalidForSecurity(); … … 3641 3641 if (!m_mouseDownMayStartDrag) 3642 3642 return !mouseDownMayStartSelect() && !m_mouseDownMayStartAutoscroll; 3643 3643 ASSERT(dragState().source); 3644 3644 3645 if (!ExactlyOneBitSet(dragState().type)) { 3645 3646 ASSERT((dragState().type & DragSourceActionSelection)); … … 3678 3679 3679 3680 if (dragState().shouldDispatchEvents) { 3680 auto dragStartDataTransfer = DataTransfer::createForDragStartEvent(); 3681 ASSERT(dragState().source); 3682 auto dragStartDataTransfer = DataTransfer::createForDragStartEvent(dragState().source->document()); 3681 3683 m_mouseDownMayStartDrag = dispatchDragStartEventOnSourceElement(dragStartDataTransfer); 3682 3684 hasNonDefaultPasteboardData = dragStartDataTransfer->pasteboard().hasData() ? HasNonDefaultPasteboardData::Yes : HasNonDefaultPasteboardData::No; -
trunk/Source/WebCore/platform/Pasteboard.h
r223140 r223195 194 194 195 195 virtual bool hasData(); 196 virtual Vector<String> typesSafeForBindings( );196 virtual Vector<String> typesSafeForBindings(const String& origin); 197 197 virtual Vector<String> typesForLegacyUnsafeBindings(); 198 virtual String readOrigin(); 198 199 virtual String readString(const String& type); 199 200 virtual String readStringInCustomData(const String& type); … … 212 213 virtual void write(const PasteboardWebContent&); 213 214 215 virtual void writeCustomData(const PasteboardCustomData&); 216 214 217 virtual bool containsFiles(); 215 218 virtual bool canSmartReplace(); … … 251 254 const String& name() const { return m_pasteboardName; } 252 255 long changeCount() const; 256 const PasteboardCustomData& readCustomData(); 253 257 #endif 254 258 … … 262 266 #endif 263 267 264 void writeCustomData(const PasteboardCustomData&);265 266 268 private: 267 269 #if PLATFORM(IOS) … … 296 298 String m_pasteboardName; 297 299 long m_changeCount; 300 std::optional<PasteboardCustomData> m_customDataCache; 298 301 #endif 299 302 -
trunk/Source/WebCore/platform/PasteboardStrategy.h
r222595 r223195 73 73 #endif 74 74 75 virtual Vector<String> typesSafeForDOMToReadAndWrite(const String& pasteboardName ) = 0;75 virtual Vector<String> typesSafeForDOMToReadAndWrite(const String& pasteboardName, const String& origin) = 0; 76 76 virtual long writeCustomData(const PasteboardCustomData&, const String& pasteboardName) = 0; 77 77 -
trunk/Source/WebCore/platform/PlatformPasteboard.h
r222595 r223195 96 96 97 97 WEBCORE_EXPORT long write(const PasteboardCustomData&); 98 WEBCORE_EXPORT Vector<String> typesSafeForDOMToReadAndWrite( ) const;98 WEBCORE_EXPORT Vector<String> typesSafeForDOMToReadAndWrite(const String& origin) const; 99 99 100 100 #if PLATFORM(GTK) -
trunk/Source/WebCore/platform/StaticPasteboard.cpp
r222964 r223195 26 26 #include "config.h" 27 27 #include "StaticPasteboard.h" 28 29 #include "Settings.h"30 #include "SharedBuffer.h"31 28 32 29 namespace WebCore { … … 86 83 } 87 84 88 void StaticPasteboard::commitToPasteboard(Pasteboard& pasteboard)85 PasteboardCustomData StaticPasteboard::takeCustomData() 89 86 { 90 if (m_platformData.isEmpty() && m_customData.isEmpty()) 91 return; 92 93 if (Settings::customPasteboardDataEnabled()) { 94 pasteboard.writeCustomData({ { }, WTFMove(m_types), WTFMove(m_platformData), WTFMove(m_customData) }); 95 return; 96 } 97 98 for (auto& entry : m_platformData) 99 pasteboard.writeString(entry.key, entry.value); 100 for (auto& entry : m_customData) 101 pasteboard.writeString(entry.key, entry.value); 87 return { { }, WTFMove(m_types), WTFMove(m_platformData), WTFMove(m_customData) }; 102 88 } 103 89 -
trunk/Source/WebCore/platform/StaticPasteboard.h
r222964 r223195 37 37 StaticPasteboard(); 38 38 39 void commitToPasteboard(Pasteboard&);39 PasteboardCustomData takeCustomData(); 40 40 41 41 bool isStatic() const final { return true; } 42 42 43 43 bool hasData() final; 44 Vector<String> typesSafeForBindings( ) final { return m_types; }44 Vector<String> typesSafeForBindings(const String&) final { return m_types; } 45 45 Vector<String> typesForLegacyUnsafeBindings() final { return m_types; } 46 String readOrigin() final { return { }; } 46 47 String readString(const String& type) final; 47 48 String readStringInCustomData(const String& type) final; … … 58 59 void write(const PasteboardImage&) final { } 59 60 void write(const PasteboardWebContent&) final { } 61 62 void writeCustomData(const PasteboardCustomData&) final { } 60 63 61 64 bool containsFiles() final { return false; } -
trunk/Source/WebCore/platform/cocoa/PasteboardCocoa.mm
r223167 r223195 144 144 } 145 145 146 Vector<String> Pasteboard::typesSafeForBindings( )147 { 148 Vector<String> types = platformStrategies()->pasteboardStrategy()->typesSafeForDOMToReadAndWrite(m_pasteboardName );146 Vector<String> Pasteboard::typesSafeForBindings(const String& origin) 147 { 148 Vector<String> types = platformStrategies()->pasteboardStrategy()->typesSafeForDOMToReadAndWrite(m_pasteboardName, origin); 149 149 150 150 // Enforce changeCount ourselves for security. We check after reading instead of before to be … … 217 217 String Pasteboard::readStringInCustomData(const String& type) 218 218 { 219 auto buffer = readBufferForTypeWithSecurityCheck(PasteboardCustomData::cocoaType()); 220 if (!buffer) 221 return { }; 222 223 // Enforce changeCount ourselves for security. We check after reading instead of before to be 224 // sure it doesn't change between our testing the change count and accessing the data. 225 if (m_changeCount != platformStrategies()->pasteboardStrategy()->changeCount(m_pasteboardName)) 226 return { }; 227 228 return PasteboardCustomData::fromSharedBuffer(*buffer).sameOriginCustomData.get(type); 219 return readCustomData().sameOriginCustomData.get(type); 220 } 221 222 String Pasteboard::readOrigin() 223 { 224 return readCustomData().origin; 225 } 226 227 const PasteboardCustomData& Pasteboard::readCustomData() 228 { 229 if (m_customDataCache) 230 return *m_customDataCache; 231 232 if (auto buffer = readBufferForTypeWithSecurityCheck(PasteboardCustomData::cocoaType())) 233 m_customDataCache = PasteboardCustomData::fromSharedBuffer(*buffer); 234 else 235 m_customDataCache = PasteboardCustomData { }; 236 return *m_customDataCache; 229 237 } 230 238 -
trunk/Source/WebCore/platform/gtk/PasteboardGtk.cpp
r222702 r223195 256 256 } 257 257 258 Vector<String> Pasteboard::typesSafeForBindings( )258 Vector<String> Pasteboard::typesSafeForBindings(const String&) 259 259 { 260 260 notImplemented(); // webkit.org/b/177633: [GTK] Move to new Pasteboard API … … 285 285 286 286 return types; 287 } 288 289 String Pasteboard::readOrigin() 290 { 291 notImplemented(); // webkit.org/b/177633: [GTK] Move to new Pasteboard API 292 return { }; 287 293 } 288 294 -
trunk/Source/WebCore/platform/gtk/PlatformPasteboardGtk.cpp
r222595 r223195 47 47 } 48 48 49 Vector<String> PlatformPasteboard::typesSafeForDOMToReadAndWrite( ) const49 Vector<String> PlatformPasteboard::typesSafeForDOMToReadAndWrite(const String&) const 50 50 { 51 51 return { }; -
trunk/Source/WebCore/platform/ios/PlatformPasteboardIOS.mm
r222761 r223195 344 344 } 345 345 346 Vector<String> PlatformPasteboard::typesSafeForDOMToReadAndWrite() const 346 static const char originKeyForTeamData[] = "com.apple.WebKit.drag-and-drop-team-data.origin"; 347 static const char customTypesKeyForTeamData[] = "com.apple.WebKit.drag-and-drop-team-data.custom-types"; 348 349 Vector<String> PlatformPasteboard::typesSafeForDOMToReadAndWrite(const String& origin) const 347 350 { 348 351 ListHashSet<String> domPasteboardTypes; … … 355 358 continue; 356 359 357 id customTypes = [(NSDictionary *)teamDataObject objectForKey:@(PasteboardCustomData::cocoaType())]; 360 id originInTeamData = [(NSDictionary *)teamDataObject objectForKey:@(originKeyForTeamData)]; 361 if (![originInTeamData isKindOfClass:[NSString class]]) 362 continue; 363 if (String((NSString *)originInTeamData) != origin) 364 continue; 365 366 id customTypes = [(NSDictionary *)teamDataObject objectForKey:@(customTypesKeyForTeamData)]; 358 367 if (![customTypes isKindOfClass:[NSArray class]]) 359 368 continue; … … 364 373 365 374 if (NSData *serializedCustomData = [m_pasteboard dataForPasteboardType:@(PasteboardCustomData::cocoaType())]) { 366 auto buffer = SharedBuffer::create(serializedCustomData); 367 for (auto& type : PasteboardCustomData::fromSharedBuffer(buffer.get()).orderedTypes) 368 domPasteboardTypes.add(type); 375 auto data = PasteboardCustomData::fromSharedBuffer(SharedBuffer::create(serializedCustomData).get()); 376 if (data.origin == origin) { 377 for (auto& type : data.orderedTypes) 378 domPasteboardTypes.add(type); 379 } 369 380 } 370 381 … … 403 414 for (auto& type : data.orderedTypes) 404 415 [typesAsNSArray addObject:type]; 405 [representationsToRegister setTeamData:[NSKeyedArchiver archivedDataWithRootObject:@{ @(PasteboardCustomData::cocoaType()) : typesAsNSArray }]]; 416 [representationsToRegister setTeamData:[NSKeyedArchiver archivedDataWithRootObject:@{ 417 @(originKeyForTeamData) : data.origin, @(customTypesKeyForTeamData) : typesAsNSArray }]]; 406 418 [representationsToRegister addData:serializedSharedBuffer.get() forType:@(PasteboardCustomData::cocoaType())]; 407 419 } … … 449 461 } 450 462 451 Vector<String> PlatformPasteboard::typesSafeForDOMToReadAndWrite( ) const463 Vector<String> PlatformPasteboard::typesSafeForDOMToReadAndWrite(const String&) const 452 464 { 453 465 return { }; … … 517 529 { 518 530 NSIndexSet *indexSet = [NSIndexSet indexSetWithIndex:index]; 519 520 531 RetainPtr<NSArray> pasteboardItem = [m_pasteboard valuesForPasteboardType:type inItemSet:indexSet]; 521 532 522 533 if (![pasteboardItem count]) 523 return URL();534 return { }; 524 535 525 536 id value = [pasteboardItem objectAtIndex:0]; 526 ASSERT([value isKindOfClass:[NSURL class]]); 527 if (![value isKindOfClass:[NSURL class]]) 528 return URL(); 529 530 if (!allowReadingURLAtIndex((NSURL *)value, index)) 537 NSURL *url = nil; 538 if ([value isKindOfClass:[NSData class]]) { 539 id plist = [NSPropertyListSerialization propertyListWithData:(NSData *)value options:NSPropertyListImmutable format:NULL error:NULL]; 540 if (![plist isKindOfClass:[NSArray class]]) 541 return { }; 542 NSArray *plistArray = (NSArray *)plist; 543 if (plistArray.count < 2) 544 return { }; 545 if (plistArray.count == 2) 546 url = [NSURL URLWithString:plistArray[0]]; 547 else // The first string is the relative URL. 548 url = [NSURL URLWithString:plistArray[0] relativeToURL:[NSURL URLWithString:plistArray[1]]]; 549 } else { 550 ASSERT([value isKindOfClass:[NSURL class]]); 551 if (![value isKindOfClass:[NSURL class]]) 552 return { }; 553 url = (NSURL *)value; 554 } 555 556 if (!allowReadingURLAtIndex(url, index)) 531 557 return { }; 532 558 533 559 #if PLATFORM(IOS) && !(PLATFORM(WATCHOS) || PLATFORM(APPLETV)) 534 title = [ value_title];560 title = [url _title]; 535 561 #else 536 562 UNUSED_PARAM(title); 537 563 #endif 538 564 539 return (NSURL *)value;565 return url; 540 566 } 541 567 -
trunk/Source/WebCore/platform/mac/PlatformPasteboardMac.mm
r222761 r223195 108 108 } 109 109 110 Vector<String> PlatformPasteboard::typesSafeForDOMToReadAndWrite( ) const110 Vector<String> PlatformPasteboard::typesSafeForDOMToReadAndWrite(const String& origin) const 111 111 { 112 112 ListHashSet<String> domPasteboardTypes; 113 113 if (NSData *serializedCustomData = [m_pasteboard dataForType:@(PasteboardCustomData::cocoaType())]) { 114 auto buffer = SharedBuffer::create(serializedCustomData); 115 for (auto& type : PasteboardCustomData::fromSharedBuffer(buffer.get()).orderedTypes) 116 domPasteboardTypes.add(type); 114 auto data = PasteboardCustomData::fromSharedBuffer(SharedBuffer::create(serializedCustomData).get()); 115 if (data.origin == origin) { 116 for (auto& type : data.orderedTypes) 117 domPasteboardTypes.add(type); 118 } 117 119 } 118 120 -
trunk/Source/WebCore/platform/win/PasteboardWin.cpp
r222702 r223195 238 238 } 239 239 240 Vector<String> Pasteboard::typesSafeForBindings( )240 Vector<String> Pasteboard::typesSafeForBindings(const String&) 241 241 { 242 242 notImplemented(); … … 276 276 copyToVector(results, vector); 277 277 return vector; 278 } 279 280 String Pasteboard::readOrigin() 281 { 282 notImplemented(); 283 return { }; 278 284 } 279 285 -
trunk/Source/WebCore/platform/wpe/PasteboardWPE.cpp
r222699 r223195 50 50 } 51 51 52 Vector<String> Pasteboard::typesSafeForBindings( )52 Vector<String> Pasteboard::typesSafeForBindings(const String&) 53 53 { 54 54 notImplemented(); … … 61 61 platformStrategies()->pasteboardStrategy()->getTypes(types); 62 62 return types; 63 } 64 65 String Pasteboard::readOrigin() 66 { 67 notImplemented(); // webkit.org/b/177633: [GTK] Move to new Pasteboard API 68 return { }; 63 69 } 64 70 -
trunk/Source/WebCore/platform/wpe/PlatformPasteboardWPE.cpp
r222595 r223195 117 117 } 118 118 119 Vector<String> PlatformPasteboard::typesSafeForDOMToReadAndWrite( ) const119 Vector<String> PlatformPasteboard::typesSafeForDOMToReadAndWrite(const String&) const 120 120 { 121 121 return { }; -
trunk/Source/WebKit/ChangeLog
r223192 r223195 1 2017-10-11 Ryosuke Niwa <rniwa@webkit.org> 2 3 Sanitize URL in pasteboard for other applications and cross origin content 4 https://bugs.webkit.org/show_bug.cgi?id=178060 5 <rdar://problem/34874518> 6 7 Reviewed by Wenson Hsieh. 8 9 Plubmed the origin identifier through IPC from Pasteboard in WebContent process to PlatformPasteboard in UIProcess. 10 11 * UIProcess/Cocoa/WebPasteboardProxyCocoa.mm: 12 (WebKit::WebPasteboardProxy::typesSafeForDOMToReadAndWrite): 13 * UIProcess/WebPasteboardProxy.cpp: 14 (WebKit::WebPasteboardProxy::typesSafeForDOMToReadAndWrite): 15 * UIProcess/WebPasteboardProxy.h: 16 * UIProcess/WebPasteboardProxy.messages.in: 17 * WebProcess/WebCoreSupport/WebPlatformStrategies.cpp: 18 (WebKit::WebPlatformStrategies::typesSafeForDOMToReadAndWrite): 19 * WebProcess/WebCoreSupport/WebPlatformStrategies.h: 20 1 21 2017-10-11 Chris Dumez <cdumez@apple.com> 2 22 -
trunk/Source/WebKit/UIProcess/Cocoa/WebPasteboardProxyCocoa.mm
r222839 r223195 160 160 } 161 161 162 void WebPasteboardProxy::typesSafeForDOMToReadAndWrite(const String& pasteboardName, Vector<String>& types)163 { 164 types = PlatformPasteboard(pasteboardName).typesSafeForDOMToReadAndWrite( );162 void WebPasteboardProxy::typesSafeForDOMToReadAndWrite(const String& pasteboardName, const String& origin, Vector<String>& types) 163 { 164 types = PlatformPasteboard(pasteboardName).typesSafeForDOMToReadAndWrite(origin); 165 165 } 166 166 -
trunk/Source/WebKit/UIProcess/WebPasteboardProxy.cpp
r222595 r223195 64 64 #if !PLATFORM(COCOA) 65 65 66 void WebPasteboardProxy::typesSafeForDOMToReadAndWrite(const String&, Vector<String>& types)66 void WebPasteboardProxy::typesSafeForDOMToReadAndWrite(const String&, const String&, Vector<String>& types) 67 67 { 68 68 types = { }; -
trunk/Source/WebKit/UIProcess/WebPasteboardProxy.h
r222656 r223195 100 100 101 101 void writeCustomData(const WebCore::PasteboardCustomData&, const String& pasteboardName, uint64_t& newChangeCount); 102 void typesSafeForDOMToReadAndWrite(const String& pasteboardName, Vector<String>& types);102 void typesSafeForDOMToReadAndWrite(const String& pasteboardName, const String& origin, Vector<String>& types); 103 103 104 104 #if PLATFORM(GTK) -
trunk/Source/WebKit/UIProcess/WebPasteboardProxy.messages.in
r222656 r223195 37 37 38 38 WriteCustomData(struct WebCore::PasteboardCustomData data, String pasteboardName) -> (uint64_t changeCount) 39 TypesSafeForDOMToReadAndWrite(String pasteboardName ) -> (Vector<String> types)39 TypesSafeForDOMToReadAndWrite(String pasteboardName, String origin) -> (Vector<String> types) 40 40 41 41 #if PLATFORM(COCOA) -
trunk/Source/WebKit/WebProcess/WebCoreSupport/WebPlatformStrategies.cpp
r222938 r223195 406 406 #endif // PLATFORM(WPE) 407 407 408 Vector<String> WebPlatformStrategies::typesSafeForDOMToReadAndWrite(const String& pasteboardName )408 Vector<String> WebPlatformStrategies::typesSafeForDOMToReadAndWrite(const String& pasteboardName, const String& origin) 409 409 { 410 410 Vector<String> types; 411 WebProcess::singleton().parentProcessConnection()->sendSync(Messages::WebPasteboardProxy::TypesSafeForDOMToReadAndWrite(pasteboardName ), Messages::WebPasteboardProxy::TypesSafeForDOMToReadAndWrite::Reply(types), 0);411 WebProcess::singleton().parentProcessConnection()->sendSync(Messages::WebPasteboardProxy::TypesSafeForDOMToReadAndWrite(pasteboardName, origin), Messages::WebPasteboardProxy::TypesSafeForDOMToReadAndWrite::Reply(types), 0); 412 412 return types; 413 413 } -
trunk/Source/WebKit/WebProcess/WebCoreSupport/WebPlatformStrategies.h
r222938 r223195 98 98 #endif 99 99 100 Vector<String> typesSafeForDOMToReadAndWrite(const String& pasteboardName ) override;100 Vector<String> typesSafeForDOMToReadAndWrite(const String& pasteboardName, const String& origin) override; 101 101 long writeCustomData(const WebCore::PasteboardCustomData&, const String&) override; 102 102 }; -
trunk/Source/WebKitLegacy/mac/ChangeLog
r223192 r223195 1 2017-10-11 Ryosuke Niwa <rniwa@webkit.org> 2 3 Sanitize URL in pasteboard for other applications and cross origin content 4 https://bugs.webkit.org/show_bug.cgi?id=178060 5 <rdar://problem/34874518> 6 7 Reviewed by Wenson Hsieh. 8 9 * WebCoreSupport/WebPlatformStrategies.h: 10 * WebCoreSupport/WebPlatformStrategies.mm: 11 (WebPlatformStrategies::typesSafeForDOMToReadAndWrite): 12 1 13 2017-10-11 Chris Dumez <cdumez@apple.com> 2 14 -
trunk/Source/WebKitLegacy/mac/WebCoreSupport/WebPlatformStrategies.h
r222938 r223195 82 82 83 83 long writeCustomData(const WebCore::PasteboardCustomData&, const String& pasteboardName) override; 84 Vector<String> typesSafeForDOMToReadAndWrite(const String& pasteboardName ) override;84 Vector<String> typesSafeForDOMToReadAndWrite(const String& pasteboardName, const String& origin) override; 85 85 86 86 long addTypes(const Vector<String>& pasteboardTypes, const String& pasteboardName) override; -
trunk/Source/WebKitLegacy/mac/WebCoreSupport/WebPlatformStrategies.mm
r222938 r223195 179 179 } 180 180 181 Vector<String> WebPlatformStrategies::typesSafeForDOMToReadAndWrite(const String& pasteboardName )182 { 183 return PlatformPasteboard(pasteboardName).typesSafeForDOMToReadAndWrite( );181 Vector<String> WebPlatformStrategies::typesSafeForDOMToReadAndWrite(const String& pasteboardName, const String& origin) 182 { 183 return PlatformPasteboard(pasteboardName).typesSafeForDOMToReadAndWrite(origin); 184 184 } 185 185 -
trunk/Tools/ChangeLog
r223192 r223195 1 2017-10-11 Ryosuke Niwa <rniwa@webkit.org> 2 3 Sanitize URL in pasteboard for other applications and cross origin content 4 https://bugs.webkit.org/show_bug.cgi?id=178060 5 <rdar://problem/34874518> 6 7 Reviewed by Wenson Hsieh. 8 9 Added API tests for sanitizing URLs copied from web content, and that the original URL is exposed to the web content. 10 11 * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj: 12 * TestWebKitAPI/Tests/WebKitCocoa/CopyURL.mm: Added. 13 (readURLFromPasteboard): A helper function. 14 * TestWebKitAPI/Tests/WebKitCocoa/copy-url.html: Added. 15 * TestWebKitAPI/Tests/ios/DataInteractionTests.mm: 16 (DataInteractionTests.DataTransferGetDataWhenDroppingCustomData): Rebaselined. https://www.apple.com is no longer 17 normalized to https://www.apple.com/ by NSURL / UIPasteboard as expected. 18 (DataInteractionTests.DataTransferSetDataValidURL): Added. 19 (DataInteractionTests.DataTransferSetDataUnescapedURL): Added. 20 (DataInteractionTests.qDataTransferSetDataInvalidURL): Added. 21 1 22 2017-10-11 Chris Dumez <cdumez@apple.com> 2 23 -
trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj
r222839 r223195 546 546 9B270FEE1DDC2C0B002D53F3 /* closed-shadow-tree-test.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 9B270FED1DDC25FD002D53F3 /* closed-shadow-tree-test.html */; }; 547 547 9B4F8FA7159D52DD002D9F94 /* HTMLCollectionNamedItem.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 9B4F8FA6159D52CA002D9F94 /* HTMLCollectionNamedItem.html */; }; 548 9B62630C1F8C25C8007EE29B /* copy-url.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 9B62630B1F8C2510007EE29B /* copy-url.html */; }; 549 9B7A37C41F8AEBA5004AA228 /* CopyURL.mm in Sources */ = {isa = PBXBuildFile; fileRef = 9B7A37C21F8AEBA5004AA228 /* CopyURL.mm */; }; 548 550 9B7D740F1F8378770006C432 /* paste-rtfd.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 9B7D740E1F8377E60006C432 /* paste-rtfd.html */; }; 549 551 9BD4239A1E04BD9800200395 /* AttributedSubstringForProposedRangeWithImage.mm in Sources */ = {isa = PBXBuildFile; fileRef = 9BD423991E04BD9800200395 /* AttributedSubstringForProposedRangeWithImage.mm */; }; … … 842 844 CD0BD0A81F79982D001AB2CF /* ContextMenuImgWithVideo.html in Copy Resources */, 843 845 5C2936961D5C00ED00DEAB1E /* CookieMessage.html in Copy Resources */, 846 9B62630C1F8C25C8007EE29B /* copy-url.html in Copy Resources */, 844 847 7AEAD4811E20122700416EFE /* CrossPartitionFileSchemeAccess.html in Copy Resources */, 845 848 F4AB578A1F65165400DB0DA1 /* custom-draggable-div.html in Copy Resources */, … … 1510 1513 9B4F8FA3159D52B1002D9F94 /* HTMLCollectionNamedItem.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = HTMLCollectionNamedItem.mm; sourceTree = "<group>"; }; 1511 1514 9B4F8FA6159D52CA002D9F94 /* HTMLCollectionNamedItem.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = HTMLCollectionNamedItem.html; sourceTree = "<group>"; }; 1515 9B62630B1F8C2510007EE29B /* copy-url.html */ = {isa = PBXFileReference; lastKnownFileType = text.html; path = "copy-url.html"; sourceTree = "<group>"; }; 1512 1516 9B79164F1BD89D0D00D50B8F /* FirstResponderScrollingPosition.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = FirstResponderScrollingPosition.mm; sourceTree = "<group>"; }; 1517 9B7A37C21F8AEBA5004AA228 /* CopyURL.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = CopyURL.mm; sourceTree = "<group>"; }; 1513 1518 9B7D740E1F8377E60006C432 /* paste-rtfd.html */ = {isa = PBXFileReference; lastKnownFileType = text.html; path = "paste-rtfd.html"; sourceTree = "<group>"; }; 1514 1519 9BD423991E04BD9800200395 /* AttributedSubstringForProposedRangeWithImage.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = AttributedSubstringForProposedRangeWithImage.mm; sourceTree = "<group>"; }; … … 1983 1988 5C2936911D5BF63E00DEAB1E /* CookieAcceptPolicy.mm */, 1984 1989 9999108A1F393C8B008AD455 /* Copying.mm */, 1990 9B7A37C21F8AEBA5004AA228 /* CopyURL.mm */, 1985 1991 2DC4CF761D2D9DD800ECCC94 /* DataDetection.mm */, 1986 1992 CEC16EA41EE863BF00DE479A /* DecidePolicyForNavigationAction.mm */, … … 2231 2237 A16F66B91C40EA2000BD4D24 /* ContentFiltering.html */, 2232 2238 5C2936941D5BFD1900DEAB1E /* CookieMessage.html */, 2239 9B62630B1F8C2510007EE29B /* copy-url.html */, 2233 2240 F4AB57891F65164B00DB0DA1 /* custom-draggable-div.html */, 2234 2241 F486B1CF1F6794FF00F34BDD /* DataTransfer-setDragImage.html */, … … 3224 3231 51D1249B1E785425002B2820 /* CookieManager.cpp in Sources */, 3225 3232 9999108B1F393C96008AD455 /* Copying.mm in Sources */, 3233 9B7A37C41F8AEBA5004AA228 /* CopyURL.mm in Sources */, 3226 3234 7CCE7EAC1A411A3400447C4C /* Counters.cpp in Sources */, 3227 3235 7AEAD47F1E20116C00416EFE /* CrossPartitionFileSchemeAccess.mm in Sources */, -
trunk/Tools/TestWebKitAPI/Tests/ios/DataInteractionTests.mm
r222743 r223195 1522 1522 @"text/html" : @"<b>bold text</b>", 1523 1523 @"bar/html" : @"<i>italic text</i>", 1524 @"text/uri-list" : @"https://www.apple.com /",1524 @"text/uri-list" : @"https://www.apple.com", 1525 1525 @"baz/uri-list" : @"https://www.webkit.org" 1526 1526 } … … 1646 1646 } 1647 1647 1648 TEST(DataInteractionTests, DataTransferSetDataValidURL) 1649 { 1650 auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 500)]); 1651 [webView synchronouslyLoadTestPageNamed:@"dump-datatransfer-types"]; 1652 auto simulator = adoptNS([[DataInteractionSimulator alloc] initWithWebView:webView.get()]); 1653 1654 [webView stringByEvaluatingJavaScript:@"select(rich)"]; 1655 [webView stringByEvaluatingJavaScript:@"customData = { 'url' : 'https://webkit.org/b/123' }"]; 1656 [webView stringByEvaluatingJavaScript:@"writeCustomData = true"]; 1657 1658 __block bool done = false; 1659 [simulator.get() setOverridePerformDropBlock:^NSArray<UIDragItem *> *(id <UIDropSession> session) 1660 { 1661 EXPECT_EQ(1UL, session.items.count); 1662 auto *item = session.items[0].itemProvider; 1663 EXPECT_TRUE([item.registeredTypeIdentifiers containsObject:(NSString *)kUTTypeURL]); 1664 EXPECT_TRUE([item canLoadObjectOfClass: [NSURL class]]); 1665 [item loadObjectOfClass:[NSURL class] completionHandler:^(id<NSItemProviderReading> url, NSError *error) { 1666 EXPECT_TRUE([url isKindOfClass: [NSURL class]]); 1667 EXPECT_WK_STREQ([(NSURL *)url absoluteString], @"https://webkit.org/b/123"); 1668 done = true; 1669 }]; 1670 return session.items; 1671 }]; 1672 [simulator runFrom:CGPointMake(50, 225) to:CGPointMake(50, 375)]; 1673 1674 checkJSONWithLogging([webView stringByEvaluatingJavaScript:@"output.value"], @{ 1675 @"dragover": @{ 1676 @"text/uri-list": @"", 1677 }, 1678 @"drop": @{ 1679 @"text/uri-list": @"https://webkit.org/b/123", 1680 } 1681 }); 1682 TestWebKitAPI::Util::run(&done); 1683 } 1684 1685 TEST(DataInteractionTests, DataTransferSetDataUnescapedURL) 1686 { 1687 auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 500)]); 1688 [webView synchronouslyLoadTestPageNamed:@"dump-datatransfer-types"]; 1689 auto simulator = adoptNS([[DataInteractionSimulator alloc] initWithWebView:webView.get()]); 1690 1691 [webView stringByEvaluatingJavaScript:@"select(rich)"]; 1692 [webView stringByEvaluatingJavaScript:@"customData = { 'url' : 'http://webkit.org/b/\u4F60\u597D;?x=8 + 6' }"]; 1693 [webView stringByEvaluatingJavaScript:@"writeCustomData = true"]; 1694 1695 __block bool done = false; 1696 [simulator.get() setOverridePerformDropBlock:^NSArray<UIDragItem *> *(id <UIDropSession> session) 1697 { 1698 EXPECT_EQ(1UL, session.items.count); 1699 auto *item = session.items[0].itemProvider; 1700 EXPECT_TRUE([item.registeredTypeIdentifiers containsObject:(NSString *)kUTTypeURL]); 1701 EXPECT_TRUE([item canLoadObjectOfClass: [NSURL class]]); 1702 [item loadObjectOfClass:[NSURL class] completionHandler:^(id<NSItemProviderReading> url, NSError *error) { 1703 EXPECT_TRUE([url isKindOfClass: [NSURL class]]); 1704 EXPECT_WK_STREQ([(NSURL *)url absoluteString], @"http://webkit.org/b/%E4%BD%A0%E5%A5%BD;?x=8%20+%206"); 1705 done = true; 1706 }]; 1707 return session.items; 1708 }]; 1709 [simulator runFrom:CGPointMake(50, 225) to:CGPointMake(50, 375)]; 1710 1711 checkJSONWithLogging([webView stringByEvaluatingJavaScript:@"output.value"], @{ 1712 @"dragover": @{ 1713 @"text/uri-list": @"", 1714 }, 1715 @"drop": @{ 1716 @"text/uri-list": @"http://webkit.org/b/\u4F60\u597D;?x=8 + 6", 1717 } 1718 }); 1719 TestWebKitAPI::Util::run(&done); 1720 } 1721 1722 TEST(DataInteractionTests, DataTransferSetDataInvalidURL) 1723 { 1724 auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 500)]); 1725 [webView synchronouslyLoadTestPageNamed:@"dump-datatransfer-types"]; 1726 auto simulator = adoptNS([[DataInteractionSimulator alloc] initWithWebView:webView.get()]); 1727 1728 [webView stringByEvaluatingJavaScript:@"select(rich)"]; 1729 [webView stringByEvaluatingJavaScript:@"customData = { 'url' : 'some random string' }"]; 1730 [webView stringByEvaluatingJavaScript:@"writeCustomData = true"]; 1731 1732 [simulator runFrom:CGPointMake(50, 225) to:CGPointMake(50, 375)]; 1733 NSArray *registeredTypes = [simulator.get().sourceItemProviders.firstObject registeredTypeIdentifiers]; 1734 EXPECT_FALSE([registeredTypes containsObject:(NSString *)kUTTypeURL]); 1735 checkJSONWithLogging([webView stringByEvaluatingJavaScript:@"output.value"], @{ 1736 @"dragover": @{ 1737 @"text/uri-list": @"", 1738 }, 1739 @"drop": @{ 1740 @"text/uri-list": @"some random string", 1741 } 1742 }); 1743 } 1744 1648 1745 #endif // __IPHONE_OS_VERSION_MIN_REQUIRED >= 110300 1649 1746
Note:
See TracChangeset
for help on using the changeset viewer.