Title: [180783] trunk
Revision
180783
Author
beid...@apple.com
Date
2015-02-27 14:50:03 -0800 (Fri, 27 Feb 2015)

Log Message

Add a "block-cookies" rule to the user content filter.
https://bugs.webkit.org/show_bug.cgi?id=142105

Reviewed by Alex Christensen.

Source/WebCore:

Tests: http/tests/usercontentfilter/block-cookies-basic.html
       http/tests/usercontentfilter/block-cookies-send.html

* contentextensions/ContentExtensionRule.h:

* contentextensions/ContentExtensionsBackend.cpp:
(WebCore::ContentExtensions::ContentExtensionsBackend::actionForURL):
(WebCore::ContentExtensions::ContentExtensionsBackend::shouldBlockURL): Deleted.
* contentextensions/ContentExtensionsBackend.h:

* contentextensions/ContentExtensionsManager.cpp:
(WebCore::ContentExtensions::ExtensionsManager::loadAction):

* loader/cache/CachedResourceLoader.cpp:
(WebCore::CachedResourceLoader::requestResource):

* page/UserContentController.cpp:
(WebCore::UserContentController::actionForURL):
(WebCore::UserContentController::contentFilterBlocksURL): Deleted.
* page/UserContentController.h:

LayoutTests:

* http/tests/cookies/resources/echo-cookies.php: Added.
* http/tests/usercontentfilter/block-cookies-basic-expected.txt: Added.
* http/tests/usercontentfilter/block-cookies-basic.html: Added.
* http/tests/usercontentfilter/block-cookies-basic.html.json: Added.
* http/tests/usercontentfilter/block-cookies-send-expected.txt: Added.
* http/tests/usercontentfilter/block-cookies-send.html: Added.
* http/tests/usercontentfilter/block-cookies-send.html.json: Added.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (180782 => 180783)


--- trunk/LayoutTests/ChangeLog	2015-02-27 22:45:33 UTC (rev 180782)
+++ trunk/LayoutTests/ChangeLog	2015-02-27 22:50:03 UTC (rev 180783)
@@ -1,3 +1,18 @@
+2015-02-27  Brady Eidson  <beid...@apple.com>
+
+        Add a "block-cookies" rule to the user content filter.
+        https://bugs.webkit.org/show_bug.cgi?id=142105
+
+        Reviewed by Alex Christensen.
+
+        * http/tests/cookies/resources/echo-cookies.php: Added.
+        * http/tests/usercontentfilter/block-cookies-basic-expected.txt: Added.
+        * http/tests/usercontentfilter/block-cookies-basic.html: Added.
+        * http/tests/usercontentfilter/block-cookies-basic.html.json: Added.
+        * http/tests/usercontentfilter/block-cookies-send-expected.txt: Added.
+        * http/tests/usercontentfilter/block-cookies-send.html: Added.
+        * http/tests/usercontentfilter/block-cookies-send.html.json: Added.
+
 2015-02-27  Ryosuke Niwa  <rn...@webkit.org>
 
         iOS, GTK, and EFL rebaselines after r180726.

Added: trunk/LayoutTests/http/tests/cookies/resources/echo-cookies.php (0 => 180783)


--- trunk/LayoutTests/http/tests/cookies/resources/echo-cookies.php	                        (rev 0)
+++ trunk/LayoutTests/http/tests/cookies/resources/echo-cookies.php	2015-02-27 22:50:03 UTC (rev 180783)
@@ -0,0 +1,11 @@
+<?php
+
+function echoCookie($value, $name)
+{
+    echo "$name = $value\n";
+}
+
+echo "Cookies are:\n";
+array_walk($_COOKIE, echoCookie);    
+
+?>

Added: trunk/LayoutTests/http/tests/usercontentfilter/block-cookies-basic-expected.txt (0 => 180783)


--- trunk/LayoutTests/http/tests/usercontentfilter/block-cookies-basic-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/http/tests/usercontentfilter/block-cookies-basic-expected.txt	2015-02-27 22:50:03 UTC (rev 180783)
@@ -0,0 +1,4 @@
+This image resource sets a cookie. But based on the content rules, setting cookie should be blocked.
+document.cookie should be empty, and its value is ''
+
+

Added: trunk/LayoutTests/http/tests/usercontentfilter/block-cookies-basic.html (0 => 180783)


