Title: [219797] trunk
Revision
219797
Author
[email protected]
Date
2017-07-24 01:33:11 -0700 (Mon, 24 Jul 2017)

Log Message

Add attribute allow-top-navigation-by-user-activation to iframe sandbox
https://bugs.webkit.org/show_bug.cgi?id=171327

Patch by Frederic Wang <[email protected]> on 2017-07-11
Reviewed by Chris Dumez.

LayoutTests/imported/w3c:

This commit updates the expectation for the test verifying that a sandboxed iframe without
the allow-top-navigation-by-user-activation flag set can not perform top navigation if it is
not triggered by a user gesture. The navigation is still prohibited but the parsing of the
allow-top-navigation-by-user-activation flag should not raised any error message.
A similar update is done for the test verifying that the combination of the flags
allow-top-navigation-by-user-activation and allow-top-navigation.

* web-platform-tests/html/semantics/embedded-content/the-iframe-element/iframe_sandbox_allow_top_navigation_by_user_activation_without_user_gesture-expected.txt: Remove the error message.
* web-platform-tests/html/semantics/embedded-content/the-iframe-element/iframe_sandbox_allow_top_navigation-3-expected.txt: Ditto.

Source/WebCore:

Tests: http/tests/security/frameNavigation/sandbox-ALLOWED-top-navigation-with-user-gesture-1.html
       http/tests/security/frameNavigation/sandbox-ALLOWED-top-navigation-with-user-gesture-2.html
       imported/w3c/web-platform-tests/html/semantics/embedded-content/the-iframe-element/iframe_sandbox_allow_top_navigation_by_user_activation_without_user_gesture-expected.txt
       imported/w3c/web-platform-tests/html/semantics/embedded-content/the-iframe-element/iframe_sandbox_allow_top_navigation-3-expected.txt

* dom/Document.cpp:
(WebCore::Document::canNavigate): Case 2 of conformance verification is refined to match the
current specification: Top navigation is allowed when it is triggered by user activation and
when allow-top-navigation-by-user-activation is set. Because we have additional "security
origin" rules with respect to the specification we also add some early return to ensure that
navigation is really allowed for this new case.
* dom/SecurityContext.cpp:
(WebCore::SecurityContext::isSupportedSandboxPolicy): Add allow-top-navigation-by-user-activation flag.
(WebCore::SecurityContext::parseSandboxPolicy): Parse the new flag to allow top user
navigation by user activation. Also, make sure that allow-top-navigation allows such
navigation as defined by the specification.
* dom/SecurityContext.h: Declare new sandboxing flag.

LayoutTests:

This patch adds tests to verify that a sandboxed iframe with the flag
'allow-top-navigation-by-user-activation' or 'allow-top-navigation' can navigate the top
level page, if navigation is triggered by a user gesture. This is based on a test from the
Chromium repository.
It also verifies that navigation fails when 'allow-top-navigation-by-user-activation' is
absent, even when it is triggered by a user gesture.

* http/tests/security/frameNavigation/resources/iframe-that-performs-parent-navigation-with-user-activation.html: Added. This is similar to iframe-that-performs-parent-navigation.html but it
performs navigation of its parent using user activation.
* http/tests/security/frameNavigation/sandbox-ALLOWED-top-navigation-with-user-gesture-1.html: Added.
Test top navigation for a sandboxed frame with 'allow-top-navigation-by-user-activation'
* http/tests/security/frameNavigation/sandbox-ALLOWED-top-navigation-with-user-gesture-1-expected.txt: Added.
Add PASS expectation.
* http/tests/security/frameNavigation/sandbox-ALLOWED-top-navigation-with-user-gesture-2.html: Added.
Test top navigation for a sandboxed frame with 'allow-top-navigation'.
* http/tests/security/frameNavigation/sandbox-ALLOWED-top-navigation-with-user-gesture-2-expected.txt: Added.
Add PASS expectation.
* http/tests/security/frameNavigation/sandbox-DENIED-top-navigation-with-user-gesture.html: Added.
Test user-triggered navigation for a sandboxed frame without 'allow-top-navigation-by-user-activation'.
* http/tests/security/frameNavigation/sandbox-DENIED-top-navigation-with-user-gesture-expected.txt: Added.
Add reference with navigation failure.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (219796 => 219797)


