Skip to content

Commit 6cc1ad8

Browse files
committed
Force HTTPS on site URLs to avoid ATS errors
1 parent a4197fe commit 6cc1ad8

File tree

2 files changed

+6
-9
lines changed

2 files changed

+6
-9
lines changed

Modules/Sources/Networking/Model/Site.swift

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ public struct Site: Decodable, Equatable, Hashable, GeneratedFakeable, Generated
117117
let siteID = try siteContainer.decode(Int64.self, forKey: .siteID)
118118
let name = try siteContainer.decode(String.self, forKey: .name)
119119
let description = try siteContainer.decode(String.self, forKey: .description)
120-
let url = try siteContainer.decode(String.self, forKey: .url)
120+
let url = Self.safeURL(try siteContainer.decode(String.self, forKey: .url))
121121
let capabilitiesContainer = try siteContainer.nestedContainer(keyedBy: CapabilitiesKeys.self, forKey: .capabilities)
122122
let isSiteOwner = try capabilitiesContainer.decode(Bool.self, forKey: .isSiteOwner)
123123
let isAdmin = try capabilitiesContainer.decode(Bool.self, forKey: .isAdmin)
@@ -130,8 +130,8 @@ public struct Site: Decodable, Equatable, Hashable, GeneratedFakeable, Generated
130130
let jetpackConnectionActivePlugins = try optionsContainer.decodeIfPresent([String].self, forKey: .jetpackConnectionActivePlugins) ?? []
131131
let timezone = try optionsContainer.decode(String.self, forKey: .timezone)
132132
let gmtOffset = try optionsContainer.decode(Double.self, forKey: .gmtOffset)
133-
let adminURL = try optionsContainer.decode(String.self, forKey: .adminURL)
134-
let loginURL = try optionsContainer.decode(String.self, forKey: .loginURL)
133+
let adminURL = Self.safeURL(try optionsContainer.decode(String.self, forKey: .adminURL))
134+
let loginURL = Self.safeURL(try optionsContainer.decode(String.self, forKey: .loginURL))
135135
let frameNonce = try optionsContainer.decode(String.self, forKey: .frameNonce)
136136
let canBlaze = optionsContainer.failsafeDecodeIfPresent(booleanForKey: .canBlaze) ?? false
137137
let visibility = optionsContainer.failsafeDecodeIfPresent(SiteVisibility.self, forKey: .visibility) ?? .privateSite
@@ -333,7 +333,8 @@ public enum SiteVisibility: Int, Codable, GeneratedFakeable {
333333
///
334334
public extension Site {
335335

336-
private var jetpackCanonicalURL: String {
336+
/// Force URL to use HTTPS if possible to avoid App Transport Security errors
337+
private static func safeURL(_ url: String) -> String {
337338
guard let originalURL = URL(string: url),
338339
originalURL.scheme?.lowercased() == "http"
339340
else {
@@ -360,7 +361,7 @@ public extension Site {
360361
}
361362

362363
func toJetpackSite() -> JetpackSite {
363-
JetpackSite(siteID: siteID, siteAddress: jetpackCanonicalURL, applicationPasswordAvailable: applicationPasswordAvailable)
364+
JetpackSite(siteID: siteID, siteAddress: url, applicationPasswordAvailable: applicationPasswordAvailable)
364365
}
365366
}
366367

WooCommerce/Classes/Authentication/AuthenticatedWebViewController.swift

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -321,10 +321,6 @@ extension AuthenticatedWebViewController: WKNavigationDelegate {
321321
func webView(_ webView: WKWebView, didFailProvisionalNavigation navigation: WKNavigation!, withError error: Error) {
322322
viewModel.didFailProvisionalNavigation(with: error)
323323
activityIndicator.stopAnimating()
324-
// attempt reloading without authentication when provisioning fails
325-
if let url = viewModel.initialURL {
326-
webView.load(URLRequest(url: url))
327-
}
328324
}
329325
}
330326

0 commit comments

Comments
 (0)