--- trunk/LayoutTests/http/tests/usercontentfilter/block-cookies-basic.html	                        (rev 0)
+++ trunk/LayoutTests/http/tests/usercontentfilter/block-cookies-basic.html	2015-02-27 22:50:03 UTC (rev 180783)
@@ -0,0 +1,18 @@
+<script>
+if (window.testRunner) {
+	testRunner.dumpAsText();
+	testRunner.waitUntilDone();
+}
+
+function loaded()
+{
+	document.getElementById("logger").innerHTML += "document.cookie should be empty, and its value is '" + document.cookie + "'";
+	
+	if (window.testRunner)
+		testRunner.notifyDone();
+}
+</script>
+
+This image resource sets a cookie. But based on the content rules, setting cookie should be blocked.<br>
+<div id="logger"></div><br>
+<img src="" _onerror_="loaded()">

Added: trunk/LayoutTests/http/tests/usercontentfilter/block-cookies-basic.html.json (0 => 180783)


--- trunk/LayoutTests/http/tests/usercontentfilter/block-cookies-basic.html.json	                        (rev 0)
+++ trunk/LayoutTests/http/tests/usercontentfilter/block-cookies-basic.html.json	2015-02-27 22:50:03 UTC (rev 180783)
@@ -0,0 +1,10 @@
+[
+    {
+        "action": {
+            "type": "block-cookies"
+        },
+        "trigger": {
+            "url-filter": "http://127.0.0.1:8000/cookies/resources/cookie-utility.php"
+        }
+    }
+]
\ No newline at end of file

Added: trunk/LayoutTests/http/tests/usercontentfilter/block-cookies-send-expected.txt (0 => 180783)


--- trunk/LayoutTests/http/tests/usercontentfilter/block-cookies-send-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/http/tests/usercontentfilter/block-cookies-send-expected.txt	2015-02-27 22:50:03 UTC (rev 180783)
@@ -0,0 +1,9 @@
+This test loads a resource that sets a cookie, then verifies that the cookie is not sent out when it should be blocked.
+After the image, document.cookie is 'foo=awesomevalue'
+After the iframe, document.cookie is 'foo=awesomevalue'
+ 
+
+--------
+Frame: 'iframe'
+--------
+Cookies are:

Added: trunk/LayoutTests/http/tests/usercontentfilter/block-cookies-send.html (0 => 180783)


--- trunk/LayoutTests/http/tests/usercontentfilter/block-cookies-send.html	                        (rev 0)
+++ trunk/LayoutTests/http/tests/usercontentfilter/block-cookies-send.html	2015-02-27 22:50:03 UTC (rev 180783)
@@ -0,0 +1,29 @@
+<script>
+if (window.testRunner) {
+	testRunner.dumpAsText();
+	testRunner.dumpChildFramesAsText();
+	testRunner.waitUntilDone();
+}
+
+function iframeDone()
+{
+	document.getElementById("logger").innerHTML += "After the iframe, document.cookie is '" + document.cookie + "'<br>";
+
+	if (window.testRunner)
+		testRunner.notifyDone();
+}
+
+function imageDone()
+{
+	document.getElementById("logger").innerHTML += "After the image, document.cookie is '" + document.cookie + "'<br>";
+	document.getElementById("iframe")._onload_ = iframeDone;
+	document.getElementById("iframe").src = ""
+}
+
+
+</script>
+
+This test loads a resource that sets a cookie, then verifies that the cookie is not sent out when it should be blocked.<br>
+<div id="logger"></div>
+<img src="" _onerror_="imageDone();">
+<iframe id="iframe"></iframe>

Added: trunk/LayoutTests/http/tests/usercontentfilter/block-cookies-send.html.json (0 => 180783)


--- trunk/LayoutTests/http/tests/usercontentfilter/block-cookies-send.html.json	                        (rev 0)
+++ trunk/LayoutTests/http/tests/usercontentfilter/block-cookies-send.html.json	2015-02-27 22:50:03 UTC (rev 180783)
@@ -0,0 +1,10 @@
+[
+    {
+        "action": {
+            "type": "block-cookies"
+        },
+        "trigger": {
+            "url-filter": "http://127.0.0.1:8000/cookies/resources/echo-cookies"
+        }
+    }
+]
\ No newline at end of file

Modified: trunk/Source/WebCore/ChangeLog (180782 => 180783)