--- trunk/LayoutTests/ChangeLog	2017-07-24 06:47:25 UTC (rev 219796)
+++ trunk/LayoutTests/ChangeLog	2017-07-24 08:33:11 UTC (rev 219797)
@@ -1,3 +1,32 @@
+2017-07-11  Frederic Wang  <[email protected]>
+
+        Add attribute allow-top-navigation-by-user-activation to iframe sandbox
+        https://bugs.webkit.org/show_bug.cgi?id=171327
+
+        Reviewed by Chris Dumez.
+
+        This patch adds tests to verify that a sandboxed iframe with the flag
+        'allow-top-navigation-by-user-activation' or 'allow-top-navigation' can navigate the top
+        level page, if navigation is triggered by a user gesture. This is based on a test from the
+        Chromium repository.
+        It also verifies that navigation fails when 'allow-top-navigation-by-user-activation' is
+        absent, even when it is triggered by a user gesture.
+
+        * http/tests/security/frameNavigation/resources/iframe-that-performs-parent-navigation-with-user-activation.html: Added. This is similar to iframe-that-performs-parent-navigation.html but it
+        performs navigation of its parent using user activation.
+        * http/tests/security/frameNavigation/sandbox-ALLOWED-top-navigation-with-user-gesture-1.html: Added.
+        Test top navigation for a sandboxed frame with 'allow-top-navigation-by-user-activation'
+        * http/tests/security/frameNavigation/sandbox-ALLOWED-top-navigation-with-user-gesture-1-expected.txt: Added.
+        Add PASS expectation.
+        * http/tests/security/frameNavigation/sandbox-ALLOWED-top-navigation-with-user-gesture-2.html: Added.
+        Test top navigation for a sandboxed frame with 'allow-top-navigation'.
+        * http/tests/security/frameNavigation/sandbox-ALLOWED-top-navigation-with-user-gesture-2-expected.txt: Added.
+        Add PASS expectation.
+        * http/tests/security/frameNavigation/sandbox-DENIED-top-navigation-with-user-gesture.html: Added.
+        Test user-triggered navigation for a sandboxed frame without 'allow-top-navigation-by-user-activation'.
+        * http/tests/security/frameNavigation/sandbox-DENIED-top-navigation-with-user-gesture-expected.txt: Added.
+        Add reference with navigation failure.
+
 2017-07-22  Chris Dumez  <[email protected]>
 
         Merge ExceptionBase into DOMException and drop custom toString

Added: trunk/LayoutTests/http/tests/security/frameNavigation/resources/iframe-that-performs-parent-navigation-with-user-activation.html (0 => 219797)


--- trunk/LayoutTests/http/tests/security/frameNavigation/resources/iframe-that-performs-parent-navigation-with-user-activation.html	                        (rev 0)
+++ trunk/LayoutTests/http/tests/security/frameNavigation/resources/iframe-that-performs-parent-navigation-with-user-activation.html	2017-07-24 08:33:11 UTC (rev 219797)
@@ -0,0 +1,34 @@
+<html>
+<head>
+    <script src=""
+    <script>
+        function loaded()
+        {
+            document.getElementsByTagName('h4')[0].innerHTML = document.domain;
+        }
+
+        function startTest(event)
+        {
+            var button = document.getElementById("button");
+            UIHelper.activateAt(event.data.x + button.offsetLeft + 2, event.data.y + button.offsetTop + 2).catch(function(reason) {
+                parent.postMessage("Failed to emulate user interaction: " + reason, "*");
+            });
+        }
+
+        function performTest()
+        {
+            try {
+                parent.location = "http://localhost:8000/security/frameNavigation/resources/navigation-changed-iframe.html";
+            } catch (e) {
+                parent.postMessage("cannot navigate", "*");
+            }
+        }
+
+        window.addEventListener("message", startTest, false);
+    </script>
+</head>
+<body _onload_="loaded();">
+    <h4>DOMAIN</h4>
+    <button id="button" _onclick_="performTest();">Perform Test</button>
+</body>
+</html>
Property changes on: trunk/LayoutTests/http/tests/security/frameNavigation/resources/iframe-that-performs-parent-navigation-with-user-activation.html
___________________________________________________________________

