Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Strip away event handlers and JavaScript URLs when copying
https://bugs.webkit.org/show_bug.cgi?id=178375 Reviewed by Wenson Hsieh. Source/WebCore: Don't serialize event handlers and URLs with javascript protocol when serializing HTML since they're not safe to be pasted elsewhere. Test: editing/pasteboard/copying-html-strips-javascript-url-and-event-handler.html * dom/Element.cpp: (WebCore::Element::isEventHandlerAttribute const): (WebCore::isEventHandlerAttribute): Deleted. * dom/Element.h: * editing/markup.cpp: (WebCore::StyledMarkupAccumulator::appendElement): LayoutTests: Added a regression test. * editing/pasteboard/copying-html-strips-javascript-url-and-event-handler-expected.txt: Added. * editing/pasteboard/copying-html-strips-javascript-url-and-event-handler.html: Added. Canonical link: https://commits.webkit.org/194600@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@223462 268f45cc-cd09-0410-ab3c-d52691b4dbfc
- Loading branch information
Showing
with
96 additions
and 4 deletions.
- +12 −0 LayoutTests/ChangeLog
- +12 −0 LayoutTests/editing/pasteboard/copying-html-strips-javascript-url-and-event-handler-expected.txt
- +46 −0 LayoutTests/editing/pasteboard/copying-html-strips-javascript-url-and-event-handler.html
- +19 −0 Source/WebCore/ChangeLog
- +2 −2 Source/WebCore/dom/Element.cpp
- +3 −2 Source/WebCore/dom/Element.h
- +2 −0 Source/WebCore/editing/markup.cpp
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@@ -0,0 +1,12 @@ | ||
This tests copying and pasting a markup with an event handler and a javascript URL. WebKit should strip them away upon copy. | ||
|
||
On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE". | ||
|
||
|
||
PASS html.includes("hello") is true | ||
PASS html.includes("world") is true | ||
PASS html.includes("dangerousCode") is false | ||
PASS successfullyParsed is true | ||
|
||
TEST COMPLETE | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@@ -0,0 +1,46 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<body> | ||
<div id="container"> | ||
<button onclick="runTest()">Copy</button> | ||
<div id="source" contenteditable><a href="javascript:dangerousCode()">hello</a>, <b onmouseover="dangerousCode()">world</b>. WebKit</div> | ||
<div id="destination" onpaste="doPaste(event)" contenteditable>Paste here</div> | ||
</div> | ||
<script src="../../resources/js-test-pre.js"></script> | ||
<script> | ||
|
||
description('This tests copying and pasting a markup with an event handler and a javascript URL. WebKit should strip them away upon copy.'); | ||
jsTestIsAsync = true; | ||
|
||
function dangerousCode() { } | ||
|
||
function runTest() { | ||
source.focus(); | ||
document.execCommand('selectAll'); | ||
document.execCommand('copy'); | ||
|
||
destination.focus(); | ||
document.execCommand('selectAll'); | ||
if (window.testRunner) | ||
document.execCommand('paste'); | ||
} | ||
|
||
function doPaste(event) { | ||
html = event.clipboardData.getData('text/html'); | ||
shouldBeTrue('html.includes("hello")'); | ||
shouldBeTrue('html.includes("world")'); | ||
shouldBeFalse('html.includes("dangerousCode")'); | ||
|
||
container.remove(); | ||
finishJSTest(); | ||
} | ||
|
||
if (window.testRunner) | ||
window.onload = runTest; | ||
|
||
successfullyParsed = true; | ||
|
||
</script> | ||
<script src="../../resources/js-test-post.js"></script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters