Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(518)

Unified Diff: Source/core/editing/CompositeEditCommand.cpp

Issue 71163005: Prevent recursive call of Document::execCommand() to protect from attack code (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: 2013-11-14T13:56:25 Created 7 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « LayoutTests/editing/execCommand/apply-style-iframe-crash-expected.txt ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/core/editing/CompositeEditCommand.cpp
diff --git a/Source/core/editing/CompositeEditCommand.cpp b/Source/core/editing/CompositeEditCommand.cpp
index 4db2fe86342c16860200307aa8539f6c2eb0c379..905354fe98d7d8979a7214b76ed1567773a85b25 100644
--- a/Source/core/editing/CompositeEditCommand.cpp
+++ b/Source/core/editing/CompositeEditCommand.cpp
@@ -73,6 +73,24 @@ namespace WebCore {
using namespace HTMLNames;
+namespace {
+class PreventRecursiveApply {
Hajime Morrita 2013/11/14 07:00:24 Nit: Let's name more noun-like
+public:
+ static bool isRecursiveCall() { return s_nestingCounter; }
+
+ class Scope {
+ public:
+ Scope() { ++s_nestingCounter; }
+ ~Scope() { --s_nestingCounter; }
+ };
+ friend class Scope;
+
+private:
+ static int s_nestingCounter;
+};
+int PreventRecursiveApply::s_nestingCounter;
+}
+
PassRefPtr<EditCommandComposition> EditCommandComposition::create(Document* document,
const VisibleSelection& startingSelection, const VisibleSelection& endingSelection, EditAction editAction)
{
@@ -158,6 +176,14 @@ CompositeEditCommand::~CompositeEditCommand()
void CompositeEditCommand::apply()
{
+ // We don't allow recusrive |apply()| to protect against attack code.
+ // Recursive call of |apply()| could be happened by moving iframe
+ // with script triggered by insertion, e.g. <iframe src="javascript:...">
+ // <iframe onload="...">. This usage is valid as of the specification
+ // although, it isn't common use case, rather it is used as attack code.
+ if (PreventRecursiveApply::isRecursiveCall())
+ return;
+
if (!endingSelection().isContentRichlyEditable()) {
switch (editingAction()) {
case EditActionTyping:
@@ -182,7 +208,8 @@ void CompositeEditCommand::apply()
Frame* frame = document().frame();
ASSERT(frame);
{
- EventQueueScope scope;
+ EventQueueScope eventQueueScope;
+ PreventRecursiveApply::Scope preventRecursiveApplyScope;
doApply();
}
« no previous file with comments | « LayoutTests/editing/execCommand/apply-style-iframe-crash-expected.txt ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698