Skip to content
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

Block the opening of potentially malicious URLs via custom intents su… (uplift to 1.68.x) #24651

Merged
merged 1 commit into from
Jul 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ios/brave-ios/App/iOS/Delegates/SceneDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -489,7 +489,7 @@ extension SceneDelegate {

private func switchToTabForIntentURL(_ scene: UIWindowScene, intentURL: String?) {
if let browserViewController = scene.browserViewController {
guard let siteURL = intentURL, let url = URL(string: siteURL) else {
guard let siteURL = intentURL, let url = URL(string: siteURL), url.isWebPage() else {
browserViewController.openBlankNewTab(
attemptLocationFieldFocus: false,
isPrivate: Preferences.Privacy.privateBrowsingOnly.value
Expand Down
1 change: 1 addition & 0 deletions ios/brave-ios/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ var package = Package(
),
.target(
name: "BrowserIntentsModels",
dependencies: ["Shared"],
sources: ["BrowserIntents.intentdefinition", "CustomIntentHandler.swift"],
plugins: ["IntentBuilderPlugin"]
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,32 @@
import CoreSpotlight
import Intents
import MobileCoreServices
import Shared

public class OpenWebsiteIntentHandler: NSObject, OpenWebsiteIntentHandling {

public func handle(
intent: OpenWebsiteIntent,
completion: @escaping (OpenWebsiteIntentResponse) -> Void
) {
guard let siteURL = intent.websiteURL else {
guard let urlString = intent.websiteURL, let url = URL(string: urlString), let host = url.host,
!host.isEmpty, url.isWebPage(includeDataURIs: false)
else {
completion(OpenWebsiteIntentResponse(code: .failure, userActivity: nil))

return
}

completion(OpenWebsiteIntentResponse.success(websiteURL: siteURL))
completion(OpenWebsiteIntentResponse.success(websiteURL: urlString))
}

public func confirm(
intent: OpenWebsiteIntent,
completion: @escaping (OpenWebsiteIntentResponse) -> Void
) {
guard let urlString = intent.websiteURL, URL(string: urlString) != nil else {
guard let urlString = intent.websiteURL, let url = URL(string: urlString), let host = url.host,
!host.isEmpty, url.isWebPage(includeDataURIs: false)
else {
completion(OpenWebsiteIntentResponse(code: .failure, userActivity: nil))
return
}
Expand All @@ -41,20 +46,24 @@ public class OpenHistoryWebsiteIntentHandler: NSObject, OpenHistoryWebsiteIntent
intent: OpenHistoryWebsiteIntent,
completion: @escaping (OpenHistoryWebsiteIntentResponse) -> Void
) {
guard let siteURL = intent.websiteURL else {
guard let urlString = intent.websiteURL, let url = URL(string: urlString), let host = url.host,
!host.isEmpty, url.isWebPage(includeDataURIs: false)
else {
completion(OpenHistoryWebsiteIntentResponse(code: .failure, userActivity: nil))

return
}

completion(OpenHistoryWebsiteIntentResponse.success(websiteURL: siteURL))
completion(OpenHistoryWebsiteIntentResponse.success(websiteURL: urlString))
}

public func confirm(
intent: OpenHistoryWebsiteIntent,
completion: @escaping (OpenHistoryWebsiteIntentResponse) -> Void
) {
guard let urlString = intent.websiteURL, URL(string: urlString) != nil else {
guard let urlString = intent.websiteURL, let url = URL(string: urlString), let host = url.host,
!host.isEmpty, url.isWebPage(includeDataURIs: false)
else {
completion(OpenHistoryWebsiteIntentResponse(code: .failure, userActivity: nil))
return
}
Expand All @@ -69,20 +78,24 @@ public class OpenBookmarkWebsiteIntentHandler: NSObject, OpenBookmarkWebsiteInte
intent: OpenBookmarkWebsiteIntent,
completion: @escaping (OpenBookmarkWebsiteIntentResponse) -> Void
) {
guard let siteURL = intent.websiteURL else {
guard let urlString = intent.websiteURL, let url = URL(string: urlString), let host = url.host,
!host.isEmpty, url.isWebPage(includeDataURIs: false)
else {
completion(OpenBookmarkWebsiteIntentResponse(code: .failure, userActivity: nil))

return
}

completion(OpenBookmarkWebsiteIntentResponse.success(websiteURL: siteURL))
completion(OpenBookmarkWebsiteIntentResponse.success(websiteURL: urlString))
}

public func confirm(
intent: OpenBookmarkWebsiteIntent,
completion: @escaping (OpenBookmarkWebsiteIntentResponse) -> Void
) {
guard let urlString = intent.websiteURL, URL(string: urlString) != nil else {
guard let urlString = intent.websiteURL, let url = URL(string: urlString), let host = url.host,
!host.isEmpty, url.isWebPage(includeDataURIs: false)
else {
completion(OpenBookmarkWebsiteIntentResponse(code: .failure, userActivity: nil))
return
}
Expand Down
Loading