Added: svn:eol-style

+LF \ No newline at end of property

Added: svn:mime-type

+text/html \ No newline at end of property

Added: trunk/LayoutTests/http/tests/security/frameNavigation/sandbox-ALLOWED-top-navigation-with-user-gesture-1-expected.txt (0 => 219797)


--- trunk/LayoutTests/http/tests/security/frameNavigation/sandbox-ALLOWED-top-navigation-with-user-gesture-1-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/http/tests/security/frameNavigation/sandbox-ALLOWED-top-navigation-with-user-gesture-1-expected.txt	2017-07-24 08:33:11 UTC (rev 219797)
@@ -0,0 +1,3 @@
+localhost
+
+PASSED: Navigation succeeded.
Property changes on: trunk/LayoutTests/http/tests/security/frameNavigation/sandbox-ALLOWED-top-navigation-with-user-gesture-1-expected.txt
___________________________________________________________________

Added: svn:eol-style

+LF \ No newline at end of property

Added: trunk/LayoutTests/http/tests/security/frameNavigation/sandbox-ALLOWED-top-navigation-with-user-gesture-1.html (0 => 219797)


--- trunk/LayoutTests/http/tests/security/frameNavigation/sandbox-ALLOWED-top-navigation-with-user-gesture-1.html	                        (rev 0)
+++ trunk/LayoutTests/http/tests/security/frameNavigation/sandbox-ALLOWED-top-navigation-with-user-gesture-1.html	2017-07-24 08:33:11 UTC (rev 219797)
@@ -0,0 +1,34 @@
+<html>
+<head>
+    <style>
+        iframe { width: 400px; height: 200px;}
+    </style>
+    <script>
+        if (window.testRunner) {
+            testRunner.dumpAsText();
+            testRunner.waitUntilDone();
+        }
+
+        function loaded()
+        {
+            document.getElementsByTagName('h4')[0].innerHTML = document.domain;
+            var iframe = document.getElementById("iframe");
+            // The iframe uses eventSender to emulate a user navigation, which requires absolute coordinates.
+            // Because the iframe is cross-origin, it can't get the offsets itself, so leak them.
+            frames[0].postMessage({x: iframe.offsetLeft, y: iframe.offsetTop}, "*");
+        }
+
+        window.addEventListener("message", function(event) {
+            console.error(event.data);
+            if (window.testRunner)
+                testRunner.notifyDone();
+        }, false);
+    </script>
+</head>
+<body _onload_="loaded();">
+    <p>This tests that a sandboxed iframe with 'allow-top-navigation-by-user-activation'
+    can navigate the top level page, if navigation is trigged by a user gesture.</p>
+    <h4>DOMAIN</h4>
+    <iframe id="iframe" sandbox="allow-scripts allow-top-navigation-by-user-activation" src=""
+</body>
+</html>
Property changes on: trunk/LayoutTests/http/tests/security/frameNavigation/sandbox-ALLOWED-top-navigation-with-user-gesture-1.html
___________________________________________________________________

Added: svn:eol-style

+LF \ No newline at end of property

Added: svn:mime-type

+text/html \ No newline at end of property

Added: trunk/LayoutTests/http/tests/security/frameNavigation/sandbox-ALLOWED-top-navigation-with-user-gesture-2-expected.txt (0 => 219797)


