Title: [99489] trunk/Source/WebCore
Revision
99489
Author
[email protected]
Date
2011-11-07 15:20:18 -0800 (Mon, 07 Nov 2011)

Log Message

Move parseSandboxPolicy to SecurityContext
https://bugs.webkit.org/show_bug.cgi?id=71732

Reviewed by Eric Seidel.

As requested by Eric, this patch resolves a layering inversion.  Now
that we have SecurityContext to hold the sandbox bits and the origin,
it's a logical place to put the parser for sandbox policies.

* dom/SecurityContext.cpp:
(WebCore::SecurityContext::parseSandboxPolicy):
* dom/SecurityContext.h:
* html/HTMLIFrameElement.cpp:
(WebCore::HTMLIFrameElement::parseMappedAttribute):
* page/ContentSecurityPolicy.cpp:
(WebCore::ContentSecurityPolicy::applySandboxPolicy):
* page/SecurityOrigin.cpp:
* page/SecurityOrigin.h:

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (99488 => 99489)


--- trunk/Source/WebCore/ChangeLog	2011-11-07 23:17:42 UTC (rev 99488)
+++ trunk/Source/WebCore/ChangeLog	2011-11-07 23:20:18 UTC (rev 99489)
@@ -1,3 +1,24 @@
+2011-11-07  Adam Barth  <[email protected]>
+
+        Move parseSandboxPolicy to SecurityContext
+        https://bugs.webkit.org/show_bug.cgi?id=71732
+
+        Reviewed by Eric Seidel.
+
+        As requested by Eric, this patch resolves a layering inversion.  Now
+        that we have SecurityContext to hold the sandbox bits and the origin,
+        it's a logical place to put the parser for sandbox policies.
+
+        * dom/SecurityContext.cpp:
+        (WebCore::SecurityContext::parseSandboxPolicy):
+        * dom/SecurityContext.h:
+        * html/HTMLIFrameElement.cpp:
+        (WebCore::HTMLIFrameElement::parseMappedAttribute):
+        * page/ContentSecurityPolicy.cpp:
+        (WebCore::ContentSecurityPolicy::applySandboxPolicy):
+        * page/SecurityOrigin.cpp:
+        * page/SecurityOrigin.h:
+
 2011-11-07  Jer Noble  <[email protected]>
 
         Rename PlatformClockPOSIX -> ClockGeneric, and use WTF::currentTime() for its timing source.

Modified: trunk/Source/WebCore/dom/SecurityContext.cpp (99488 => 99489)


--- trunk/Source/WebCore/dom/SecurityContext.cpp	2011-11-07 23:17:42 UTC (rev 99488)
+++ trunk/Source/WebCore/dom/SecurityContext.cpp	2011-11-07 23:20:18 UTC (rev 99489)
@@ -28,6 +28,7 @@
 #include "SecurityContext.h"
 
 #include "ContentSecurityPolicy.h"
+#include "HTMLParserIdioms.h"
 #include "SecurityOrigin.h"
 
 namespace WebCore {
@@ -51,4 +52,40 @@
     m_contentSecurityPolicy = contentSecurityPolicy;
 }
 
+SandboxFlags SecurityContext::parseSandboxPolicy(const String& policy)
+{
+    // http://www.w3.org/TR/html5/the-iframe-element.html#attr-iframe-sandbox
+    // Parse the unordered set of unique space-separated tokens.
+    SandboxFlags flags = SandboxAll;
+    const UChar* characters = policy.characters();
+    unsigned length = policy.length();
+    unsigned start = 0;
+    while (true) {
+        while (start < length && isHTMLSpace(characters[start]))
+            ++start;
+        if (start >= length)
+            break;
+        unsigned end = start + 1;
+        while (end < length && !isHTMLSpace(characters[end]))
+            ++end;
+
+        // Turn off the corresponding sandbox flag if it's set as "allowed".
+        String sandboxToken = policy.substring(start, end - start);
+        if (equalIgnoringCase(sandboxToken, "allow-same-origin"))
+            flags &= ~SandboxOrigin;
+        else if (equalIgnoringCase(sandboxToken, "allow-forms"))
+            flags &= ~SandboxForms;
+        else if (equalIgnoringCase(sandboxToken, "allow-scripts"))
+            flags &= ~SandboxScripts;
+        else if (equalIgnoringCase(sandboxToken, "allow-top-navigation"))
+            flags &= ~SandboxTopNavigation;
+        else if (equalIgnoringCase(sandboxToken, "allow-popups"))
+            flags &= ~SandboxPopups;
+
+        start = end + 1;
+    }
+
+    return flags;
 }
+
+}

Modified: trunk/Source/WebCore/dom/SecurityContext.h (99488 => 99489)


--- trunk/Source/WebCore/dom/SecurityContext.h	2011-11-07 23:17:42 UTC (rev 99488)
+++ trunk/Source/WebCore/dom/SecurityContext.h	2011-11-07 23:20:18 UTC (rev 99489)
@@ -29,6 +29,7 @@
 
 #include <wtf/PassRefPtr.h>
 #include <wtf/RefPtr.h>
