Title: [210218] trunk
Revision
210218
Author
mcatanz...@igalia.com
Date
2016-12-31 16:48:19 -0800 (Sat, 31 Dec 2016)

Log Message

SecurityOrigin::create triplet constructor does not canonicalize port
https://bugs.webkit.org/show_bug.cgi?id=166624

Reviewed by Daniel Bates.

Source/WebCore:

It is currently possible to create two different unequal SecurityOrigin objects that
represent the same security origin. The SecurityOrigin create functions that take URL and
String parameters convert the port to nullopt if it is the default port for the protocol,
but the separate protocol/host/port constructor doesn't. Change it to parallel the other
constructors.

* page/SecurityOrigin.cpp:
(WebCore::SecurityOrigin::create):
* page/SecurityOrigin.h: Export isSameOriginAs for use by tests.

Tools:

* TestWebKitAPI/PlatformGTK.cmake:
* TestWebKitAPI/PlatformWin.cmake:
* TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
* TestWebKitAPI/Tests/WebCore/SecurityOrigin.cpp: Added.
(TestWebKitAPI::SecurityOriginTest::SetUp):
(TestWebKitAPI::TEST_F):

Modified Paths

Added Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (210217 => 210218)


--- trunk/Source/WebCore/ChangeLog	2016-12-31 09:57:11 UTC (rev 210217)
+++ trunk/Source/WebCore/ChangeLog	2017-01-01 00:48:19 UTC (rev 210218)
@@ -1,3 +1,20 @@
+2016-12-31  Michael Catanzaro  <mcatanz...@igalia.com>
+
+        SecurityOrigin::create triplet constructor does not canonicalize port
+        https://bugs.webkit.org/show_bug.cgi?id=166624
+
+        Reviewed by Daniel Bates.
+
+        It is currently possible to create two different unequal SecurityOrigin objects that
+        represent the same security origin. The SecurityOrigin create functions that take URL and
+        String parameters convert the port to nullopt if it is the default port for the protocol,
+        but the separate protocol/host/port constructor doesn't. Change it to parallel the other
+        constructors.
+
+        * page/SecurityOrigin.cpp:
+        (WebCore::SecurityOrigin::create):
+        * page/SecurityOrigin.h: Export isSameOriginAs for use by tests.
+
 2016-12-25  Darin Adler  <da...@apple.com>
 
         Remove setDOMException and a few custom bindings

Modified: trunk/Source/WebCore/page/SecurityOrigin.cpp (210217 => 210218)


--- trunk/Source/WebCore/page/SecurityOrigin.cpp	2016-12-31 09:57:11 UTC (rev 210217)
+++ trunk/Source/WebCore/page/SecurityOrigin.cpp	2017-01-01 00:48:19 UTC (rev 210218)
@@ -490,7 +490,8 @@
 {
     String decodedHost = decodeURLEscapeSequences(host);
     auto origin = create(URL(URL(), protocol + "://" + host + "/"));
-    origin->m_port = port;
+    if (port && !isDefaultPortForProtocol(*port, protocol))
+        origin->m_port = port;
     return origin;
 }
 

Modified: trunk/Source/WebCore/page/SecurityOrigin.h (210217 => 210218)


--- trunk/Source/WebCore/page/SecurityOrigin.h	2016-12-31 09:57:11 UTC (rev 210217)
+++ trunk/Source/WebCore/page/SecurityOrigin.h	2017-01-01 00:48:19 UTC (rev 210218)
@@ -198,7 +198,7 @@
 
     // This method implements the "same origin" algorithm from the HTML Standard:
     // https://html.spec.whatwg.org/multipage/browsers.html#same-origin
-    bool isSameOriginAs(const SecurityOrigin*) const;
+    WEBCORE_EXPORT bool isSameOriginAs(const SecurityOrigin*) const;
 
     static URL urlWithUniqueSecurityOrigin();
 

Modified: trunk/Tools/ChangeLog (210217 => 210218)


