Skip to content

Commit dd08f81

Browse files
fix: Open redirect URL if not a web-based scheme
1 parent c56bdc3 commit dd08f81

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import Foundation
2+
3+
extension URL {
4+
var hasWebBasedScheme: Bool {
5+
["http", "https"].contains(scheme?.lowercased() ?? "")
6+
}
7+
}

Sources/PrimerSDK/Classes/User Interface/TokenizationViewModels/WebRedirectPaymentMethodTokenizationViewModel.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,14 @@ class WebRedirectPaymentMethodTokenizationViewModel: PaymentMethodTokenizationVi
148148

149149
@MainActor
150150
override func presentPaymentMethodUserInterface() async throws {
151+
guard redirectUrl.hasWebBasedScheme else {
152+
if UIApplication.shared.canOpenURL(redirectUrl) {
153+
return UIApplication.shared.open(redirectUrl)
154+
} else {
155+
throw handled(primerError: .invalidUrl(url: redirectUrl.absoluteString))
156+
}
157+
}
158+
151159
let safariViewController = SFSafariViewController(url: redirectUrl)
152160
safariViewController.delegate = self
153161
webViewController = safariViewController

0 commit comments

Comments
 (0)