Diff
Modified: trunk/LayoutTests/imported/w3c/ChangeLog (224060 => 224061)
--- trunk/LayoutTests/imported/w3c/ChangeLog 2017-10-26 23:07:01 UTC (rev 224060)
+++ trunk/LayoutTests/imported/w3c/ChangeLog 2017-10-26 23:25:41 UTC (rev 224061)
@@ -1,3 +1,16 @@
+2017-10-26 Andy Estes <[email protected]>
+
+ [Payment Request] Restrict API use to secure, same-origin frames
+ https://bugs.webkit.org/show_bug.cgi?id=178887
+
+ Reviewed by Tim Horton.
+
+ The allowpaymentrequest <iframe> attribute is not yet implemented, so the regression in basic.https.html is expected.
+
+ * web-platform-tests/payment-request/allowpaymentrequest/active-document-cross-origin.https.sub-expected.txt:
+ * web-platform-tests/payment-request/allowpaymentrequest/active-document-same-origin.https-expected.txt:
+ * web-platform-tests/payment-request/allowpaymentrequest/basic.https-expected.txt:
+
2017-10-24 Andy Estes <[email protected]>
[Payment Request] Implement the "PaymentRequest updated" algorithm
Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/payment-request/allowpaymentrequest/active-document-cross-origin.https.sub-expected.txt (224060 => 224061)
--- trunk/LayoutTests/imported/w3c/web-platform-tests/payment-request/allowpaymentrequest/active-document-cross-origin.https.sub-expected.txt 2017-10-26 23:07:01 UTC (rev 224060)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/payment-request/allowpaymentrequest/active-document-cross-origin.https.sub-expected.txt 2017-10-26 23:25:41 UTC (rev 224061)
@@ -1,7 +1,5 @@
Blocked access to external URL https://www1.localhost:9443/common/blank.html
-FAIL PaymentRequest <iframe allowpaymentrequest> in non-active document (cross-origin) assert_throws: function "() => {
- new grabbedPaymentRequest(...paymentArgs);
- }" did not throw
+PASS PaymentRequest <iframe allowpaymentrequest> in non-active document (cross-origin)
Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/payment-request/allowpaymentrequest/active-document-same-origin.https-expected.txt (224060 => 224061)
--- trunk/LayoutTests/imported/w3c/web-platform-tests/payment-request/allowpaymentrequest/active-document-same-origin.https-expected.txt 2017-10-26 23:07:01 UTC (rev 224060)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/payment-request/allowpaymentrequest/active-document-same-origin.https-expected.txt 2017-10-26 23:25:41 UTC (rev 224061)
@@ -1,6 +1,4 @@
-FAIL PaymentRequest <iframe allowpaymentrequest> in non-active document (same-origin) assert_throws: function "() => {
- new grabbedPaymentRequest(...paymentArgs);
- }" did not throw
+PASS PaymentRequest <iframe allowpaymentrequest> in non-active document (same-origin)
Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/payment-request/allowpaymentrequest/basic.https-expected.txt (224060 => 224061)
--- trunk/LayoutTests/imported/w3c/web-platform-tests/payment-request/allowpaymentrequest/basic.https-expected.txt 2017-10-26 23:07:01 UTC (rev 224060)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/payment-request/allowpaymentrequest/basic.https-expected.txt 2017-10-26 23:25:41 UTC (rev 224061)
@@ -1,4 +1,4 @@
-PASS PaymentRequest <iframe allowpaymentrequest> basic
+FAIL PaymentRequest <iframe allowpaymentrequest> basic Trying to start an Apple Pay session from an insecure document.
Modified: trunk/Source/WebCore/ChangeLog (224060 => 224061)
--- trunk/Source/WebCore/ChangeLog 2017-10-26 23:07:01 UTC (rev 224060)
+++ trunk/Source/WebCore/ChangeLog 2017-10-26 23:25:41 UTC (rev 224061)
@@ -1,3 +1,36 @@
+2017-10-26 Andy Estes <[email protected]>
+
+ [Payment Request] Restrict API use to secure, same-origin frames
+ https://bugs.webkit.org/show_bug.cgi?id=178887
+
+ Reviewed by Tim Horton.
+
+ Reuse the access checks from Apple Pay to restrict PaymentRequest API usage to secure frames
+ in the same origin as the main frame.
+
+ Progresses active-document-cross-origin.https.sub.html and
+ active-document-same-origin.https.html from web-platform-tests. Regresses basic.https.html
+ since the allowpaymentrequest <iframe> attribute is not yet implemented.
+
+ * Modules/applepay/ApplePaySession.cpp:
+ (WebCore::ApplePaySession::create):
+ (WebCore::ApplePaySession::supportsVersion):
+ (WebCore::ApplePaySession::canMakePayments):
+ (WebCore::ApplePaySession::canMakePaymentsWithActiveCard):
+ (WebCore::ApplePaySession::openPaymentSetup):
+ (WebCore::isSecure): Deleted.
+ (WebCore::canCallApplePaySessionAPIs): Deleted.
+ * Modules/applepay/PaymentSession.cpp: Added.
+ (WebCore::isSecure):
+ (WebCore::PaymentSession::canCreateSession):
+ * Modules/applepay/PaymentSession.h:
+ * Modules/paymentrequest/PaymentHandler.cpp:
+ (WebCore::PaymentHandler::canCreateSession):
+ * Modules/paymentrequest/PaymentHandler.h:
+ * Modules/paymentrequest/PaymentRequest.cpp:
+ (WebCore::PaymentRequest::create):
+ * WebCore.xcodeproj/project.pbxproj:
+
2017-10-26 Youenn Fablet <[email protected]>
Add service worker handle fetch support for all subresource requests
Modified: trunk/Source/WebCore/Modules/applepay/ApplePaySession.cpp (224060 => 224061)
--- trunk/Source/WebCore/Modules/applepay/ApplePaySession.cpp 2017-10-26 23:07:01 UTC (rev 224060)
+++ trunk/Source/WebCore/Modules/applepay/ApplePaySession.cpp 2017-10-26 23:25:41 UTC (rev 224061)
@@ -398,44 +398,9 @@
return WTFMove(convertedUpdate);
}
-static bool isSecure(DocumentLoader& documentLoader)
-{
- if (!documentLoader.response().url().protocolIs("https"))
- return false;
-
- if (!documentLoader.response().certificateInfo() || documentLoader.response().certificateInfo()->containsNonRootSHA1SignedCertificate())
- return false;
-
- return true;
-}
-
-static ExceptionOr<void> canCallApplePaySessionAPIs(Document& document)
-{
- if (!isSecure(*document.loader()))
- return Exception { InvalidAccessError, "Trying to call an ApplePaySession API from an insecure document." };
-
- auto& topDocument = document.topDocument();
- if (&document != &topDocument) {
- auto& topOrigin = topDocument.topOrigin();
-
- if (!document.securityOrigin().isSameSchemeHostPort(topOrigin))
- return Exception { InvalidAccessError, "Trying to call an ApplePaySession API from a document with an different security origin than its top-level frame." };
-
- for (auto* ancestorDocument = document.parentDocument(); ancestorDocument != &topDocument; ancestorDocument = ancestorDocument->parentDocument()) {
- if (!isSecure(*ancestorDocument->loader()))
- return Exception { InvalidAccessError, "Trying to call an ApplePaySession API from a document with an insecure parent frame." };
-
- if (!ancestorDocument->securityOrigin().isSameSchemeHostPort(topOrigin))
- return Exception { InvalidAccessError, "Trying to call an ApplePaySession API from a document with an different security origin than its top-level frame." };
- }
- }
-
- return { };
-}
-
ExceptionOr<Ref<ApplePaySession>> ApplePaySession::create(Document& document, unsigned version, ApplePayPaymentRequest&& paymentRequest)
{
- auto canCall = canCallApplePaySessionAPIs(document);
+ auto canCall = canCreateSession(document);
if (canCall.hasException())
return canCall.releaseException();
@@ -470,7 +435,7 @@
auto& document = downcast<Document>(scriptExecutionContext);
- auto canCall = canCallApplePaySessionAPIs(document);
+ auto canCall = canCreateSession(document);
if (canCall.hasException())
return canCall.releaseException();
@@ -490,7 +455,7 @@
{
auto& document = downcast<Document>(scriptExecutionContext);
- auto canCall = canCallApplePaySessionAPIs(document);
+ auto canCall = canCreateSession(document);
if (canCall.hasException())
return canCall.releaseException();
@@ -501,7 +466,7 @@
{
auto& document = downcast<Document>(scriptExecutionContext);
- auto canCall = canCallApplePaySessionAPIs(document);
+ auto canCall = canCreateSession(document);
if (canCall.hasException())
return canCall.releaseException();
@@ -528,7 +493,7 @@
{
auto& document = downcast<Document>(scriptExecutionContext);
- auto canCall = canCallApplePaySessionAPIs(document);
+ auto canCall = canCreateSession(document);
if (canCall.hasException())
return canCall.releaseException();
Added: trunk/Source/WebCore/Modules/applepay/PaymentSession.cpp (0 => 224061)
--- trunk/Source/WebCore/Modules/applepay/PaymentSession.cpp (rev 0)
+++ trunk/Source/WebCore/Modules/applepay/PaymentSession.cpp 2017-10-26 23:25:41 UTC (rev 224061)
@@ -0,0 +1,77 @@
+/*
+ * Copyright (C) 2017 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"
+#include "PaymentSession.h"
+
+#if ENABLE(APPLE_PAY)
+
+#include "Document.h"
+#include "DocumentLoader.h"
+#include "SecurityOrigin.h"
+
+namespace WebCore {
+
+static bool isSecure(DocumentLoader& documentLoader)
+{
+ if (!documentLoader.response().url().protocolIs("https"))
+ return false;
+
+ if (!documentLoader.response().certificateInfo() || documentLoader.response().certificateInfo()->containsNonRootSHA1SignedCertificate())
+ return false;
+
+ return true;
+}
+
+ExceptionOr<void> PaymentSession::canCreateSession(Document& document)
+{
+ if (!document.frame())
+ return Exception { InvalidAccessError, "Trying to start an Apple Pay session from an inactive document." };
+
+ if (!isSecure(*document.loader()))
+ return Exception { InvalidAccessError, "Trying to start an Apple Pay session from an insecure document." };
+
+ auto& topDocument = document.topDocument();
+ if (&document != &topDocument) {
+ auto& topOrigin = topDocument.topOrigin();
+
+ if (!document.securityOrigin().isSameSchemeHostPort(topOrigin))
+ return Exception { InvalidAccessError, "Trying to start an Apple Pay session from a document with an different security origin than its top-level frame." };
+
+ for (auto* ancestorDocument = document.parentDocument(); ancestorDocument != &topDocument; ancestorDocument = ancestorDocument->parentDocument()) {
+ if (!isSecure(*ancestorDocument->loader()))
+ return Exception { InvalidAccessError, "Trying to start an Apple Pay session from a document with an insecure parent frame." };
+
+ if (!ancestorDocument->securityOrigin().isSameSchemeHostPort(topOrigin))
+ return Exception { InvalidAccessError, "Trying to start an Apple Pay session from a document with an different security origin than its top-level frame." };
+ }
+ }
+
+ return { };
+}
+
+} // namespace WebCore
+
+#endif // ENABLE(APPLE_PAY)
Modified: trunk/Source/WebCore/Modules/applepay/PaymentSession.h (224060 => 224061)
--- trunk/Source/WebCore/Modules/applepay/PaymentSession.h 2017-10-26 23:07:01 UTC (rev 224060)
+++ trunk/Source/WebCore/Modules/applepay/PaymentSession.h 2017-10-26 23:25:41 UTC (rev 224061)
@@ -28,10 +28,12 @@
#if ENABLE(APPLE_PAY)
#include "ApplePaySessionPaymentRequest.h"
+#include "ExceptionOr.h"
#include "PaymentSessionBase.h"
namespace WebCore {
+class Document;
class Payment;
class PaymentContact;
class PaymentMethod;
@@ -39,6 +41,8 @@
class PaymentSession : public virtual PaymentSessionBase {
public:
+ static ExceptionOr<void> canCreateSession(Document&);
+
virtual void validateMerchant(const URL&) = 0;
virtual void didAuthorizePayment(const Payment&) = 0;
virtual void didSelectShippingMethod(const ApplePaySessionPaymentRequest::ShippingMethod&) = 0;
Modified: trunk/Source/WebCore/Modules/paymentrequest/PaymentHandler.cpp (224060 => 224061)
--- trunk/Source/WebCore/Modules/paymentrequest/PaymentHandler.cpp 2017-10-26 23:07:01 UTC (rev 224060)
+++ trunk/Source/WebCore/Modules/paymentrequest/PaymentHandler.cpp 2017-10-26 23:25:41 UTC (rev 224061)
@@ -48,6 +48,19 @@
return nullptr;
}
+ExceptionOr<void> PaymentHandler::canCreateSession(Document& document)
+{
+#if ENABLE(APPLE_PAY)
+ auto result = PaymentSession::canCreateSession(document);
+ if (result.hasException())
+ return Exception { SecurityError, result.releaseException().releaseMessage() };
+#else
+ UNUSED_PARAM(document);
+#endif
+
+ return { };
+}
+
bool PaymentHandler::hasActiveSession(Document& document)
{
#if ENABLE(APPLE_PAY)
Modified: trunk/Source/WebCore/Modules/paymentrequest/PaymentHandler.h (224060 => 224061)
--- trunk/Source/WebCore/Modules/paymentrequest/PaymentHandler.h 2017-10-26 23:07:01 UTC (rev 224060)
+++ trunk/Source/WebCore/Modules/paymentrequest/PaymentHandler.h 2017-10-26 23:25:41 UTC (rev 224061)
@@ -42,6 +42,7 @@
class PaymentHandler : public virtual PaymentSessionBase {
public:
static RefPtr<PaymentHandler> create(Document&, PaymentRequest&, const PaymentRequest::MethodIdentifier&);
+ static ExceptionOr<void> canCreateSession(Document&);
static bool hasActiveSession(Document&);
virtual ExceptionOr<void> convertData(JSC::JSValue&&) = 0;
Modified: trunk/Source/WebCore/Modules/paymentrequest/PaymentRequest.cpp (224060 => 224061)
--- trunk/Source/WebCore/Modules/paymentrequest/PaymentRequest.cpp 2017-10-26 23:07:01 UTC (rev 224060)
+++ trunk/Source/WebCore/Modules/paymentrequest/PaymentRequest.cpp 2017-10-26 23:25:41 UTC (rev 224061)
@@ -314,7 +314,9 @@
// https://www.w3.org/TR/payment-request/#constructor
ExceptionOr<Ref<PaymentRequest>> PaymentRequest::create(Document& document, Vector<PaymentMethodData>&& methodData, PaymentDetailsInit&& details, PaymentOptions&& options)
{
- // FIXME: Check if this document is allowed to access the PaymentRequest API based on the allowpaymentrequest attribute.
+ auto canCreateSession = PaymentHandler::canCreateSession(document);
+ if (canCreateSession.hasException())
+ return canCreateSession.releaseException();
if (details.id.isNull())
details.id = createCanonicalUUIDString();
Modified: trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj (224060 => 224061)
--- trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj 2017-10-26 23:07:01 UTC (rev 224060)
+++ trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj 2017-10-26 23:25:41 UTC (rev 224061)
@@ -2804,6 +2804,7 @@
A1BF6B831AA96C7D00AF4A8A /* MockContentFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = A1BF6B811AA96C7D00AF4A8A /* MockContentFilter.h */; };
A1C150791E3F2B3E0032C98C /* PreviewConverter.mm in Sources */ = {isa = PBXBuildFile; fileRef = A1C150771E3F2B3E0032C98C /* PreviewConverter.mm */; };
A1C1507A1E3F2B3E0032C98C /* PreviewConverter.h in Headers */ = {isa = PBXBuildFile; fileRef = A1C150781E3F2B3E0032C98C /* PreviewConverter.h */; };
+ A1C2C5761FA2851600BA46FA /* PaymentSession.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A1C2C5751FA2851600BA46FA /* PaymentSession.cpp */; };
A1CBEF531F9EEE750028DE7C /* ApplePayPaymentMethodUpdateEvent.h in Headers */ = {isa = PBXBuildFile; fileRef = A1CBEF501F9EEE750028DE7C /* ApplePayPaymentMethodUpdateEvent.h */; };
A1CBEF541F9EEE750028DE7C /* ApplePayPaymentMethodUpdateEvent.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A1CBEF511F9EEE750028DE7C /* ApplePayPaymentMethodUpdateEvent.cpp */; };
A1CBEF611F9F09040028DE7C /* JSApplePayPaymentMethodUpdateEvent.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A1CBEF5F1F9F09020028DE7C /* JSApplePayPaymentMethodUpdateEvent.cpp */; };
@@ -10604,6 +10605,7 @@
A1BF6B811AA96C7D00AF4A8A /* MockContentFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MockContentFilter.h; sourceTree = "<group>"; };
A1C150771E3F2B3E0032C98C /* PreviewConverter.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = PreviewConverter.mm; sourceTree = "<group>"; };
A1C150781E3F2B3E0032C98C /* PreviewConverter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PreviewConverter.h; sourceTree = "<group>"; };
+ A1C2C5751FA2851600BA46FA /* PaymentSession.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = PaymentSession.cpp; sourceTree = "<group>"; };
A1C7FAA1133A5D3500D6732D /* JSXPathResultCustom.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSXPathResultCustom.cpp; sourceTree = "<group>"; };
A1CBEF501F9EEE750028DE7C /* ApplePayPaymentMethodUpdateEvent.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ApplePayPaymentMethodUpdateEvent.h; sourceTree = "<group>"; };
A1CBEF511F9EEE750028DE7C /* ApplePayPaymentMethodUpdateEvent.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = ApplePayPaymentMethodUpdateEvent.cpp; sourceTree = "<group>"; };
@@ -15374,6 +15376,7 @@
1A8A64391D19FC5300D0E00F /* PaymentMethod.h */,
1A8A64661D19FDFF00D0E00F /* PaymentRequestValidator.h */,
1A8A64651D19FDFF00D0E00F /* PaymentRequestValidator.mm */,
+ A1C2C5751FA2851600BA46FA /* PaymentSession.cpp */,
A1491DA21F859D870095F5D4 /* PaymentSession.h */,
);
path = applepay;
@@ -30207,6 +30210,7 @@
6A72798C1F16C29C003F39B8 /* InspectorShaderProgram.cpp in Sources */,
A1F9296F1F8D9F5B00523AF3 /* JSApplePayMerchantValidationEvent.cpp in Sources */,
A1CBEF611F9F09040028DE7C /* JSApplePayPaymentMethodUpdateEvent.cpp in Sources */,
+ 5372022E1FA29C0300016B2B /* JSGestureEvent.cpp in Sources */,
538EC93E1F99BF5A004D22A8 /* JSQuickTimePluginReplacement.cpp in Sources */,
538EC9421F99CE47004D22A8 /* JSTouch.cpp in Sources */,
538EC9451F99CE51004D22A8 /* JSTouchEvent.cpp in Sources */,
@@ -30273,6 +30277,7 @@
E453901E0EAFCACA003695C8 /* PasteboardIOS.mm in Sources */,
A1CFE0321F9E71290065C345 /* PaymentAddress.cpp in Sources */,
DE5F86101FA238D9006DB63A /* PaymentMerchantSessionCocoa.mm in Sources */,
+ A1C2C5761FA2851600BA46FA /* PaymentSession.cpp in Sources */,
26601EC014B3B9AD0012C0FE /* PlatformEventFactoryIOS.mm in Sources */,
C5278B0C17F212EA003A2998 /* PlatformPasteboardIOS.mm in Sources */,
E45390430EAFD637003695C8 /* PlatformScreenIOS.mm in Sources */,
@@ -30592,7 +30597,6 @@
DECA7E531F9EBD8300E3B661 /* UnifiedSource216.cpp in Sources */,
DECA7E541F9EBD8300E3B661 /* UnifiedSource217.cpp in Sources */,
DECA7E551F9EBD8300E3B661 /* UnifiedSource218.cpp in Sources */,
- 5372022E1FA29C0300016B2B /* JSGestureEvent.cpp in Sources */,
DECA7E561F9EBD8300E3B661 /* UnifiedSource219.cpp in Sources */,
DECA7E571F9EBD8300E3B661 /* UnifiedSource220.cpp in Sources */,
DECA7E581F9EBD8300E3B661 /* UnifiedSource221.cpp in Sources */,