--- trunk/Tools/ChangeLog	2016-12-31 09:57:11 UTC (rev 210217)
+++ trunk/Tools/ChangeLog	2017-01-01 00:48:19 UTC (rev 210218)
@@ -1,3 +1,17 @@
+2016-12-31  Michael Catanzaro  <mcatanz...@igalia.com>
+
+        SecurityOrigin::create triplet constructor does not canonicalize port
+        https://bugs.webkit.org/show_bug.cgi?id=166624
+
+        Reviewed by Daniel Bates.
+
+        * TestWebKitAPI/PlatformGTK.cmake:
+        * TestWebKitAPI/PlatformWin.cmake:
+        * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
+        * TestWebKitAPI/Tests/WebCore/SecurityOrigin.cpp: Added.
+        (TestWebKitAPI::SecurityOriginTest::SetUp):
+        (TestWebKitAPI::TEST_F):
+
 2016-12-30  Michael Catanzaro  <mcatanz...@igalia.com>
 
         [GTK] Improve user agent construction

Modified: trunk/Tools/TestWebKitAPI/PlatformGTK.cmake (210217 => 210218)


--- trunk/Tools/TestWebKitAPI/PlatformGTK.cmake	2016-12-31 09:57:11 UTC (rev 210217)
+++ trunk/Tools/TestWebKitAPI/PlatformGTK.cmake	2017-01-01 00:48:19 UTC (rev 210218)
@@ -133,6 +133,7 @@
     ${TESTWEBKITAPI_DIR}/Tests/WebCore/HTMLParserIdioms.cpp
     ${TESTWEBKITAPI_DIR}/Tests/WebCore/LayoutUnit.cpp
     ${TESTWEBKITAPI_DIR}/Tests/WebCore/PublicSuffix.cpp
+    ${TESTWEBKITAPI_DIR}/Tests/WebCore/SecurityOrigin.cpp
     ${TESTWEBKITAPI_DIR}/Tests/WebCore/SharedBuffer.cpp
     ${TESTWEBKITAPI_DIR}/Tests/WebCore/URL.cpp
     ${TESTWEBKITAPI_DIR}/Tests/WebCore/URLParser.cpp

Modified: trunk/Tools/TestWebKitAPI/PlatformWin.cmake (210217 => 210218)


--- trunk/Tools/TestWebKitAPI/PlatformWin.cmake	2016-12-31 09:57:11 UTC (rev 210217)
+++ trunk/Tools/TestWebKitAPI/PlatformWin.cmake	2017-01-01 00:48:19 UTC (rev 210218)
@@ -56,6 +56,7 @@
     ${TESTWEBKITAPI_DIR}/Tests/WebCore/IntSize.cpp
     ${TESTWEBKITAPI_DIR}/Tests/WebCore/LayoutUnit.cpp
     ${TESTWEBKITAPI_DIR}/Tests/WebCore/ParsedContentRange.cpp
+    ${TESTWEBKITAPI_DIR}/Tests/WebCore/SecurityOrigin.cpp
     ${TESTWEBKITAPI_DIR}/Tests/WebCore/SharedBuffer.cpp
     ${TESTWEBKITAPI_DIR}/Tests/WebCore/TimeRanges.cpp
     ${TESTWEBKITAPI_DIR}/Tests/WebCore/TransformationMatrix.cpp

Modified: trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj (210217 => 210218)


--- trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj	2016-12-31 09:57:11 UTC (rev 210217)
+++ trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj	2017-01-01 00:48:19 UTC (rev 210218)
@@ -514,6 +514,7 @@
 		CDC8E4961BC6F10800594FEC /* video-without-audio.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = CDC8E48B1BC5C96200594FEC /* video-without-audio.html */; };
 		CDC8E4971BC6F10800594FEC /* video-without-audio.mp4 in Copy Resources */ = {isa = PBXBuildFile; fileRef = CDC8E48C1BC5C96200594FEC /* video-without-audio.mp4 */; };
 		CDE195B51CFE0B880053D256 /* FullscreenTopContentInset.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = CDE195B21CFE0ADE0053D256 /* FullscreenTopContentInset.html */; };
