Deny Notification API access for non secure contexts
authoryouenn@apple.com <youenn@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 24 Dec 2019 14:41:20 +0000 (14:41 +0000)
committeryouenn@apple.com <youenn@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 24 Dec 2019 14:41:20 +0000 (14:41 +0000)
https://bugs.webkit.org/show_bug.cgi?id=205496
<rdar://problem/58074660>

Reviewed by Chris Dumez.

Source/WebCore:

If document is not SecureContext, deny permission automatically.
This behavior is matching a planned update to the spec, as discussed in
https://github.com/whatwg/notifications/issues/93.
Chrome landed this restriction in M62. Mozilla is also on board with this restriction.

Test: http/tests/notifications/notification-in-non-secure-context.html

* Modules/notifications/Notification.cpp:
(WebCore::Notification::requestPermission):

Tools:

* TestWebKitAPI/Tests/WebKitCocoa/UIDelegate.mm:
(TEST):

LayoutTests:

* http/tests/notifications/notification-in-non-secure-context-expected.txt: Added.
* http/tests/notifications/notification-in-non-secure-context.html: Added.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@253899 268f45cc-cd09-0410-ab3c-d52691b4dbfc

LayoutTests/ChangeLog
LayoutTests/http/tests/notifications/notification-in-non-secure-context-expected.txt [new file with mode: 0644]
LayoutTests/http/tests/notifications/notification-in-non-secure-context.html [new file with mode: 0644]
Source/WebCore/ChangeLog
Source/WebCore/Modules/notifications/Notification.cpp
Tools/ChangeLog
Tools/TestWebKitAPI/Tests/WebKitCocoa/UIDelegate.mm

index b2cd899..bf06554 100644 (file)
@@ -1,3 +1,14 @@
+2019-12-24  Youenn Fablet  <youenn@apple.com>
+
+        Deny Notification API access for non secure contexts
+        https://bugs.webkit.org/show_bug.cgi?id=205496
+        <rdar://problem/58074660>
+
+        Reviewed by Chris Dumez.
+
+        * http/tests/notifications/notification-in-non-secure-context-expected.txt: Added.
+        * http/tests/notifications/notification-in-non-secure-context.html: Added.
+
 2019-12-24  youenn fablet  <youenn@apple.com>
 
         Service Worker doesn't terminate after a period of time when thread blocking
diff --git a/LayoutTests/http/tests/notifications/notification-in-non-secure-context-expected.txt b/LayoutTests/http/tests/notifications/notification-in-non-secure-context-expected.txt
new file mode 100644 (file)
index 0000000..925fa65
--- /dev/null
@@ -0,0 +1,3 @@
+
+PASS Notification permission in insecure context 
+
diff --git a/LayoutTests/http/tests/notifications/notification-in-non-secure-context.html b/LayoutTests/http/tests/notifications/notification-in-non-secure-context.html
new file mode 100644 (file)
index 0000000..bc3efb6
--- /dev/null
@@ -0,0 +1,20 @@
+<!DOCTYPE html>
+<html>
+<body>
+<script src="/js-test-resources/testharness.js"></script>
+<script src="/js-test-resources/testharnessreport.js"></script>
+<script>
+var test = async_test("Notification permission in insecure context");
+
+// localhost is secure by default.
+if (window.internals)
+    internals.markContextAsInsecure();
+
+Notification.requestPermission(test.step_func((result) => {
+    assert_equals(result, "denied", "result");
+    assert_equals(Notification.permission, "denied", "getter");
+    test.done();
+}));
+</script>
+</body>
+</html>
index e527641..8720487 100644 (file)
@@ -1,3 +1,21 @@
+2019-12-24  Youenn Fablet  <youenn@apple.com>
+
+        Deny Notification API access for non secure contexts
+        https://bugs.webkit.org/show_bug.cgi?id=205496
+        <rdar://problem/58074660>
+
+        Reviewed by Chris Dumez.
+
+        If document is not SecureContext, deny permission automatically.
+        This behavior is matching a planned update to the spec, as discussed in
+        https://github.com/whatwg/notifications/issues/93.
+        Chrome landed this restriction in M62. Mozilla is also on board with this restriction.
+
+        Test: http/tests/notifications/notification-in-non-secure-context.html
+
+        * Modules/notifications/Notification.cpp:
+        (WebCore::Notification::requestPermission):
+
 2019-12-24  youenn fablet  <youenn@apple.com>
 
         Service Worker doesn't terminate after a period of time when thread blocking
index 0f68cf0..ca0225c 100644 (file)
@@ -191,6 +191,9 @@ auto Notification::permission(Document& document) -> Permission
     if (!page)
         return Permission::Default;
 
+    if (!document.isSecureContext())
+        return Permission::Denied;
+
     return NotificationController::from(document.page())->client().checkPermission(&document);
 }
 
@@ -200,6 +203,13 @@ void Notification::requestPermission(Document& document, RefPtr<NotificationPerm
     if (!page)
         return;
 
+    if (!document.isSecureContext()) {
+        document.eventLoop().queueTask(TaskSource::DOMManipulation, [callback = WTFMove(callback)]() mutable {
+            callback->handleEvent(Permission::Denied);
+        });
+        return;
+    }
+
     NotificationController::from(page)->client().requestPermission(&document, WTFMove(callback));
 }
 
index c7dc790..d376bf2 100644 (file)
@@ -1,3 +1,14 @@
+2019-12-24  Youenn Fablet  <youenn@apple.com>
+
+        Deny Notification API access for non secure contexts
+        https://bugs.webkit.org/show_bug.cgi?id=205496
+        <rdar://problem/58074660>
+
+        Reviewed by Chris Dumez.
+
+        * TestWebKitAPI/Tests/WebKitCocoa/UIDelegate.mm:
+        (TEST):
+
 2019-12-24  youenn fablet  <youenn@apple.com>
 
         Service Worker doesn't terminate after a period of time when thread blocking
index 3614417..0f8b129 100644 (file)
@@ -484,11 +484,11 @@ TEST(WebKit, NotificationPermission)
     NSString *html = @"<script>Notification.requestPermission(function(p){alert('permission '+p)})</script>";
     auto webView = adoptNS([[WKWebView alloc] init]);
     [webView setUIDelegate:[[[NotificationDelegate alloc] initWithAllowNotifications:YES] autorelease]];
-    [webView loadHTMLString:html baseURL:[NSURL URLWithString:@"http://example.org"]];
+    [webView loadHTMLString:html baseURL:[NSURL URLWithString:@"https://example.org"]];
     TestWebKitAPI::Util::run(&done);
     done = false;
     [webView setUIDelegate:[[[NotificationDelegate alloc] initWithAllowNotifications:NO] autorelease]];
-    [webView loadHTMLString:html baseURL:[NSURL URLWithString:@"http://example.com"]];
+    [webView loadHTMLString:html baseURL:[NSURL URLWithString:@"https://example.com"]];
     TestWebKitAPI::Util::run(&done);
 }