Changeset 222688 in webkit
- Timestamp:
- Sep 30, 2017 11:59:00 PM (7 years ago)
- Location:
- trunk
- Files:
-
- 2 added
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/LayoutTests/ChangeLog
r222687 r222688 1 2017-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 1 15 2017-09-30 Wenson Hsieh <wenson_hsieh@apple.com> 2 16 -
trunk/Source/WebCore/ChangeLog
r222686 r222688 1 2017-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 1 36 2017-09-30 Sam Weinig <sam@webkit.org> 2 37 -
trunk/Source/WebCore/dom/DataTransfer.cpp
r222680 r222688 138 138 return String(); 139 139 140 #if ENABLE(DRAG_SUPPORT) 141 if (forFileDrag() && m_pasteboard->readFilenames().size()) 140 if ((forFileDrag() || Settings::customPasteboardDataEnabled()) && m_pasteboard->containsFiles()) 142 141 return { }; 143 #endif144 142 145 143 auto normalizedType = normalizeType(type); … … 154 152 return; 155 153 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; 160 156 161 157 String normalizedType = normalizeType(type); … … 176 172 if (!canReadTypes()) 177 173 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(); 180 181 } 181 182 -
trunk/Source/WebCore/dom/DataTransfer.h
r222595 r222688 107 107 bool forDrag() const { return m_type == Type::DragAndDropData || m_type == Type::DragAndDropFiles; } 108 108 bool forFileDrag() const { return m_type == Type::DragAndDropFiles; } 109 #else 110 bool forDrag() const { return false; } 111 bool forFileDrag() const { return false; } 109 112 #endif 110 113 -
trunk/Source/WebCore/platform/Pasteboard.h
r222680 r222688 216 216 virtual void write(const PasteboardWebContent&); 217 217 218 virtual bool containsFiles(); 218 219 virtual Vector<String> readFilenames(); 219 220 virtual bool canSmartReplace(); -
trunk/Source/WebCore/platform/StaticPasteboard.h
r222680 r222688 59 59 void write(const PasteboardWebContent&) final { } 60 60 61 bool containsFiles() final { return false; } 61 62 Vector<String> readFilenames() final { return { }; } 62 63 bool canSmartReplace() final { return false; } -
trunk/Source/WebCore/platform/cocoa/PasteboardCocoa.mm
r222680 r222688 152 152 } 153 153 154 bool 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 154 171 Vector<String> Pasteboard::typesSafeForBindings() 155 172 { -
trunk/Source/WebCore/platform/gtk/PasteboardGtk.cpp
r222680 r222688 320 320 } 321 321 322 bool Pasteboard::containsFiles() 323 { 324 return readFilenames().size(); 325 } 326 322 327 Vector<String> Pasteboard::readFilenames() 323 328 { -
trunk/Source/WebCore/platform/win/PasteboardWin.cpp
r222680 r222688 313 313 notImplemented(); 314 314 return { }; 315 } 316 317 bool Pasteboard::containsFiles() 318 { 319 return readFilenames().size(); // FIXME: Make this code more efficient. 315 320 } 316 321 -
trunk/Source/WebCore/platform/wpe/PasteboardWPE.cpp
r222680 r222688 125 125 } 126 126 127 bool Pasteboard::containsFiles() 128 { 129 notImplemented(); 130 return false; 131 } 132 127 133 Vector<String> Pasteboard::readFilenames() 128 134 { 135 notImplemented(); 129 136 return Vector<String>(); 130 137 } -
trunk/Tools/TestWebKitAPI/Tests/ios/DataInteractionTests.mm
r222656 r222688 1037 1037 { 1038 1038 NSArray<NSString *> *expectedOutput = @[ 1039 @"Found data transfer item (kind: 'string', type: 'text/plain')",1040 1039 @"Found data transfer item (kind: 'file', type: 'text/plain')", 1041 1040 @"FILE: /foo.txt ('text/plain', 28 bytes)" … … 1558 1557 // File URLs should never be exposed directly to web content, so DataTransfer.getData should return an empty string here. 1559 1558 checkJSONWithLogging([webView stringByEvaluatingJavaScript:@"output.value"], @{ 1560 @"dragover": @{ @"Files": @"" , @"text/uri-list" : @""},1561 @"drop": @{ @"Files": @"" , @"text/uri-list" : @""}1559 @"dragover": @{ @"Files": @"" }, 1560 @"drop": @{ @"Files": @"" } 1562 1561 }); 1563 1562 } … … 1580 1579 [simulator runFrom:CGPointMake(300, 375) to:CGPointMake(50, 375)]; 1581 1580 checkJSONWithLogging([webView stringByEvaluatingJavaScript:@"output.value"], @{ 1582 @"dragover": @{ @" text/plain" : @"" },1583 @"drop": @{ @" text/plain" : @"" }1581 @"dragover": @{ @"Files" : @"" }, 1582 @"drop": @{ @"Files" : @"" } 1584 1583 }); 1585 1584
Note: See TracChangeset
for help on using the changeset viewer.