-
Notifications
You must be signed in to change notification settings - Fork 128
fix: malformed redirect url when return_url has query params #1599
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,6 +3,7 @@ open ErrorUtils | |
| open Identity | ||
| open Utils | ||
| open EventListenerManager | ||
| open URLModule | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
If Consider adding a try-catch fallback: let redirectUrl = try {
let url = makeUrl(returnUrl)
url.searchParams.set("payment_intent_client_secret", clientSecretRef.contents)
url.searchParams.set("status", status)
url.href
} catch {
| _ => `${returnUrl}?payment_intent_client_secret=${clientSecretRef.contents}&status=${status}`
}
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @XyneSpaces Thanks for flagging this. On On try/catch + concat fallback: I’m hesitant to add that. If If
Thanks for the review. Let me know what you prefer. |
||
|
|
||
| type trustPayFunctions = { | ||
| finishApplePaymentV2: (string, ApplePayTypes.paymentRequestData, string) => promise<JSON.t>, | ||
|
|
@@ -811,7 +812,10 @@ let make = ( | |
| let dict = json->getDictFromJson | ||
| let status = dict->getString("status", "") | ||
| let returnUrl = dict->getString("return_url", "") | ||
| let redirectUrl = `${returnUrl}?payment_intent_client_secret=${clientSecretRef.contents}&status=${status}` | ||
| let url = makeUrl(returnUrl) | ||
| url.searchParams.set("payment_intent_client_secret", clientSecretRef.contents) | ||
| url.searchParams.set("status", status) | ||
| let redirectUrl = url.href | ||
| if redirect.contents === "always" { | ||
| Utils.replaceRootHref(redirectUrl, redirectionFlags) | ||
| resolve(JSON.Encode.null) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
URLModule.makeUrlcalls the native JavaScriptURLconstructor, which throws aTypeErroron invalid URLs. The code:Will throw if
return_urlis empty or malformed. Consider adding a guard:Or wrap in try-catch if invalid URLs should be handled gracefully.