+		CE06DF9B1E1851F200E570C9 /* SecurityOrigin.cpp in Sources */ = {isa = PBXBuildFile; fileRef = CE06DF9A1E1851F200E570C9 /* SecurityOrigin.cpp */; };
 		CE14F1A4181873B0001C2705 /* WillPerformClientRedirectToURLCrash.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = CE14F1A2181873B0001C2705 /* WillPerformClientRedirectToURLCrash.html */; };
 		CE3524F81B1431F60028A7C5 /* TextFieldDidBeginAndEndEditing_Bundle.cpp in Sources */ = {isa = PBXBuildFile; fileRef = CE3524F21B142B8D0028A7C5 /* TextFieldDidBeginAndEndEditing_Bundle.cpp */; };
 		CE3524F91B1441C40028A7C5 /* TextFieldDidBeginAndEndEditing.cpp in Sources */ = {isa = PBXBuildFile; fileRef = CE3524F11B142B8D0028A7C5 /* TextFieldDidBeginAndEndEditing.cpp */; };
@@ -1274,6 +1275,7 @@
 		CDC8E48C1BC5C96200594FEC /* video-without-audio.mp4 */ = {isa = PBXFileReference; lastKnownFileType = file; path = "video-without-audio.mp4"; sourceTree = "<group>"; };
 		CDE195B21CFE0ADE0053D256 /* FullscreenTopContentInset.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = FullscreenTopContentInset.html; sourceTree = "<group>"; };
 		CDE195B31CFE0ADE0053D256 /* FullscreenTopContentInset.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = FullscreenTopContentInset.mm; sourceTree = "<group>"; };
+		CE06DF9A1E1851F200E570C9 /* SecurityOrigin.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = SecurityOrigin.cpp; sourceTree = "<group>"; };
 		CE14F1A2181873B0001C2705 /* WillPerformClientRedirectToURLCrash.html */ = {isa = PBXFileReference; lastKnownFileType = text.html; path = WillPerformClientRedirectToURLCrash.html; sourceTree = "<group>"; };
 		CE32C7C718184C4900CD8C28 /* WillPerformClientRedirectToURLCrash.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WillPerformClientRedirectToURLCrash.mm; sourceTree = "<group>"; };
 		CE3524F11B142B8D0028A7C5 /* TextFieldDidBeginAndEndEditing.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = TextFieldDidBeginAndEndEditing.cpp; sourceTree = "<group>"; };
@@ -1555,6 +1557,7 @@
 				83B88A331C80056D00BB2418 /* HTMLParserIdioms.cpp */,
 				14464012167A8305000BD218 /* LayoutUnit.cpp */,
 				CD225C071C45A69200140761 /* ParsedContentRange.cpp */,
+				CE06DF9A1E1851F200E570C9 /* SecurityOrigin.cpp */,
 				41973B5C1AF22875006C7B36 /* SharedBuffer.cpp */,
 				CDC2C7141797089D00E627FB /* TimeRanges.cpp */,
 				7AD3FE8D1D75FB8D00B169A4 /* TransformationMatrix.cpp */,
@@ -2611,6 +2614,7 @@
 				835CF9671D25FCD6001A65D4 /* RestoreSessionStateWithoutNavigation.cpp in Sources */,
 				7A909A7F1D877480007E10F8 /* FloatRect.cpp in Sources */,
 				7CCE7F121A411AE600447C4C /* ScrollPinningBehaviors.cpp in Sources */,