--- trunk/LayoutTests/http/tests/security/frameNavigation/sandbox-ALLOWED-top-navigation-with-user-gesture-2-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/http/tests/security/frameNavigation/sandbox-ALLOWED-top-navigation-with-user-gesture-2-expected.txt	2017-07-24 08:33:11 UTC (rev 219797)
@@ -0,0 +1,3 @@
+localhost
+
+PASSED: Navigation succeeded.
Property changes on: trunk/LayoutTests/http/tests/security/frameNavigation/sandbox-ALLOWED-top-navigation-with-user-gesture-2-expected.txt
___________________________________________________________________

Added: svn:eol-style

+LF \ No newline at end of property

Added: trunk/LayoutTests/http/tests/security/frameNavigation/sandbox-ALLOWED-top-navigation-with-user-gesture-2.html (0 => 219797)


--- trunk/LayoutTests/http/tests/security/frameNavigation/sandbox-ALLOWED-top-navigation-with-user-gesture-2.html	                        (rev 0)
+++ trunk/LayoutTests/http/tests/security/frameNavigation/sandbox-ALLOWED-top-navigation-with-user-gesture-2.html	2017-07-24 08:33:11 UTC (rev 219797)
@@ -0,0 +1,34 @@
+<html>
+<head>
+    <style>
+        iframe { width: 400px; height: 200px;}
+    </style>
+    <script>
+        if (window.testRunner) {
+            testRunner.dumpAsText();
+            testRunner.waitUntilDone();
+        }
+
+        function loaded()
+        {
+            document.getElementsByTagName('h4')[0].innerHTML = document.domain;
+            var iframe = document.getElementById("iframe");
+            // The iframe uses eventSender to emulate a user navigation, which requires absolute coordinates.
+            // Because the iframe is cross-origin, it can't get the offsets itself, so leak them.
+            frames[0].postMessage({x: iframe.offsetLeft, y: iframe.offsetTop}, "*");
+        }
+
+        window.addEventListener("message", function(event) {
+            console.error(event.data);
+            if (window.testRunner)
+                testRunner.notifyDone();
+        }, false);
+    </script>
+</head>
+<body _onload_="loaded();">
+    <p>This tests that a sandboxed iframe with 'allow-top-navigation'
+    can navigate the top level page, if navigation is trigged by a user gesture.</p>
+    <h4>DOMAIN</h4>
+    <iframe id="iframe" sandbox="allow-scripts allow-top-navigation" src=""
+</body>
+</html>
Property changes on: trunk/LayoutTests/http/tests/security/frameNavigation/sandbox-ALLOWED-top-navigation-with-user-gesture-2.html
___________________________________________________________________

Added: svn:eol-style

+LF \ No newline at end of property

Added: svn:mime-type

+text/html \ No newline at end of property

Added: trunk/LayoutTests/http/tests/security/frameNavigation/sandbox-DENIED-top-navigation-with-user-gesture-expected.txt (0 => 219797)


--- trunk/LayoutTests/http/tests/security/frameNavigation/sandbox-DENIED-top-navigation-with-user-gesture-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/http/tests/security/frameNavigation/sandbox-DENIED-top-navigation-with-user-gesture-expected.txt	2017-07-24 08:33:11 UTC (rev 219797)
@@ -0,0 +1,8 @@
+CONSOLE MESSAGE: line 32: Unsafe _javascript_ attempt to initiate navigation for frame with URL 'http://127.0.0.1:8000/security/frameNavigation/sandbox-DENIED-top-navigation-with-user-gesture.html' from frame with URL 'http://127.0.0.1:8000/security/frameNavigation/resources/iframe-that-performs-parent-navigation-with-user-activation.html'. The frame attempting navigation of the top-level window is sandboxed, but the 'allow-top-navigation-by-user-activation' flag is not set and navigation is not triggered by user activation.
+
+CONSOLE MESSAGE: line 22: cannot navigate
+This tests that a sandboxed iframe without 'allow-top-navigation-by-user-activation' cannot navigate the top level page, even when navigation is trigged by a user gesture.
+
+127.0.0.1
+
+
Property changes on: trunk/LayoutTests/http/tests/security/frameNavigation/sandbox-DENIED-top-navigation-with-user-gesture-expected.txt
___________________________________________________________________

