Skip to content

Commit d5b9e7d

Browse files
evantk91Evan Greerjoaodordio
authored
[MOB-8537] updates action runner logic to check allowed protocols (#769)
Co-authored-by: Evan Greer <[email protected]> Co-authored-by: Joao Dordio <[email protected]>
1 parent 965be64 commit d5b9e7d

File tree

7 files changed

+46
-41
lines changed

7 files changed

+46
-41
lines changed

swift-sdk/Internal/ActionRunner.swift

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -29,23 +29,28 @@ struct ActionRunner {
2929
customActionHandler: CustomActionHandler? = nil,
3030
urlOpener: UrlOpenerProtocol? = nil,
3131
allowedProtocols: [String] = []) -> Bool {
32-
let handled = callExternalHandlers(action: action,
33-
from: context.source,
34-
urlHandler: urlHandler,
35-
customActionHandler: customActionHandler)
3632

37-
if handled {
38-
return true
39-
} else {
40-
if case let .openUrl(url) = detectActionType(fromAction: action),
41-
shouldOpenUrl(url: url, from: context.source, withAllowedProtocols: allowedProtocols),
42-
let urlOpener = urlOpener {
43-
urlOpener.open(url: url)
44-
return true
45-
} else {
33+
// For URL actions, validate protocol before proceeding
34+
if case let .openUrl(url) = detectActionType(fromAction: action) {
35+
guard shouldOpenUrl(url: url, from: context.source, withAllowedProtocols: allowedProtocols) else {
4636
return false
4737
}
4838
}
39+
40+
if case let handled = callExternalHandlers(action: action,
41+
from: context.source,
42+
urlHandler: urlHandler,
43+
customActionHandler: customActionHandler), handled {
44+
return true
45+
}
46+
47+
if case let .openUrl(url) = detectActionType(fromAction: action),
48+
let urlOpener = urlOpener {
49+
urlOpener.open(url: url)
50+
return true
51+
}
52+
53+
return false
4954
}
5055

5156
// MARK: - Private

tests/hosting-apps/ui-tests-app/ViewController.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class ViewController: UIViewController {
3131
ITBInfo()
3232

3333
let html = """
34-
<a href="http://website/resource#something">Click Me</a>
34+
<a href="https://website/resource#something">Click Me</a>
3535
<meta name='viewport' content='width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=no'>
3636
"""
3737
InAppDisplayer.showIterableHtmlMessage(html) { url in
@@ -104,7 +104,7 @@ class ViewController: UIViewController {
104104

105105
let messageId = "zeeMessageId"
106106
let html = """
107-
<a href="http://website/resource#something">Click Me</a>
107+
<a href="https://website/resource#something">Click Me</a>
108108
"""
109109
let content = IterableHtmlInAppContent(edgeInsets: .zero, html: html)
110110
let message = IterableInAppMessage(messageId: messageId, campaignId: 1234, content: content)
@@ -170,7 +170,7 @@ class ViewController: UIViewController {
170170

171171
let messageId = "zeeMessageId"
172172
let html = """
173-
<a href="http://website/resource#something">Click Me</a>
173+
<a href="https://website/resource#something">Click Me</a>
174174
"""
175175
let padding = Padding(top: .autoExpand,
176176
left: 10,

tests/notification-extension-tests/NotificationExtensionTests.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ class NotificationExtensionTests: XCTestCase {
171171
"openApp": true,
172172
"action": [
173173
"type": "openUrl",
174-
"data": "http://maps.apple.com/?ll=37.7828,-122.3984"
174+
"data": "https://maps.apple.com/?ll=37.7828,-122.3984"
175175
]
176176
],
177177
[
@@ -383,7 +383,7 @@ class NotificationExtensionTests: XCTestCase {
383383
"title": "Open App",
384384
"action": [
385385
"type": "openUrl",
386-
"data": "http://maps.apple.com/?ll=37.7828,-122.3984"
386+
"data": "https://maps.apple.com/?ll=37.7828,-122.3984"
387387
],
388388
] as [String : Any]],
389389
] as [String : Any],
@@ -422,7 +422,7 @@ class NotificationExtensionTests: XCTestCase {
422422
"title": "Open App",
423423
"action": [
424424
"type": "openUrl",
425-
"data": "http://maps.apple.com/?ll=37.7828,-122.3984"
425+
"data": "https://maps.apple.com/?ll=37.7828,-122.3984"
426426
],
427427
"actionIcon": [
428428
"iconType": "systemImage",
@@ -466,7 +466,7 @@ class NotificationExtensionTests: XCTestCase {
466466
"title": "Open App",
467467
"action": [
468468
"type": "openUrl",
469-
"data": "http://maps.apple.com/?ll=37.7828,-122.3984"
469+
"data": "https://maps.apple.com/?ll=37.7828,-122.3984"
470470
],
471471
"actionIcon": [
472472
"iconType": "templateImage",

tests/ui-tests/UITests.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ class UITests: XCTestCase {
105105
// }
106106
//
107107
// func testShowInApp1() {
108-
// inAppTest(buttonName: "Show InApp#1", linkName: "Click Me", expectedCallbackUrl: "http://website/resource#something")
108+
// inAppTest(buttonName: "Show InApp#1", linkName: "Click Me", expectedCallbackUrl: "https://website/resource#something")
109109
// }
110110
//
111111
// // Full Screen
@@ -120,7 +120,7 @@ class UITests: XCTestCase {
120120
//
121121
// // Full Screen
122122
// func testShowInApp4() {
123-
// inAppTest(buttonName: "Show InApp#4", linkName: "Click Me", expectedCallbackUrl: "http://website/resource#something")
123+
// inAppTest(buttonName: "Show InApp#4", linkName: "Click Me", expectedCallbackUrl: "https://website/resource#something")
124124
// }
125125
//
126126
// // Full Screen

tests/unit-tests/DeepLinkTests.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@ class DeepLinkTests: XCTestCase {
1515
super.tearDown()
1616
}
1717

18-
private let iterableRewriteURL = "http://links.iterable.com/a/60402396fbd5433eb35397b47ab2fb83?_e=joneng%40iterable.com&_m=93125f33ba814b13a882358f8e0852e0"
19-
private let iterableNoRewriteURL = "http://links.iterable.com/u/60402396fbd5433eb35397b47ab2fb83?_e=joneng%40iterable.com&_m=93125f33ba814b13a882358f8e0852e0"
18+
private let iterableRewriteURL = "https://links.iterable.com/a/60402396fbd5433eb35397b47ab2fb83?_e=joneng%40iterable.com&_m=93125f33ba814b13a882358f8e0852e0"
19+
private let iterableNoRewriteURL = "https://links.iterable.com/u/60402396fbd5433eb35397b47ab2fb83?_e=joneng%40iterable.com&_m=93125f33ba814b13a882358f8e0852e0"
2020

21-
private let redirectRequest = "https://httpbin.org/redirect-to?url=http://example.com"
22-
private let exampleUrl = "http://example.com"
21+
private let redirectRequest = "https://httpbin.org/redirect-to?url=https://example.com"
22+
private let exampleUrl = "https://example.com"
2323

2424
func testTrackUniversalDeepLinkRewrite() {
2525
let expectation1 = expectation(description: #function)

tests/unit-tests/InAppParsingTests.swift

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ class InAppParsingTests: XCTestCase {
309309
saveToInbox: false,
310310
inboxMetadata: nil,
311311
customPayload: nil)
312-
let buttonUrl = "http://somewhere.com"
312+
let buttonUrl = "https://somewhere.com"
313313
let expectation1 = expectation(description: "track in app click")
314314

315315
let networkSession = MockNetworkSession(statusCode: 200)
@@ -515,7 +515,7 @@ class InAppParsingTests: XCTestCase {
515515
"inAppMessages" : [
516516
{
517517
"content" : {
518-
"html" : "<a href=\\"http://somewhere.com\\">Click here</a>"
518+
"html" : "<a href=\\"https://somewhere.com\\">Click here</a>"
519519
},
520520
"messageId" : "messageId-\(id)",
521521
"campaignId" : \(id)
@@ -534,7 +534,7 @@ class InAppParsingTests: XCTestCase {
534534
"inAppMessages" : [
535535
{
536536
"content" : {
537-
"html" : "<a href=\\"http://somewhere.com\\">Click here</a>"
537+
"html" : "<a href=\\"https://somewhere.com\\">Click here</a>"
538538
},
539539
"messageId" : "messageId-\(id)",
540540
"campaignId" : \(id),
@@ -558,7 +558,7 @@ class InAppParsingTests: XCTestCase {
558558
"inAppMessages" : [
559559
{
560560
"content" : {
561-
"html" : "<a href=\\"http://somewhere.com\\">Click here</a>"
561+
"html" : "<a href=\\"https://somewhere.com\\">Click here</a>"
562562
},
563563
"messageId" : "messageId-\(id)",
564564
"campaignId" : \(id),
@@ -633,31 +633,31 @@ class InAppParsingTests: XCTestCase {
633633
"inAppMessages" : [
634634
{
635635
"content" : {
636-
"html" : "<a href=\\"http://somewhere.com\\">Click here</a>"
636+
"html" : "<a href=\\"https://somewhere.com\\">Click here</a>"
637637
},
638638
"messageId" : "messageId1",
639639
"campaignId" : 1,
640640
"customPayload" : \(customPayload1.toJsonString())
641641
},
642642
{
643643
"content" : {
644-
"html" : "<a href=\\"http://somewhere.com\\">Click here</a>"
644+
"html" : "<a href=\\"https://somewhere.com\\">Click here</a>"
645645
},
646646
"messageId" : "messageId2",
647647
"campaignId" : 2,
648648
"customPayload" : \(customPayload2.toJsonString())
649649
},
650650
{
651651
"content" : {
652-
"html" : "<a href=\\"http://somewhere.com\\">Click here</a>"
652+
"html" : "<a href=\\"https://somewhere.com\\">Click here</a>"
653653
},
654654
"messageId" : "messageId3",
655655
"campaignId" : 3,
656656
"customPayload" : {}
657657
},
658658
{
659659
"content" : {
660-
"html" : "<a href=\\"http://somewhere.com\\">Click here</a>"
660+
"html" : "<a href=\\"https://somewhere.com\\">Click here</a>"
661661
},
662662
"messageId" : "messageId4",
663663
"campaignId" : 4,
@@ -716,7 +716,7 @@ class InAppParsingTests: XCTestCase {
716716
{
717717
"content" : {
718718
"type" : "html",
719-
"html" : "<a href=\\"http://somewhere.com\\">Click here</a>"
719+
"html" : "<a href=\\"https://somewhere.com\\">Click here</a>"
720720
},
721721
"messageId" : "messageId1",
722722
"campaignId" : 1,
@@ -731,7 +731,7 @@ class InAppParsingTests: XCTestCase {
731731
"saveToInbox" : true,
732732
"content" : {
733733
"type" : "html",
734-
"html" : "<a href=\\"http://somewhere.com\\">Click here</a>",
734+
"html" : "<a href=\\"https://somewhere.com\\">Click here</a>",
735735
},
736736
"messageId" : "messageId2",
737737
"campaignId" : 2,
@@ -748,7 +748,7 @@ class InAppParsingTests: XCTestCase {
748748
},
749749
{
750750
"content" : {
751-
"html" : "<a href=\\"http://somewhere.com\\">Click here</a>"
751+
"html" : "<a href=\\"https://somewhere.com\\">Click here</a>"
752752
},
753753
"messageId" : "messageId3",
754754
"campaignId" : 3,
@@ -760,7 +760,7 @@ class InAppParsingTests: XCTestCase {
760760
},
761761
{
762762
"content" : {
763-
"html" : "<a href=\\"http://somewhere.com\\">Click here</a>"
763+
"html" : "<a href=\\"https://somewhere.com\\">Click here</a>"
764764
},
765765
"messageId" : "messageId4",
766766
"campaignId" : 4,

tests/unit-tests/IterableAPITests.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1088,14 +1088,14 @@ class IterableAPITests: XCTestCase {
10881088
"messageId": "messageId",
10891089
"defaultAction": [
10901090
"type": "openUrl",
1091-
"data": "http://somewhere.com",
1091+
"data": "https://somewhere.com",
10921092
],
10931093
] as [String : Any],
10941094
]
10951095
let launchOptions: [UIApplication.LaunchOptionsKey: Any] = [UIApplication.LaunchOptionsKey.remoteNotification: userInfo]
10961096
let urlDelegate = MockUrlDelegate(returnValue: true)
10971097
urlDelegate.callback = { url, _ in
1098-
XCTAssertEqual(url.absoluteString, "http://somewhere.com")
1098+
XCTAssertEqual(url.absoluteString, "https://somewhere.com")
10991099
expectation1.fulfill()
11001100
}
11011101
let config = IterableConfig()
@@ -1118,7 +1118,7 @@ class IterableAPITests: XCTestCase {
11181118
"isGhostPush": false,
11191119
"defaultAction": [
11201120
"type": "openUrl",
1121-
"data": "http://somewhere.com",
1121+
"data": "https://somewhere.com",
11221122
],
11231123
] as [String : Any],
11241124
]

0 commit comments

Comments
 (0)