--- trunk/Source/WebCore/ChangeLog	2015-02-27 22:45:33 UTC (rev 180782)
+++ trunk/Source/WebCore/ChangeLog	2015-02-27 22:50:03 UTC (rev 180783)
@@ -1,3 +1,31 @@
+2015-02-27  Brady Eidson  <beid...@apple.com>
+
+        Add a "block-cookies" rule to the user content filter.
+        https://bugs.webkit.org/show_bug.cgi?id=142105
+
+        Reviewed by Alex Christensen.
+
+        Tests: http/tests/usercontentfilter/block-cookies-basic.html
+               http/tests/usercontentfilter/block-cookies-send.html
+
+        * contentextensions/ContentExtensionRule.h:
+
+        * contentextensions/ContentExtensionsBackend.cpp:
+        (WebCore::ContentExtensions::ContentExtensionsBackend::actionForURL):
+        (WebCore::ContentExtensions::ContentExtensionsBackend::shouldBlockURL): Deleted.
+        * contentextensions/ContentExtensionsBackend.h:
+
+        * contentextensions/ContentExtensionsManager.cpp:
+        (WebCore::ContentExtensions::ExtensionsManager::loadAction):
+
+        * loader/cache/CachedResourceLoader.cpp:
+        (WebCore::CachedResourceLoader::requestResource):
+
+        * page/UserContentController.cpp:
+        (WebCore::UserContentController::actionForURL):
+        (WebCore::UserContentController::contentFilterBlocksURL): Deleted.
+        * page/UserContentController.h:
+
 2015-02-27  Alex Christensen  <achristen...@webkit.org>
 
         [WinCairo] Unreviewed build fix.

Modified: trunk/Source/WebCore/contentextensions/ContentExtensionRule.h (180782 => 180783)


--- trunk/Source/WebCore/contentextensions/ContentExtensionRule.h	2015-02-27 22:45:33 UTC (rev 180782)
+++ trunk/Source/WebCore/contentextensions/ContentExtensionRule.h	2015-02-27 22:50:03 UTC (rev 180783)
@@ -36,6 +36,7 @@
 
 enum class ExtensionActionType {
     BlockLoad,
+    BlockCookies,
     IgnorePreviousRules
 };
 

Modified: trunk/Source/WebCore/contentextensions/ContentExtensionsBackend.cpp (180782 => 180783)


--- trunk/Source/WebCore/contentextensions/ContentExtensionsBackend.cpp	2015-02-27 22:45:33 UTC (rev 180782)
+++ trunk/Source/WebCore/contentextensions/ContentExtensionsBackend.cpp	2015-02-27 22:50:03 UTC (rev 180783)
@@ -117,7 +117,7 @@
     m_ruleLists.clear();
 }
 
-bool ContentExtensionsBackend::shouldBlockURL(const URL& url)
+ContentFilterAction ContentExtensionsBackend::actionForURL(const URL& url)
 {
     const String& urlString = url.string();
     ASSERT_WITH_MESSAGE(urlString.containsOnlyASCII(), "A decoded URL should only contain ASCII characters. The matching algorithm assumes the input is ASCII.");
@@ -133,12 +133,16 @@
             copyToVector(triggeredActions, sortedActions);
             std::sort(sortedActions.begin(), sortedActions.end());
             size_t lastAction = static_cast<size_t>(sortedActions.last());
-            if (compiledContentExtension.ruleList[lastAction].action().type == ExtensionActionType::BlockLoad)
-                return true;
+            ExtensionActionType type = compiledContentExtension.ruleList[lastAction].action().type;
+
+            if (type == ExtensionActionType::BlockLoad)
+                return ContentFilterAction::Block;
+            if (type == ExtensionActionType::BlockCookies)
+                return ContentFilterAction::BlockCookies;
         }
     }
 
-    return false;
+    return ContentFilterAction::Load;
 }
 
 } // namespace ContentExtensions

Modified: trunk/Source/WebCore/contentextensions/ContentExtensionsBackend.h (180782 => 180783)


--- trunk/Source/WebCore/contentextensions/ContentExtensionsBackend.h	2015-02-27 22:45:33 UTC (rev 180782)
+++ trunk/Source/WebCore/contentextensions/ContentExtensionsBackend.h	2015-02-27 22:50:03 UTC (rev 180783)
@@ -31,6 +31,7 @@
 #include "ContentExtensionRule.h"
 #include "DFA.h"
 #include "DFABytecode.h"