+				CE06DF9B1E1851F200E570C9 /* SecurityOrigin.cpp in Sources */,
 				7CCE7ECB1A411A7E00447C4C /* SetAndUpdateCacheModel.mm in Sources */,
 				7CCE7ECC1A411A7E00447C4C /* SetDocumentURI.mm in Sources */,
 				7C83E0521D0A641800FEBCF3 /* SharedBuffer.cpp in Sources */,

Added: trunk/Tools/TestWebKitAPI/Tests/WebCore/SecurityOrigin.cpp (0 => 210218)


--- trunk/Tools/TestWebKitAPI/Tests/WebCore/SecurityOrigin.cpp	                        (rev 0)
+++ trunk/Tools/TestWebKitAPI/Tests/WebCore/SecurityOrigin.cpp	2017-01-01 00:48:19 UTC (rev 210218)
@@ -0,0 +1,87 @@
+/*
+ * Copyright (C) 2016 Igalia S.L.
+ *
+ * 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"
+#include "WTFStringUtilities.h"
+#include <WebCore/SecurityOrigin.h>
+#include <WebCore/URL.h>
+#include <wtf/MainThread.h>
+
+using namespace WebCore;
+
+namespace TestWebKitAPI {
+
+class SecurityOriginTest : public testing::Test {
+public:
+    void SetUp() final {
+        WTF::initializeMainThread();
+    }
+};
+
+TEST_F(SecurityOriginTest, SecurityOriginConstructors)
+{
+    Ref<SecurityOrigin> o1 = SecurityOrigin::create("http", "example.com", std::optional<uint16_t>(80));
+    Ref<SecurityOrigin> o2 = SecurityOrigin::create("http", "example.com", std::optional<uint16_t>());
+    Ref<SecurityOrigin> o3 = SecurityOrigin::createFromString("http://example.com");
+    Ref<SecurityOrigin> o4 = SecurityOrigin::createFromString("http://example.com:80");
+    Ref<SecurityOrigin> o5 = SecurityOrigin::create(URL(URL(), "http://example.com"));
+    Ref<SecurityOrigin> o6 = SecurityOrigin::create(URL(URL(), "http://example.com:80"));
+
+    EXPECT_EQ(String("http"), o1->protocol());
+    EXPECT_EQ(String("http"), o2->protocol());
+    EXPECT_EQ(String("http"), o3->protocol());
+    EXPECT_EQ(String("http"), o4->protocol());
+    EXPECT_EQ(String("http"), o5->protocol());
+    EXPECT_EQ(String("http"), o6->protocol());
+
+    EXPECT_EQ(String("example.com"), o1->host());
+    EXPECT_EQ(String("example.com"), o2->host());
+    EXPECT_EQ(String("example.com"), o3->host());
+    EXPECT_EQ(String("example.com"), o4->host());
+    EXPECT_EQ(String("example.com"), o5->host());
+    EXPECT_EQ(String("example.com"), o6->host());
+
+    EXPECT_FALSE(o1->port());
+    EXPECT_FALSE(o2->port());
+    EXPECT_FALSE(o3->port());
+    EXPECT_FALSE(o4->port());
+    EXPECT_FALSE(o5->port());
+    EXPECT_FALSE(o6->port());
+
+    EXPECT_EQ("http://example.com", o1->toString());
+    EXPECT_EQ("http://example.com", o2->toString());
+    EXPECT_EQ("http://example.com", o3->toString());
+    EXPECT_EQ("http://example.com", o4->toString());
+    EXPECT_EQ("http://example.com", o5->toString());
+    EXPECT_EQ("http://example.com", o6->toString());
+
+    EXPECT_TRUE(o1->isSameOriginAs(o2.ptr()));
+    EXPECT_TRUE(o1->isSameOriginAs(o3.ptr()));
+    EXPECT_TRUE(o1->isSameOriginAs(o4.ptr()));
+    EXPECT_TRUE(o1->isSameOriginAs(o5.ptr()));
+    EXPECT_TRUE(o1->isSameOriginAs(o6.ptr()));
+}
+
+} // namespace TestWebKitAPI
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to