Added: svn:eol-style

+LF \ No newline at end of property

Added: trunk/LayoutTests/http/tests/security/frameNavigation/sandbox-DENIED-top-navigation-with-user-gesture.html (0 => 219797)


--- trunk/LayoutTests/http/tests/security/frameNavigation/sandbox-DENIED-top-navigation-with-user-gesture.html	                        (rev 0)
+++ trunk/LayoutTests/http/tests/security/frameNavigation/sandbox-DENIED-top-navigation-with-user-gesture.html	2017-07-24 08:33:11 UTC (rev 219797)
@@ -0,0 +1,34 @@
+<html>
+<head>
+    <style>
+        iframe { width: 400px; height: 200px;}
+    </style>
+    <script>
+        if (window.testRunner) {
+            testRunner.dumpAsText();
+            testRunner.waitUntilDone();
+        }
+
+        function loaded()
+        {
+            document.getElementsByTagName('h4')[0].innerHTML = document.domain;
+            var iframe = document.getElementById("iframe");
+            // The iframe uses eventSender to emulate a user navigation, which requires absolute coordinates.
+            // Because the iframe is cross-origin, it can't get the offsets itself, so leak them.
+            frames[0].postMessage({x: iframe.offsetLeft, y: iframe.offsetTop}, "*");
+        }
+
+        window.addEventListener("message", function(event) {
+            console.error(event.data);
+            if (window.testRunner)
+                testRunner.notifyDone();
+        }, false);
+    </script>
+</head>
+<body _onload_="loaded();">
+    <p>This tests that a sandboxed iframe without 'allow-top-navigation-by-user-activation'
+    cannot navigate the top level page, even when navigation is trigged by a user gesture.</p>
+    <h4>DOMAIN</h4>
+    <iframe id="iframe" sandbox="allow-scripts" src=""
+</body>
+</html>
Property changes on: trunk/LayoutTests/http/tests/security/frameNavigation/sandbox-DENIED-top-navigation-with-user-gesture.html
___________________________________________________________________

Added: svn:eol-style

+LF \ No newline at end of property

Added: svn:mime-type

+text/html \ No newline at end of property

Modified: trunk/LayoutTests/imported/w3c/ChangeLog (219796 => 219797)