+#include <wtf/text/WTFString.h>
 
 namespace WebCore {
 
@@ -58,6 +59,8 @@
     void enforceSandboxFlags(SandboxFlags mask) { m_sandboxFlags |= mask; }
     bool isSandboxed(SandboxFlags mask) const { return m_sandboxFlags & mask; }
 
+    static SandboxFlags parseSandboxPolicy(const String& policy);
+
 protected:
     SecurityContext();
     ~SecurityContext();

Modified: trunk/Source/WebCore/html/HTMLIFrameElement.cpp (99488 => 99489)


--- trunk/Source/WebCore/html/HTMLIFrameElement.cpp	2011-11-07 23:17:42 UTC (rev 99488)
+++ trunk/Source/WebCore/html/HTMLIFrameElement.cpp	2011-11-07 23:20:18 UTC (rev 99489)
@@ -32,7 +32,6 @@
 #include "HTMLNames.h"
 #include "NodeRenderingContext.h"
 #include "RenderIFrame.h"
-#include "SecurityOrigin.h"
 
 namespace WebCore {
 
@@ -92,7 +91,7 @@
             // Add a rule that nulls out our border width.
             addCSSLength(attr, CSSPropertyBorderWidth, "0");
     } else if (attr->name() == sandboxAttr)
-        setSandboxFlags(attr->isNull() ? SandboxNone : SecurityOrigin::parseSandboxPolicy(attr->value()));
+        setSandboxFlags(attr->isNull() ? SandboxNone : SecurityContext::parseSandboxPolicy(attr->value()));
     else
         HTMLFrameElementBase::parseMappedAttribute(attr);
 }

Modified: trunk/Source/WebCore/page/ContentSecurityPolicy.cpp (99488 => 99489)


--- trunk/Source/WebCore/page/ContentSecurityPolicy.cpp	2011-11-07 23:17:42 UTC (rev 99488)
+++ trunk/Source/WebCore/page/ContentSecurityPolicy.cpp	2011-11-07 23:20:18 UTC (rev 99489)
@@ -769,7 +769,7 @@
 {
     ASSERT(!m_haveSandboxPolicy);
     m_haveSandboxPolicy = true;
-    m_scriptExecutionContext->enforceSandboxFlags(SecurityOrigin::parseSandboxPolicy(sandboxPolicy));
+    m_scriptExecutionContext->enforceSandboxFlags(SecurityContext::parseSandboxPolicy(sandboxPolicy));
 }
 
 void ContentSecurityPolicy::addDirective(const String& name, const String& value)

Modified: trunk/Source/WebCore/page/SecurityOrigin.cpp (99488 => 99489)


--- trunk/Source/WebCore/page/SecurityOrigin.cpp	2011-11-07 23:17:42 UTC (rev 99488)
+++ trunk/Source/WebCore/page/SecurityOrigin.cpp	2011-11-07 23:20:18 UTC (rev 99489)
@@ -32,7 +32,6 @@
 #include "BlobURL.h"
 #include "Document.h"
 #include "FileSystem.h"
-#include "HTMLParserIdioms.h"
 #include "KURL.h"
 #include "OriginAccessEntry.h"
 #include "SchemeRegistry.h"
@@ -544,41 +543,6 @@
     return !URLIsSecureURL;
 }
 
-SandboxFlags SecurityOrigin::parseSandboxPolicy(const String& policy)
-{
-    // Parse the unordered set of unique space-separated tokens.
-    SandboxFlags flags = SandboxAll;
-    const UChar* characters = policy.characters();
-    unsigned length = policy.length();
-    unsigned start = 0;
-    while (true) {
-        while (start < length && isHTMLSpace(characters[start]))
-            ++start;
-        if (start >= length)
-            break;
-        unsigned end = start + 1;
-        while (end < length && !isHTMLSpace(characters[end]))
-            ++end;
-
-        // Turn off the corresponding sandbox flag if it's set as "allowed".
-        String sandboxToken = policy.substring(start, end - start);
-        if (equalIgnoringCase(sandboxToken, "allow-same-origin"))
-            flags &= ~SandboxOrigin;
-        else if (equalIgnoringCase(sandboxToken, "allow-forms"))
-            flags &= ~SandboxForms;
-        else if (equalIgnoringCase(sandboxToken, "allow-scripts"))
-            flags &= ~SandboxScripts;
-        else if (equalIgnoringCase(sandboxToken, "allow-top-navigation"))
-            flags &= ~SandboxTopNavigation;
-        else if (equalIgnoringCase(sandboxToken, "allow-popups"))
-            flags &= ~SandboxPopups;
-
-        start = end + 1;
-    }
-
-    return flags;
-}
-
 void SecurityOrigin::setLocalLoadPolicy(LocalLoadPolicy policy)
 {
     localLoadPolicy = policy;

Modified: trunk/Source/WebCore/page/SecurityOrigin.h (99488 => 99489)


--- trunk/Source/WebCore/page/SecurityOrigin.h	2011-11-07 23:17:42 UTC (rev 99488)
+++ trunk/Source/WebCore/page/SecurityOrigin.h	2011-11-07 23:20:18 UTC (rev 99489)
@@ -30,7 +30,6 @@
 #define SecurityOrigin_h
 
 #include "PlatformString.h"
-#include "SecurityContext.h" // FIXME: Remove once parseSandboxPolicy moves to SecurityContext.
 #include <wtf/ThreadSafeRefCounted.h>
 
 namespace WebCore {
@@ -178,8 +177,6 @@
     // (and whether it was set) but considering the host. It is used for postMessage.
     bool isSameSchemeHostPort(const SecurityOrigin*) const;
 
-    static SandboxFlags parseSandboxPolicy(const String& policy);
-
     static bool shouldHideReferrer(const KURL&, const String& referrer);
 
     enum LocalLoadPolicy {
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to