Skip to content

[MOB-8537] updates action runner logic to check allowed protocols #769

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

Open
wants to merge 9 commits into
base: master
Choose a base branch
from

Conversation

evantk91
Copy link
Collaborator

@evantk91 evantk91 commented May 14, 2024

🔹 Jira Ticket(s)

✏️ Description

This pull request updates the action runner to check if protocol is allowed before checking if url can be handled by the url handler or custom action handler.

@joaodordio joaodordio self-assigned this Sep 23, 2024
@jena-chakour jena-chakour requested review from joaodordio and davidtruong and removed request for bradumbaugh May 20, 2025 15:48
@joaodordio joaodordio requested a review from Copilot May 30, 2025 14:01
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR updates the ActionRunner to enforce an allowed-protocols check before attempting to open URLs via handlers or the system opener.

  • Introduces a guard to early-exit if the action isn’t an openUrl or the URL’s protocol isn’t allowed
  • Refactors external handler invocation and URL opening into separate conditional blocks
  • Ensures a definitive false return when no handling occurs
Comments suppressed due to low confidence (2)

swift-sdk/Internal/ActionRunner.swift:45

  • [nitpick] You're calling detectActionType(fromAction:) again. Consider capturing the URL once (e.g., via the earlier guard) and reusing it to avoid duplicate calls and improve readability.
if case let .openUrl(url) = detectActionType(fromAction: action),

swift-sdk/Internal/ActionRunner.swift:33

  • New protocol-filtering behavior should be covered by unit tests. Please add tests for allowed vs. disallowed protocols to prevent regressions.
allowedProtocols: [String] = []) -> Bool {

Comment on lines +33 to +52
guard case let .openUrl(url) = detectActionType(fromAction: action),
shouldOpenUrl(url: url, from: context.source, withAllowedProtocols: allowedProtocols) else {
return false
}

if case let handled = callExternalHandlers(action: action,
from: context.source,
urlHandler: urlHandler,
customActionHandler: customActionHandler), handled {
return true
}

if case let .openUrl(url) = detectActionType(fromAction: action),
let urlOpener = urlOpener {
urlOpener.open(url: url)
return true
} else {
if case let .openUrl(url) = detectActionType(fromAction: action),
shouldOpenUrl(url: url, from: context.source, withAllowedProtocols: allowedProtocols),
let urlOpener = urlOpener {
urlOpener.open(url: url)
return true
} else {
return false
}
}

return false

Copy link
Preview

Copilot AI May 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This guard only allows openUrl actions through and returns false for all other action types, preventing external/custom handlers from running on non-URL actions. Consider separating the protocol check into the URL branch so other action types still invoke callExternalHandlers.

Copilot uses AI. Check for mistakes.

Comment on lines +38 to +41
if case let handled = callExternalHandlers(action: action,
from: context.source,
urlHandler: urlHandler,
customActionHandler: customActionHandler), handled {
Copy link
Preview

Copilot AI May 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] Using case let for a Boolean result is unconventional. Replace if case let handled = ... with let handled = ... outside the if, then if handled { ... } for clarity.

Copilot uses AI. Check for mistakes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants