- Revision
- 251709
- Author
- [email protected]
- Date
- 2019-10-29 09:57:09 -0700 (Tue, 29 Oct 2019)
Log Message
Notification permissions are not remembered for origins without port
https://bugs.webkit.org/show_bug.cgi?id=203537
<rdar://problem/55281080>
Reviewed by Brady Eidson.
Source/WebKit:
When WKSecurityOriginCreate() gets called with a port that is invalid, then pass
WTF::nullopt to construct the security origin instead of the invalid port.
The issue is that the port for security origins is optional internally. However,
our API (WKSecurityOriginGetPort() & WKSecurityOrigin.port) will return 0 when
there is no port. As a result, clients such as Safari sometimes pass 0 as port to construct
a new WKSecurityOriginRef().
This was causing issues with regards to notifications because Safari would construct
origins whose string representation looks like "https://www.apple.com:0" and it would
not match the "https://www.apple.com" we expect internally.
* Shared/API/c/WKSecurityOriginRef.cpp:
(WKSecurityOriginCreate):
Tools:
Add API test coverage.
* TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
* TestWebKitAPI/Tests/WebKit/WKSecurityOrigin.cpp: Added.
(TestWebKitAPI::TEST):
Modified Paths
Added Paths
Diff
Modified: trunk/Source/WebKit/ChangeLog (251708 => 251709)
--- trunk/Source/WebKit/ChangeLog 2019-10-29 16:56:03 UTC (rev 251708)
+++ trunk/Source/WebKit/ChangeLog 2019-10-29 16:57:09 UTC (rev 251709)
@@ -1,3 +1,26 @@
+2019-10-29 Chris Dumez <[email protected]>
+
+ Notification permissions are not remembered for origins without port
+ https://bugs.webkit.org/show_bug.cgi?id=203537
+ <rdar://problem/55281080>
+
+ Reviewed by Brady Eidson.
+
+ When WKSecurityOriginCreate() gets called with a port that is invalid, then pass
+ WTF::nullopt to construct the security origin instead of the invalid port.
+
+ The issue is that the port for security origins is optional internally. However,
+ our API (WKSecurityOriginGetPort() & WKSecurityOrigin.port) will return 0 when
+ there is no port. As a result, clients such as Safari sometimes pass 0 as port to construct
+ a new WKSecurityOriginRef().
+
+ This was causing issues with regards to notifications because Safari would construct
+ origins whose string representation looks like "https://www.apple.com:0" and it would
+ not match the "https://www.apple.com" we expect internally.
+
+ * Shared/API/c/WKSecurityOriginRef.cpp:
+ (WKSecurityOriginCreate):
+
2019-10-29 Adrian Perez de Castro <[email protected]>
Unreviewed. Update OptionsWPE.cmake and NEWS for the 2.27.2 release
Modified: trunk/Source/WebKit/Shared/API/c/WKSecurityOriginRef.cpp (251708 => 251709)
--- trunk/Source/WebKit/Shared/API/c/WKSecurityOriginRef.cpp 2019-10-29 16:56:03 UTC (rev 251708)
+++ trunk/Source/WebKit/Shared/API/c/WKSecurityOriginRef.cpp 2019-10-29 16:57:09 UTC (rev 251709)
@@ -50,7 +50,10 @@
WKSecurityOriginRef WKSecurityOriginCreate(WKStringRef protocol, WKStringRef host, int port)
{
- auto securityOrigin = API::SecurityOrigin::create(WebKit::toImpl(protocol)->string(), WebKit::toImpl(host)->string(), port);
+ Optional<uint16_t> validPort;
+ if (port && port <= std::numeric_limits<uint16_t>::max())
+ validPort = port;
+ auto securityOrigin = API::SecurityOrigin::create(WebKit::toImpl(protocol)->string(), WebKit::toImpl(host)->string(), validPort);
return WebKit::toAPI(&securityOrigin.leakRef());
}
Modified: trunk/Tools/ChangeLog (251708 => 251709)
--- trunk/Tools/ChangeLog 2019-10-29 16:56:03 UTC (rev 251708)
+++ trunk/Tools/ChangeLog 2019-10-29 16:57:09 UTC (rev 251709)
@@ -1,3 +1,17 @@
+2019-10-29 Chris Dumez <[email protected]>
+
+ Notification permissions are not remembered for origins without port
+ https://bugs.webkit.org/show_bug.cgi?id=203537
+ <rdar://problem/55281080>
+
+ Reviewed by Brady Eidson.
+
+ Add API test coverage.
+
+ * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
+ * TestWebKitAPI/Tests/WebKit/WKSecurityOrigin.cpp: Added.
+ (TestWebKitAPI::TEST):
+
2019-10-29 Kate Cheney <[email protected]>
Removed duplicate email address.
Modified: trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj (251708 => 251709)
--- trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj 2019-10-29 16:56:03 UTC (rev 251708)
+++ trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj 2019-10-29 16:57:09 UTC (rev 251709)
@@ -226,6 +226,7 @@
448D7E471EA6C55500ECC756 /* EnvironmentUtilitiesTest.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 448D7E451EA6C55500ECC756 /* EnvironmentUtilitiesTest.cpp */; };
44AC8BC621D0245A00CAFB34 /* RetainPtr.cpp in Sources */ = {isa = PBXBuildFile; fileRef = BC029B161486AD6400817DA9 /* RetainPtr.cpp */; };
4612C2B9210A6ACE00B788A6 /* LoadFileThenReload.mm in Sources */ = {isa = PBXBuildFile; fileRef = 4612C2B8210A6ABF00B788A6 /* LoadFileThenReload.mm */; };
+ 4628C8E92367ABD100B073F0 /* WKSecurityOrigin.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4628C8E82367ABBC00B073F0 /* WKSecurityOrigin.cpp */; };
46397B951DC2C850009A78AE /* DOMNode.mm in Sources */ = {isa = PBXBuildFile; fileRef = 46397B941DC2C850009A78AE /* DOMNode.mm */; };
4647B1261EBA3B850041D7EF /* ProcessDidTerminate.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4647B1251EBA3B730041D7EF /* ProcessDidTerminate.cpp */; };
464C764D230DF85C00AFB020 /* BadServiceWorkerRegistrations-4.sqlite3 in Copy Resources */ = {isa = PBXBuildFile; fileRef = 464C764C230DF83200AFB020 /* BadServiceWorkerRegistrations-4.sqlite3 */; };
@@ -1458,7 +1459,6 @@
57663DEA234EA66D00E85E09 /* web-authentication-get-assertion-nfc.html in Copy Resources */,
577454D22359BB01008E1ED7 /* web-authentication-get-assertion-u2f-no-credentials.html in Copy Resources */,
57C624502346C21E00383FE7 /* web-authentication-get-assertion.html in Copy Resources */,
- 5798337E236019A4008E5547 /* web-authentication-make-credential-hid.html in Copy Resources */,
1C2B81861C89259D00A5529F /* webfont.html in Copy Resources */,
51714EB41CF8C78C004723C4 /* WebProcessKillIDBCleanup-1.html in Copy Resources */,
51714EB51CF8C78C004723C4 /* WebProcessKillIDBCleanup-2.html in Copy Resources */,
@@ -1739,6 +1739,7 @@
448D7E451EA6C55500ECC756 /* EnvironmentUtilitiesTest.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = EnvironmentUtilitiesTest.cpp; sourceTree = "<group>"; };
44A622C114A0E2B60048515B /* WTFStringUtilities.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WTFStringUtilities.h; sourceTree = "<group>"; };
4612C2B8210A6ABF00B788A6 /* LoadFileThenReload.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = LoadFileThenReload.mm; sourceTree = "<group>"; };
+ 4628C8E82367ABBC00B073F0 /* WKSecurityOrigin.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WKSecurityOrigin.cpp; sourceTree = "<group>"; };
46397B941DC2C850009A78AE /* DOMNode.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = DOMNode.mm; sourceTree = "<group>"; };
4647B1251EBA3B730041D7EF /* ProcessDidTerminate.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ProcessDidTerminate.cpp; sourceTree = "<group>"; };
464C764C230DF83200AFB020 /* BadServiceWorkerRegistrations-4.sqlite3 */ = {isa = PBXFileReference; lastKnownFileType = file; path = "BadServiceWorkerRegistrations-4.sqlite3"; sourceTree = "<group>"; };
@@ -3643,6 +3644,7 @@
524BBC9C19DF377A002F1AF1 /* WKPageIsPlayingAudio.cpp */,
BC7B619A1299FE9E00D174A4 /* WKPreferences.cpp */,
1CF0D3781BBF2F3D00B4EF54 /* WKRetainPtr.cpp */,
+ 4628C8E82367ABBC00B073F0 /* WKSecurityOrigin.cpp */,
BC90995D12567BC100083756 /* WKString.cpp */,
BC9099931256ACF100083756 /* WKStringJSString.cpp */,
);
@@ -4916,6 +4918,7 @@
7C83E0B51D0A649300FEBCF3 /* WKRetainPtr.cpp in Sources */,
5E4B1D2E1D404C6100053621 /* WKScrollViewDelegate.mm in Sources */,
F43E3BBF20DADA1E00A4E7ED /* WKScrollViewTests.mm in Sources */,
+ 4628C8E92367ABD100B073F0 /* WKSecurityOrigin.cpp in Sources */,
7CCE7F221A411AE600447C4C /* WKString.cpp in Sources */,
7CCE7F1E1A411AE600447C4C /* WKStringJSString.cpp in Sources */,
2D4CF8BD1D8360CC0001CE8D /* WKThumbnailView.mm in Sources */,
Added: trunk/Tools/TestWebKitAPI/Tests/WebKit/WKSecurityOrigin.cpp (0 => 251709)
--- trunk/Tools/TestWebKitAPI/Tests/WebKit/WKSecurityOrigin.cpp (rev 0)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKit/WKSecurityOrigin.cpp 2019-10-29 16:57:09 UTC (rev 251709)
@@ -0,0 +1,68 @@
+/*
+ * Copyright (C) 2019 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+
+#if WK_HAVE_C_SPI
+
+#include "PlatformUtilities.h"
+#include "Test.h"
+#include <WebKit/WKSecurityOriginRef.h>
+
+namespace TestWebKitAPI {
+
+TEST(WebKit, WKSecurityOriginCreateInvalidPortZero)
+{
+ auto protocol = adoptWK(WKStringCreateWithUTF8CString("https"));
+ auto host = adoptWK(WKStringCreateWithUTF8CString("www.apple.com"));
+ auto origin = adoptWK(WKSecurityOriginCreate(protocol.get(), host.get(), 0));
+
+ auto copiedProtocol = adoptWK(WKSecurityOriginCopyProtocol(origin.get()));
+ EXPECT_WK_STREQ("https", copiedProtocol.get());
+ auto copiedHost = adoptWK(WKSecurityOriginCopyHost(origin.get()));
+ EXPECT_WK_STREQ("www.apple.com", copiedHost.get());
+ auto string = adoptWK(WKSecurityOriginCopyToString(origin.get()));
+ EXPECT_WK_STREQ("https://www.apple.com", string.get());
+ EXPECT_EQ(0U, WKSecurityOriginGetPort(origin.get()));
+}
+
+TEST(WebKit, WKSecurityOriginCreateInvalidPortTooLarge)
+{
+ auto protocol = adoptWK(WKStringCreateWithUTF8CString("https"));
+ auto host = adoptWK(WKStringCreateWithUTF8CString("www.apple.com"));
+ auto origin = adoptWK(WKSecurityOriginCreate(protocol.get(), host.get(), 99999));
+
+ auto copiedProtocol = adoptWK(WKSecurityOriginCopyProtocol(origin.get()));
+ EXPECT_WK_STREQ("https", copiedProtocol.get());
+ auto copiedHost = adoptWK(WKSecurityOriginCopyHost(origin.get()));
+ EXPECT_WK_STREQ("www.apple.com", copiedHost.get());
+ auto string = adoptWK(WKSecurityOriginCopyToString(origin.get()));
+ EXPECT_WK_STREQ("https://www.apple.com", string.get());
+ EXPECT_EQ(0U, WKSecurityOriginGetPort(origin.get()));
+}
+
+} // namespace TestWebKitAPI
+
+#endif // WK_HAVE_C_SPI