--- trunk/LayoutTests/imported/w3c/ChangeLog	2017-07-24 06:47:25 UTC (rev 219796)
+++ trunk/LayoutTests/imported/w3c/ChangeLog	2017-07-24 08:33:11 UTC (rev 219797)
@@ -1,3 +1,20 @@
+2017-07-11  Frederic Wang  <[email protected]>
+
+        Add attribute allow-top-navigation-by-user-activation to iframe sandbox
+        https://bugs.webkit.org/show_bug.cgi?id=171327
+
+        Reviewed by Chris Dumez.
+
+        This commit updates the expectation for the test verifying that a sandboxed iframe without
+        the allow-top-navigation-by-user-activation flag set can not perform top navigation if it is
+        not triggered by a user gesture. The navigation is still prohibited but the parsing of the
+        allow-top-navigation-by-user-activation flag should not raised any error message.
+        A similar update is done for the test verifying that the combination of the flags
+        allow-top-navigation-by-user-activation and allow-top-navigation.
+
+        * web-platform-tests/html/semantics/embedded-content/the-iframe-element/iframe_sandbox_allow_top_navigation_by_user_activation_without_user_gesture-expected.txt: Remove the error message.
+        * web-platform-tests/html/semantics/embedded-content/the-iframe-element/iframe_sandbox_allow_top_navigation-3-expected.txt: Ditto.
+
 2017-07-22  Chris Dumez  <[email protected]>
 
         Merge ExceptionBase into DOMException and drop custom toString

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/html/semantics/embedded-content/the-iframe-element/iframe_sandbox_allow_top_navigation-3-expected.txt (219796 => 219797)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/html/semantics/embedded-content/the-iframe-element/iframe_sandbox_allow_top_navigation-3-expected.txt	2017-07-24 06:47:25 UTC (rev 219796)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/html/semantics/embedded-content/the-iframe-element/iframe_sandbox_allow_top_navigation-3-expected.txt	2017-07-24 08:33:11 UTC (rev 219797)
@@ -1,5 +1,3 @@
-CONSOLE MESSAGE: line 15: Error while parsing the 'sandbox' attribute: 'allow-top-navigation-by-user-activation' is an invalid sandbox flag.
-CONSOLE MESSAGE: line 15: Error while parsing the 'sandbox' attribute: 'allow-top-navigation-by-user-activation' is an invalid sandbox flag.
 
 
 PASS Frames with `allow-top-navigation` should be able to navigate the top frame even when `allow-top-navigation-by-user-activation` is set. 

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/html/semantics/embedded-content/the-iframe-element/iframe_sandbox_allow_top_navigation_by_user_activation_without_user_gesture-expected.txt (219796 => 219797)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/html/semantics/embedded-content/the-iframe-element/iframe_sandbox_allow_top_navigation_by_user_activation_without_user_gesture-expected.txt	2017-07-24 06:47:25 UTC (rev 219796)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/html/semantics/embedded-content/the-iframe-element/iframe_sandbox_allow_top_navigation_by_user_activation_without_user_gesture-expected.txt	2017-07-24 08:33:11 UTC (rev 219797)
@@ -1,4 +1,3 @@
-CONSOLE MESSAGE: line 17: Error while parsing the 'sandbox' attribute: 'allow-top-navigation-by-user-activation' is an invalid sandbox flag.
 CONSOLE MESSAGE: line 8: Unsafe _javascript_ attempt to initiate navigation for frame with URL 'http://localhost:8800/html/semantics/embedded-content/the-iframe-element/iframe_sandbox_allow_top_navigation_by_user_activation_without_user_gesture.html' from frame with URL 'http://localhost:8800/html/semantics/embedded-content/the-iframe-element/support/iframe-that-performs-top-navigation-without-user-gesture-failed.html'. The frame attempting navigation of the top-level window is sandboxed, but the 'allow-top-navigation' flag is not set.
 
 This tests that an iframe in sandbox with 'allow-top-navigation-by-user-activation' cannot navigate its top level page, if it is not trigged by a user gesture.

Modified: trunk/Source/WebCore/ChangeLog (219796 => 219797)


--- trunk/Source/WebCore/ChangeLog	2017-07-24 06:47:25 UTC (rev 219796)
+++ trunk/Source/WebCore/ChangeLog	2017-07-24 08:33:11 UTC (rev 219797)
@@ -1,3 +1,28 @@
+2017-07-11  Frederic Wang  <[email protected]>
+
+        Add attribute allow-top-navigation-by-user-activation to iframe sandbox
+        https://bugs.webkit.org/show_bug.cgi?id=171327
+
+        Reviewed by Chris Dumez.
+
+        Tests: http/tests/security/frameNavigation/sandbox-ALLOWED-top-navigation-with-user-gesture-1.html
+               http/tests/security/frameNavigation/sandbox-ALLOWED-top-navigation-with-user-gesture-2.html
+               imported/w3c/web-platform-tests/html/semantics/embedded-content/the-iframe-element/iframe_sandbox_allow_top_navigation_by_user_activation_without_user_gesture-expected.txt
+               imported/w3c/web-platform-tests/html/semantics/embedded-content/the-iframe-element/iframe_sandbox_allow_top_navigation-3-expected.txt
+
+        * dom/Document.cpp:
+        (WebCore::Document::canNavigate): Case 2 of conformance verification is refined to match the
+        current specification: Top navigation is allowed when it is triggered by user activation and
+        when allow-top-navigation-by-user-activation is set. Because we have additional "security
+        origin" rules with respect to the specification we also add some early return to ensure that
+        navigation is really allowed for this new case.
+        * dom/SecurityContext.cpp:
+        (WebCore::SecurityContext::isSupportedSandboxPolicy): Add allow-top-navigation-by-user-activation flag.
+        (WebCore::SecurityContext::parseSandboxPolicy): Parse the new flag to allow top user
+        navigation by user activation. Also, make sure that allow-top-navigation allows such
+        navigation as defined by the specification.
+        * dom/SecurityContext.h: Declare new sandboxing flag.
+
 2017-07-23  Wenson Hsieh  <[email protected]>
 
         [iOS WK2] 5 DataInteractionTests are failing: observed selection rects after dropping don't match expected values

