[DTINAPPXO-3265][DTINAPPXO-3391] Resume Flow fix: Extract query-style params embedded in the hash fragment#2599
Conversation
314c53a to
690fcee
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #2599 +/- ##
==========================================
- Coverage 54.51% 54.26% -0.26%
==========================================
Files 162 164 +2
Lines 16365 17712 +1347
Branches 1083 1218 +135
==========================================
+ Hits 8922 9611 +689
- Misses 7330 7975 +645
- Partials 113 126 +13
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
| searchParams.approval_token_id || | ||
| searchParams.approval_session_id | ||
| ? searchParams | ||
| : { ...getParamsFromHashFragment(), ...searchParams }; |
There was a problem hiding this comment.
Potential false positive for merchant hash params
This new fallback to getParamsFromHashFragment() introduces a risk: if a merchant's SPA uses token in their own hash fragment (e.g. https://merchant.com/shop#products?token=my-cart-token), this will now be detected as a resume flow and trigger onCancel.
On main this was safe — the web fallback only read window.location.search, so merchant hash params were ignored. With this change, any page with token= or a vault param in the hash will match.
Can we explore an additional guard here for this scenaio?
There was a problem hiding this comment.
@nikrom17 This isn't a new risk introduced by this change - the same issue already exists with query params today. If a merchant uses a query param named token, it will incorrectly trigger the cancel flow. This change brings hash params to parity with query params. If we want to address the false positive problem, it should be tackled holistically for both query and hash params. (I think we should, but not part of this PR)
There was a problem hiding this comment.
I created a ticket to handle this issue DTINAPPXO-3434
9e7eb9c to
b05f89f
Compare
Description
Two related fixes for the app-switch resume flow when a merchant's
return_urlcontains a hash fragment:Hash fragment param extraction: When a merchant's
return_urlcontains a hash fragment (e.g./checkout/#payment), PayPal params (token,PayerID) get appended inside the hash as query-style params (e.g.#payment?token=ABC&PayerID=XYZ) in the web fallback flow.This enters into the resume flow which only recognizes hashes starting with a known action (
onApprove,onCancel,onError) and silently dropped params embedded in non-action hash fragments. This change adds agetParamsFromHashFragment()helper that extracts query-style params from the hash, and updatesgetAppSwitchParamsWebFallback()to use it as a fallback when no PayPal params are found in the query string.Multiple
?parsing fix: When returning from PayPal app with a merchant'sreturn_urlwhich itself contains a?(e.g.#hash?query=param), the native app constructs the return URL as#onApprove?token=...&hash?query=param. UsingString.split("?")produced 3 segments and destructuring only captured the first two, silently dropping everything after the second?. Replaced withindexOf+sliceto only split on the first?, consistent with howgetParamsFromHashFragment()already handles the same parsing.Reproduction Steps
return_urlwith a hash fragment, e.g.https://example.com/checkout/#paymentorhttps://example.com#hash?query=paramhttps://example.com/checkout/#payment?token=3JB49854KA&PayerID=BF44HY8FDgetAppSwitchResumeParams()returnsnull, checkout does not resumeFor the native app case with a merchant hash containing
?:return_urllikehttps://example.com#hash?query=paramhttps://example.com#onApprove?token=...&button_session_id=...&hash?query=paramsplit("?")drops the third segment — works by luck today but is fragileslice()preserves the full query string after the first?Dependent Changes
None