- Revision
- 244853
- Author
- [email protected]
- Date
- 2019-05-01 15:08:00 -0700 (Wed, 01 May 2019)
Log Message
Move Document::domainIsRegisterable to SecurityOrigin::isMatchingRegistrableDomainSuffix
https://bugs.webkit.org/show_bug.cgi?id=181950
<rdar://problem/43357371>
Reviewed by Brent Fulgham.
Source/WebCore:
This patch moves Document::domainIsRegisterable to SecurityOrigin::isMatchingRegistrableDomainSuffix
to be more aligned with the HTML standard:
https://html.spec.whatwg.org/multipage/origin.html#is-a-registrable-domain-suffix-of-or-is-equal-to.
Besides that, it also removes redundant codes within the original method that is also done in
OriginAccessEntry::matchesOrigin.
Covered by new API tests.
* dom/Document.cpp:
(WebCore::Document::setDomain):
(WebCore::Document::domainIsRegisterable const): Deleted.
* dom/Document.h:
* page/SecurityOrigin.cpp:
(WebCore::SecurityOrigin::isMatchingRegistrableDomainSuffix const):
* page/SecurityOrigin.h:
Tools:
* TestWebKitAPI/Tests/WebCore/SecurityOrigin.cpp:
(TestWebKitAPI::TEST_F):
Modified Paths
Diff
Modified: trunk/Source/WebCore/ChangeLog (244852 => 244853)
--- trunk/Source/WebCore/ChangeLog 2019-05-01 21:40:25 UTC (rev 244852)
+++ trunk/Source/WebCore/ChangeLog 2019-05-01 22:08:00 UTC (rev 244853)
@@ -1,3 +1,27 @@
+2019-05-01 Jiewen Tan <[email protected]>
+
+ Move Document::domainIsRegisterable to SecurityOrigin::isMatchingRegistrableDomainSuffix
+ https://bugs.webkit.org/show_bug.cgi?id=181950
+ <rdar://problem/43357371>
+
+ Reviewed by Brent Fulgham.
+
+ This patch moves Document::domainIsRegisterable to SecurityOrigin::isMatchingRegistrableDomainSuffix
+ to be more aligned with the HTML standard:
+ https://html.spec.whatwg.org/multipage/origin.html#is-a-registrable-domain-suffix-of-or-is-equal-to.
+ Besides that, it also removes redundant codes within the original method that is also done in
+ OriginAccessEntry::matchesOrigin.
+
+ Covered by new API tests.
+
+ * dom/Document.cpp:
+ (WebCore::Document::setDomain):
+ (WebCore::Document::domainIsRegisterable const): Deleted.
+ * dom/Document.h:
+ * page/SecurityOrigin.cpp:
+ (WebCore::SecurityOrigin::isMatchingRegistrableDomainSuffix const):
+ * page/SecurityOrigin.h:
+
2019-05-01 Ryosuke Niwa <[email protected]>
[iOS] Element::focus and Element::scrollIntoView do not clamp scroll positions
Modified: trunk/Source/WebCore/dom/Document.cpp (244852 => 244853)
--- trunk/Source/WebCore/dom/Document.cpp 2019-05-01 21:40:25 UTC (rev 244852)
+++ trunk/Source/WebCore/dom/Document.cpp 2019-05-01 22:08:00 UTC (rev 244853)
@@ -135,7 +135,6 @@
#include "NodeIterator.h"
#include "NodeRareData.h"
#include "NodeWithIndex.h"
-#include "OriginAccessEntry.h"
#include "OverflowEvent.h"
#include "PageConsoleClient.h"
#include "PageGroup.h"
@@ -4857,49 +4856,6 @@
return securityOrigin().domain();
}
-bool Document::domainIsRegisterable(const String& newDomain) const
-{
- if (newDomain.isEmpty())
- return false;
-
- const String& effectiveDomain = domain();
-
- // If the new domain is the same as the old domain, return true so that
- // we still call securityOrigin().setDomainForDOM. This will change the
- // security check behavior. For example, if a page loaded on port 8000
- // assigns its current domain using document.domain, the page will
- // allow other pages loaded on different ports in the same domain that
- // have also assigned to access this page.
- if (equalIgnoringASCIICase(effectiveDomain, newDomain))
- return true;
-
- // e.g. newDomain = webkit.org (10) and domain() = www.webkit.org (14)
- unsigned oldLength = effectiveDomain.length();
- unsigned newLength = newDomain.length();
- if (newLength >= oldLength)
- return false;
-
- auto ipAddressSetting = settings().treatIPAddressAsDomain() ? OriginAccessEntry::TreatIPAddressAsDomain : OriginAccessEntry::TreatIPAddressAsIPAddress;
- OriginAccessEntry accessEntry { securityOrigin().protocol(), newDomain, OriginAccessEntry::AllowSubdomains, ipAddressSetting };
- if (!accessEntry.matchesOrigin(securityOrigin()))
- return false;
-
- if (effectiveDomain[oldLength - newLength - 1] != '.')
- return false;
- if (StringView { effectiveDomain }.substring(oldLength - newLength) != newDomain)
- return false;
-
- auto potentialPublicSuffix = newDomain;
- if (potentialPublicSuffix.startsWith('.'))
- potentialPublicSuffix.remove(0, 1);
-
-#if ENABLE(PUBLIC_SUFFIX_LIST)
- return !isPublicSuffix(potentialPublicSuffix);
-#else
- return true;
-#endif
-}
-
ExceptionOr<void> Document::setDomain(const String& newDomain)
{
if (!frame())
@@ -4917,7 +4873,7 @@
if (effectiveDomain.isEmpty())
return Exception { SecurityError, "The document has a null effectiveDomain." };
- if (!domainIsRegisterable(newDomain))
+ if (!securityOrigin().isMatchingRegistrableDomainSuffix(newDomain, settings().treatIPAddressAsDomain()))
return Exception { SecurityError, "Attempted to use a non-registrable domain." };
securityOrigin().setDomainFromDOM(newDomain);
Modified: trunk/Source/WebCore/dom/Document.h (244852 => 244853)
--- trunk/Source/WebCore/dom/Document.h 2019-05-01 21:40:25 UTC (rev 244852)
+++ trunk/Source/WebCore/dom/Document.h 2019-05-01 22:08:00 UTC (rev 244853)
@@ -1644,8 +1644,6 @@
void platformSuspendOrStopActiveDOMObjects();
- bool domainIsRegisterable(const String&) const;
-
void enableTemporaryTimeUserGesture();
bool isBodyPotentiallyScrollable(HTMLBodyElement&);
Modified: trunk/Source/WebCore/page/SecurityOrigin.cpp (244852 => 244853)
--- trunk/Source/WebCore/page/SecurityOrigin.cpp 2019-05-01 21:40:25 UTC (rev 244852)
+++ trunk/Source/WebCore/page/SecurityOrigin.cpp 2019-05-01 22:08:00 UTC (rev 244853)
@@ -30,6 +30,7 @@
#include "SecurityOrigin.h"
#include "BlobURL.h"
+#include "OriginAccessEntry.h"
#include "SchemeRegistry.h"
#include "SecurityPolicy.h"
#include "TextEncoding.h"
@@ -432,6 +433,27 @@
return isSameSchemeHostPort(other);
}
+bool SecurityOrigin::isMatchingRegistrableDomainSuffix(const String& domainSuffix, bool treatIPAddressAsDomain) const
+{
+ if (domainSuffix.isEmpty())
+ return false;
+
+ auto ipAddressSetting = treatIPAddressAsDomain ? OriginAccessEntry::TreatIPAddressAsDomain : OriginAccessEntry::TreatIPAddressAsIPAddress;
+ OriginAccessEntry accessEntry { protocol(), domainSuffix, OriginAccessEntry::AllowSubdomains, ipAddressSetting };
+ if (!accessEntry.matchesOrigin(*this))
+ return false;
+
+ // Always return true if it is an exact match.
+ if (domainSuffix.length() == host().length())
+ return true;
+
+#if ENABLE(PUBLIC_SUFFIX_LIST)
+ return !isPublicSuffix(domainSuffix);
+#else
+ return true;
+#endif
+}
+
void SecurityOrigin::grantLoadLocalResources()
{
// Granting privileges to some, but not all, documents in a SecurityOrigin
Modified: trunk/Source/WebCore/page/SecurityOrigin.h (244852 => 244853)
--- trunk/Source/WebCore/page/SecurityOrigin.h 2019-05-01 21:40:25 UTC (rev 244852)
+++ trunk/Source/WebCore/page/SecurityOrigin.h 2019-05-01 22:08:00 UTC (rev 244853)
@@ -204,6 +204,10 @@
// https://html.spec.whatwg.org/multipage/browsers.html#same-origin
WEBCORE_EXPORT bool isSameOriginAs(const SecurityOrigin&) const;
+ // This method implements the "is a registrable domain suffix of or is equal to" algorithm from the HTML Standard:
+ // https://html.spec.whatwg.org/multipage/origin.html#is-a-registrable-domain-suffix-of-or-is-equal-to
+ WEBCORE_EXPORT bool isMatchingRegistrableDomainSuffix(const String&, bool treatIPAddressAsDomain = false) const;
+
bool isPotentiallyTrustworthy() const { return m_isPotentiallyTrustworthy; }
void setIsPotentiallyTrustworthy(bool value) { m_isPotentiallyTrustworthy = value; }
Modified: trunk/Tools/ChangeLog (244852 => 244853)
--- trunk/Tools/ChangeLog 2019-05-01 21:40:25 UTC (rev 244852)
+++ trunk/Tools/ChangeLog 2019-05-01 22:08:00 UTC (rev 244853)
@@ -1,3 +1,14 @@
+2019-05-01 Jiewen Tan <[email protected]>
+
+ Move Document::domainIsRegisterable to SecurityOrigin::isMatchingRegistrableDomainSuffix
+ https://bugs.webkit.org/show_bug.cgi?id=181950
+ <rdar://problem/43357371>
+
+ Reviewed by Brent Fulgham.
+
+ * TestWebKitAPI/Tests/WebCore/SecurityOrigin.cpp:
+ (TestWebKitAPI::TEST_F):
+
2019-05-01 Aakash Jain <[email protected]>
Remove webkitpy and bindings EWS queues from dashboard
Modified: trunk/Tools/TestWebKitAPI/Tests/WebCore/SecurityOrigin.cpp (244852 => 244853)
--- trunk/Tools/TestWebKitAPI/Tests/WebCore/SecurityOrigin.cpp 2019-05-01 21:40:25 UTC (rev 244852)
+++ trunk/Tools/TestWebKitAPI/Tests/WebCore/SecurityOrigin.cpp 2019-05-01 22:08:00 UTC (rev 244853)
@@ -183,4 +183,44 @@
EXPECT_FALSE(SecurityOrigin::createFromString("dummy:a")->isPotentiallyTrustworthy());
}
+TEST_F(SecurityOriginTest, IsRegistrableDomainSuffix)
+{
+ auto exampleOrigin = SecurityOrigin::create(URL(URL(), "http://www.example.com"));
+ EXPECT_TRUE(exampleOrigin->isMatchingRegistrableDomainSuffix("example.com"));
+ EXPECT_TRUE(exampleOrigin->isMatchingRegistrableDomainSuffix("www.example.com"));
+#if !ENABLE(PUBLIC_SUFFIX_LIST)
+ EXPECT_TRUE(exampleOrigin->isMatchingRegistrableDomainSuffix("com"));
+#endif
+ EXPECT_FALSE(exampleOrigin->isMatchingRegistrableDomainSuffix(""));
+ EXPECT_FALSE(exampleOrigin->isMatchingRegistrableDomainSuffix("."));
+ EXPECT_FALSE(exampleOrigin->isMatchingRegistrableDomainSuffix(".example.com"));
+ EXPECT_FALSE(exampleOrigin->isMatchingRegistrableDomainSuffix(".www.example.com"));
+ EXPECT_FALSE(exampleOrigin->isMatchingRegistrableDomainSuffix("example.com."));
+#if ENABLE(PUBLIC_SUFFIX_LIST)
+ EXPECT_FALSE(exampleOrigin->isMatchingRegistrableDomainSuffix("com"));
+#endif
+
+ auto exampleDotOrigin = SecurityOrigin::create(URL(URL(), "http://www.example.com."));
+ EXPECT_TRUE(exampleDotOrigin->isMatchingRegistrableDomainSuffix("example.com."));
+ EXPECT_TRUE(exampleDotOrigin->isMatchingRegistrableDomainSuffix("www.example.com."));
+#if !ENABLE(PUBLIC_SUFFIX_LIST)
+ EXPECT_TRUE(exampleOrigin->isMatchingRegistrableDomainSuffix("com."));
+#endif
+ EXPECT_FALSE(exampleDotOrigin->isMatchingRegistrableDomainSuffix(""));
+ EXPECT_FALSE(exampleDotOrigin->isMatchingRegistrableDomainSuffix("."));
+ EXPECT_FALSE(exampleDotOrigin->isMatchingRegistrableDomainSuffix(".example.com."));
+ EXPECT_FALSE(exampleDotOrigin->isMatchingRegistrableDomainSuffix(".www.example.com."));
+ EXPECT_FALSE(exampleDotOrigin->isMatchingRegistrableDomainSuffix("example.com"));
+#if ENABLE(PUBLIC_SUFFIX_LIST)
+ EXPECT_FALSE(exampleDotOrigin->isMatchingRegistrableDomainSuffix("com"));
+#endif
+
+ auto ipOrigin = SecurityOrigin::create(URL(URL(), "http://127.0.0.1"));
+ EXPECT_TRUE(ipOrigin->isMatchingRegistrableDomainSuffix("127.0.0.1", true));
+ EXPECT_FALSE(ipOrigin->isMatchingRegistrableDomainSuffix("127.0.0.2", true));
+
+ auto comOrigin = SecurityOrigin::create(URL(URL(), "http://com"));
+ EXPECT_TRUE(comOrigin->isMatchingRegistrableDomainSuffix("com"));
+}
+
} // namespace TestWebKitAPI