Modified: trunk/Source/WebCore/dom/Document.cpp (219796 => 219797)


--- trunk/Source/WebCore/dom/Document.cpp	2017-07-24 06:47:25 UTC (rev 219796)
+++ trunk/Source/WebCore/dom/Document.cpp	2017-07-24 08:33:11 UTC (rev 219797)
@@ -186,6 +186,7 @@
 #include "TextNodeTraversal.h"
 #include "TransformSource.h"
 #include "TreeWalker.h"
+#include "UserGestureIndicator.h"
 #include "ValidationMessageClient.h"
 #include "VisibilityChangeClient.h"
 #include "VisitedLinkState.h"
@@ -3093,14 +3094,17 @@
     if (!targetFrame)
         return true;
 
-    // Cases (i) and (ii) pass the tests from the specifications but might not pass the "security origin" tests.
-    // Hence they are kept for backward compatibility.
+    // Cases (i), (ii) and (iii) pass the tests from the specifications but might not pass the "security origin" tests.
 
     // i. A frame can navigate its top ancestor when its 'allow-top-navigation' flag is set (sometimes known as 'frame-busting').
     if (!isSandboxed(SandboxTopNavigation) && targetFrame == &m_frame->tree().top())
         return true;
 
-    // ii. A sandboxed frame can always navigate its descendants.
+    // ii. A frame can navigate its top ancestor when its 'allow-top-navigation-by-user-activation' flag is set and navigation is triggered by user activation.
+    if (!isSandboxed(SandboxTopNavigationByUserActivation) && UserGestureIndicator::processingUserGesture() && targetFrame == &m_frame->tree().top())
+        return true;
+
+    // iii. A sandboxed frame can always navigate its descendants.
     if (isSandboxed(SandboxNavigation) && targetFrame->tree().isDescendantOf(m_frame))
         return true;
 
@@ -3112,11 +3116,19 @@
         return false;
     }
 
