ignore unknown messages#287
Conversation
This stack of pull requests is managed by Graphite. Learn more about stacking. |
7156a26 to
b2500fb
Compare
| } | ||
| assertThat(js).contains("\"error\"") | ||
| assertThat(js).contains("-32601") | ||
| fun `ec auth is silently ignored and not delegated to client`() { |
There was a problem hiding this comment.
bringing this back in PR 3, but across all platforms
b2500fb to
b61158a
Compare
b61158a to
4b0d021
Compare
| extension CheckoutWebView { | ||
| fileprivate static let readyMethod = "ec.ready" | ||
|
|
||
| fileprivate static let supportedProtocolMethods: Set<String> = [ |
There was a problem hiding this comment.
CheckoutProtocol is an enum of the events we support
Should we add CaseIterable to it so we can get all supported cases with CheckoutProtocol.allCases
| CheckoutProtocol.windowOpen.method | ||
| ] | ||
|
|
||
| fileprivate static func supportedProtocolMethod(_ body: String) -> String? { |
There was a problem hiding this comment.
feels like this would make sense to exist in the protocol side too
| extension CheckoutWebView { | ||
| fileprivate static let readyMethod = "ec.ready" | ||
|
|
||
| fileprivate static let supportedProtocolMethods: Set<String> = [ | ||
| readyMethod, | ||
| CheckoutProtocol.start.method, | ||
| CheckoutProtocol.complete.method, | ||
| CheckoutProtocol.error.method, | ||
| CheckoutProtocol.lineItemsChange.method, | ||
| CheckoutProtocol.messagesChange.method, | ||
| CheckoutProtocol.totalsChange.method, | ||
| CheckoutProtocol.windowOpen.method | ||
| ] | ||
|
|
||
| fileprivate static func supportedProtocolMethod(_ body: String) -> String? { | ||
| guard | ||
| let object = try? JSONSerialization.jsonObject(with: Data(body.utf8)) as? [String: Any], | ||
| object["jsonrpc"] as? String == "2.0", | ||
| let method = object["method"] as? String, | ||
| supportedProtocolMethods.contains(method) | ||
| else { | ||
| return nil | ||
| } | ||
|
|
||
| return method | ||
| } | ||
| } |
There was a problem hiding this comment.
On the protocol side, we're already only binding to a limited set of events →
So this feels duplicative, but, saying that, if we were to extend the protocol to expose it as separate package we would need to bind the relevant ones here.
What do you think about keeping this logic in the protocol until this is needed?
4b0d021 to
e711cb0
Compare

What changes are you making?
PR 1 -> parity with web r.e. an allowlist of events
Previously, the SDK responded to certain unsupported ECP methods (e.g.
ec.auth,ec.payment.credential_request) with an explicit JSON-RPC-32601"method not supported" error, and forwarded any unknown methods to the consumerCheckoutCommunicationClient. This approach exposed internal protocol details and allowed arbitrary unrecognized methods to reach the client.This PR replaces that behavior with an explicit allow-list of supported protocol methods on both Android and iOS:
UNSUPPORTED_METHODS(which sent explicit error responses) withSUPPORTED_CLIENT_METHODS, an allow-list aligned with the web component'sCHECKOUT_PROTOCOL_MESSAGES. Methods outside this list — includingep.*,ec.auth, and any unknown methods — are now silently ignored rather than forwarded or rejected with an error.supportedProtocolMethodsallow-list inCheckoutWebView. Incoming messages are parsed and their method checked against this list before any further processing or client delegation occurs. Messages with unsupported methods are dropped silently.CheckoutCommunicationClientdocumentation is updated on both platforms to clarify that only supported ECP messages are forwarded to the client.How to test
ec.auth,ec.payment.credential_request,ep.cart.ready, or a custom unknown method) to the bridge on both Android and iOS.CheckoutCommunicationClientdoes not receive the message.ec.window.open_request,ec.messages.change) and verify it is still correctly delegated to the client and any response is forwarded back to the web page.Before you merge
Important
platforms/swift/README.mdand/orplatforms/android/README.md)Releasing a new Swift version?
ShopifyCheckoutKit.podspecplatforms/swift/Sources/ShopifyCheckoutKit/ShopifyCheckoutKit.swiftplatforms/swift/CHANGELOG.mdplatforms/swift/README.md(major version only)Releasing a new Android version?
versionNameinplatforms/android/lib/build.gradleplatforms/android/CHANGELOG.mdplatforms/android/README.mdTip
See the Contributing documentation for the full release process per platform.