Crash in WebCore::PaymentRequest::canMakePayment when Apple Pay payment method data...
authoraestes@apple.com <aestes@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 7 Nov 2018 23:49:29 +0000 (23:49 +0000)
committeraestes@apple.com <aestes@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 7 Nov 2018 23:49:29 +0000 (23:49 +0000)
commitd6e84e2f2c26a40ba968540d38452f2fe03df62d
tree582ad7aafff7dccb5eed5178602755533be445a4
parentb2c1525431c382d5f31d96c6fe1b1ab17520220b
Crash in WebCore::PaymentRequest::canMakePayment when Apple Pay payment method data is missing
https://bugs.webkit.org/show_bug.cgi?id=191331

Reviewed by Alexey Proskuryakov.

Source/WebCore:

Apple Pay requires merchants specify an ApplePayRequest (which contains several required
fields) as payment method data when constructing a new PaymentRequest. If the
ApplePayRequest is missing required fields, or is missing entirely, canMakePayment() should
resolve to false.

We would properly resolve to false when an ApplePayRequest was specified with missing
required fields, but we would crash when the ApplePayRequest was missing entirely.

This patch fixes the crash by checking for an empty JSValue before trying to convert it to
an ApplePayRequest struct. Because we stringify ApplePayRequests in the PaymentRequest
constructor then parse them again in canMakePayments, an undefined or null payment method
data stringifies to a null String, which then parses to an empty JSValue.

Added test case to http/tests/paymentrequest/payment-request-canmakepayment-method.https.html.

* Modules/applepay/paymentrequest/ApplePayPaymentHandler.cpp:
(WebCore::ApplePayPaymentHandler::convertData):
* Modules/paymentrequest/PaymentRequest.cpp:
(WebCore::PaymentRequest::canMakePayment):

LayoutTests:

* http/tests/paymentrequest/payment-request-canmakepayment-method.https.html:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@237947 268f45cc-cd09-0410-ab3c-d52691b4dbfc
LayoutTests/ChangeLog
LayoutTests/http/tests/paymentrequest/payment-request-canmakepayment-method.https.html
Source/WebCore/ChangeLog
Source/WebCore/Modules/applepay/paymentrequest/ApplePayPaymentHandler.cpp
Source/WebCore/Modules/paymentrequest/PaymentRequest.cpp