-    // 2. Otherwise, if B is a top-level browsing context, and is one of the ancestor browsing contexts of A, and A's active document's active sandboxing flag set has its sandboxed
-    // top-level navigation browsing context flag set, then abort these steps negatively.
-    if (m_frame != targetFrame && targetFrame == &m_frame->tree().top() && isSandboxed(SandboxTopNavigation)) {
-        printNavigationErrorMessage(targetFrame, url(), ASCIILiteral("The frame attempting navigation of the top-level window is sandboxed, but the 'allow-top-navigation' flag is not set."));
-        return false;
+    // 2. Otherwise, if B is a top-level browsing context, and is one of the ancestor browsing contexts of A, then:
+    if (m_frame != targetFrame && targetFrame == &m_frame->tree().top()) {
+        bool triggeredByUserActivation = UserGestureIndicator::processingUserGesture();
+        // 1. If this algorithm is triggered by user activation and A's active document's active sandboxing flag set has its sandboxed top-level navigation with user activation browsing context flag set, then abort these steps negatively.
+        if (triggeredByUserActivation && isSandboxed(SandboxTopNavigationByUserActivation)) {
+            printNavigationErrorMessage(targetFrame, url(), ASCIILiteral("The frame attempting navigation of the top-level window is sandboxed, but the 'allow-top-navigation-by-user-activation' flag is not set and navigation is not triggered by user activation."));
+            return false;
+        }
+        // 2. Otherwise, If this algorithm is not triggered by user activation and A's active document's active sandboxing flag set has its sandboxed top-level navigation without user activation browsing context flag set, then abort these steps negatively.
+        if (!triggeredByUserActivation && isSandboxed(SandboxTopNavigation)) {
+            printNavigationErrorMessage(targetFrame, url(), ASCIILiteral("The frame attempting navigation of the top-level window is sandboxed, but the 'allow-top-navigation' flag is not set."));
+            return false;
+        }
     }
 
     // 3. Otherwise, if B is a top-level browsing context, and is neither A nor one of the ancestor browsing contexts of A, and A's Document's active sandboxing flag set has its

Modified: trunk/Source/WebCore/dom/SecurityContext.cpp (219796 => 219797)


--- trunk/Source/WebCore/dom/SecurityContext.cpp	2017-07-24 06:47:25 UTC (rev 219796)
+++ trunk/Source/WebCore/dom/SecurityContext.cpp	2017-07-24 08:33:11 UTC (rev 219797)
@@ -85,7 +85,7 @@
 bool SecurityContext::isSupportedSandboxPolicy(StringView policy)
 {
     static const char* const supportedPolicies[] = {
-        "allow-forms", "allow-same-origin", "allow-scripts", "allow-top-navigation", "allow-pointer-lock", "allow-popups", "allow-popups-to-escape-sandbox"
+        "allow-forms", "allow-same-origin", "allow-scripts", "allow-top-navigation", "allow-pointer-lock", "allow-popups", "allow-popups-to-escape-sandbox", "allow-top-navigation-by-user-activation"
     };
 
     for (auto* supportedPolicy : supportedPolicies) {
@@ -123,14 +123,17 @@
         else if (equalLettersIgnoringASCIICase(sandboxToken, "allow-scripts")) {
             flags &= ~SandboxScripts;
             flags &= ~SandboxAutomaticFeatures;
-        } else if (equalLettersIgnoringASCIICase(sandboxToken, "allow-top-navigation"))
+        } else if (equalLettersIgnoringASCIICase(sandboxToken, "allow-top-navigation")) {
             flags &= ~SandboxTopNavigation;
-        else if (equalLettersIgnoringASCIICase(sandboxToken, "allow-popups"))
+            flags &= ~SandboxTopNavigationByUserActivation;
+        } else if (equalLettersIgnoringASCIICase(sandboxToken, "allow-popups"))
             flags &= ~SandboxPopups;
         else if (equalLettersIgnoringASCIICase(sandboxToken, "allow-pointer-lock"))
             flags &= ~SandboxPointerLock;
         else if (equalLettersIgnoringASCIICase(sandboxToken, "allow-popups-to-escape-sandbox"))
             flags &= ~SandboxPropagatesToAuxiliaryBrowsingContexts;
+        else if (equalLettersIgnoringASCIICase(sandboxToken, "allow-top-navigation-by-user-activation"))
+            flags &= ~SandboxTopNavigationByUserActivation;
         else {
             if (numberOfTokenErrors)
                 tokenErrors.appendLiteral(", '");

Modified: trunk/Source/WebCore/dom/SecurityContext.h (219796 => 219797)


--- trunk/Source/WebCore/dom/SecurityContext.h	2017-07-24 06:47:25 UTC (rev 219796)
+++ trunk/Source/WebCore/dom/SecurityContext.h	2017-07-24 08:33:11 UTC (rev 219797)
@@ -50,6 +50,7 @@
     SandboxAutomaticFeatures    = 1 << 7,
     SandboxPointerLock          = 1 << 8,
     SandboxPropagatesToAuxiliaryBrowsingContexts = 1 << 9,
+    SandboxTopNavigationByUserActivation = 1 << 10,
     SandboxAll                  = -1 // Mask with all bits set to 1.
 };
 
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to