+#include "UserContentController.h"
 #include <wtf/HashMap.h>
 #include <wtf/text/StringHash.h>
 #include <wtf/text/WTFString.h>
@@ -57,7 +58,7 @@
     void removeAllRuleLists();
 
     // - Internal WebCore Interface.
-    bool shouldBlockURL(const URL&);
+    ContentFilterAction actionForURL(const URL&);
 
 private:
     struct CompiledContentExtension {

Modified: trunk/Source/WebCore/contentextensions/ContentExtensionsManager.cpp (180782 => 180783)


--- trunk/Source/WebCore/contentextensions/ContentExtensionsManager.cpp	2015-02-27 22:45:33 UTC (rev 180782)
+++ trunk/Source/WebCore/contentextensions/ContentExtensionsManager.cpp	2015-02-27 22:50:03 UTC (rev 180783)
@@ -96,6 +96,8 @@
         action.type = ExtensionActionType::BlockLoad;
     else if (actionType == "ignore-previous-rules")
         action.type = ExtensionActionType::IgnorePreviousRules;
+    else if (actionType == "block-cookies")
+        action.type = ExtensionActionType::BlockCookies;
     else if (actionType != "block" && actionType != "") {
         WTFLogAlways("Unrecognized action: \"%s\"", actionType.utf8().data());
         return false;

Modified: trunk/Source/WebCore/loader/cache/CachedResourceLoader.cpp (180782 => 180783)


--- trunk/Source/WebCore/loader/cache/CachedResourceLoader.cpp	2015-02-27 22:45:33 UTC (rev 180782)
+++ trunk/Source/WebCore/loader/cache/CachedResourceLoader.cpp	2015-02-27 22:50:03 UTC (rev 180783)
@@ -464,8 +464,16 @@
         return nullptr;
 
 #if ENABLE(CONTENT_EXTENSIONS)
-    if (frame() && frame()->page() && frame()->page()->userContentController() && frame()->page()->userContentController()->contentFilterBlocksURL(url))
-        return nullptr;
+    ContentFilterAction action = ""
+
+    if (frame() && frame()->page() && frame()->page()->userContentController()) {
+        action = ""
+        if (action == ContentFilterAction::Block)
+            return nullptr;
+    }
+
+    if (action == ContentFilterAction::BlockCookies)
+        request.mutableResourceRequest().setAllowCookies(false);
 #endif
 
     auto& memoryCache = MemoryCache::singleton();

Modified: trunk/Source/WebCore/page/UserContentController.cpp (180782 => 180783)


--- trunk/Source/WebCore/page/UserContentController.cpp	2015-02-27 22:45:33 UTC (rev 180782)
+++ trunk/Source/WebCore/page/UserContentController.cpp	2015-02-27 22:50:03 UTC (rev 180783)
@@ -203,12 +203,12 @@
     m_contentExtensionBackend->removeAllRuleLists();
 }
 
-bool UserContentController::contentFilterBlocksURL(const URL& url)
+ContentFilterAction UserContentController::actionForURL(const URL& url)
 {
     if (!m_contentExtensionBackend)
-        return false;
+        return ContentFilterAction::Load;
 
-    return m_contentExtensionBackend->shouldBlockURL(url);
+    return m_contentExtensionBackend->actionForURL(url);
 }
 
 #endif

Modified: trunk/Source/WebCore/page/UserContentController.h (180782 => 180783)


--- trunk/Source/WebCore/page/UserContentController.h	2015-02-27 22:45:33 UTC (rev 180782)
+++ trunk/Source/WebCore/page/UserContentController.h	2015-02-27 22:50:03 UTC (rev 180783)
@@ -49,6 +49,12 @@
 class ContentExtensionsBackend;
 }
 
+enum class ContentFilterAction {
+    Load,
+    Block,
+    BlockCookies
+};
+
 class UserContentController : public RefCounted<UserContentController> {
 public:
     WEBCORE_EXPORT static RefPtr<UserContentController> create();
@@ -85,7 +91,7 @@
     WEBCORE_EXPORT void removeAllUserContentFilters();
     
     // FIXME: Consider putting this (and other future content filter predicates) in its own class.
-    bool contentFilterBlocksURL(const URL&);
+    ContentFilterAction actionForURL(const URL&);
 #endif
 
 private:
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to