@capacitor/ios 8.3.5-nightly-20260601T165419.0 → 8.3.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -103,6 +103,12 @@ open class CapacitorBridge: NSObject, CAPBridgeProtocol {
|
|
|
103
103
|
@available(*, deprecated, message: "`httpsInterceptorStartIdentifier` is no longer required. All proxied requests are handled via `httpInterceptorStartIdentifier` instead")
|
|
104
104
|
public static let httpsInterceptorStartIdentifier = "/_capacitor_https_interceptor_"
|
|
105
105
|
public static let httpInterceptorUrlParam = "u"
|
|
106
|
+
|
|
107
|
+
/// Whether `path` addresses one of the bridge's internal proxy routes (local files or the HTTP proxy).
|
|
108
|
+
/// These are served at the app's own origin, so they must never be loaded as a document.
|
|
109
|
+
public static func isInternalProxyPath(_ path: String) -> Bool {
|
|
110
|
+
return path.starts(with: fileStartIdentifier) || path.starts(with: httpInterceptorStartIdentifier)
|
|
111
|
+
}
|
|
106
112
|
public static let defaultScheme = "capacitor"
|
|
107
113
|
|
|
108
114
|
public private(set) var webViewAssetHandler: WebViewAssetHandler
|
|
@@ -217,6 +223,7 @@ open class CapacitorBridge: NSObject, CAPBridgeProtocol {
|
|
|
217
223
|
super.init()
|
|
218
224
|
|
|
219
225
|
self.webViewDelegationHandler.bridge = self
|
|
226
|
+
self.webViewAssetHandler.setConfiguration(configuration)
|
|
220
227
|
|
|
221
228
|
exportCoreJS(localUrl: configuration.localURL.absoluteString)
|
|
222
229
|
registerPlugins()
|
|
@@ -30,13 +30,6 @@ import Foundation
|
|
|
30
30
|
return defaultValue
|
|
31
31
|
}
|
|
32
32
|
|
|
33
|
-
@objc public func getDouble(_ configKey: String, _ defaultValue: Double) -> Double {
|
|
34
|
-
if let val = (self.config)[keyPath: KeyPath(configKey)] as? Double {
|
|
35
|
-
return val
|
|
36
|
-
}
|
|
37
|
-
return defaultValue
|
|
38
|
-
}
|
|
39
|
-
|
|
40
33
|
public func getArray(_ configKey: String, _ defaultValue: JSArray? = nil) -> JSArray? {
|
|
41
34
|
if let val = (self.config)[keyPath: KeyPath(configKey)] as? JSArray {
|
|
42
35
|
return val
|
|
@@ -6,6 +6,7 @@ import UniformTypeIdentifiers
|
|
|
6
6
|
open class WebViewAssetHandler: NSObject, WKURLSchemeHandler {
|
|
7
7
|
private var router: Router
|
|
8
8
|
private var serverUrl: URL?
|
|
9
|
+
private var configuration: InstanceConfiguration?
|
|
9
10
|
|
|
10
11
|
public init(router: Router) {
|
|
11
12
|
self.router = router
|
|
@@ -20,25 +21,33 @@ open class WebViewAssetHandler: NSObject, WKURLSchemeHandler {
|
|
|
20
21
|
self.serverUrl = serverUrl
|
|
21
22
|
}
|
|
22
23
|
|
|
24
|
+
open func setConfiguration(_ configuration: InstanceConfiguration?) {
|
|
25
|
+
self.configuration = configuration
|
|
26
|
+
}
|
|
27
|
+
|
|
23
28
|
private func isUsingLiveReload(_ localUrl: URL) -> Bool {
|
|
24
29
|
return self.serverUrl != nil && self.serverUrl?.scheme != localUrl.scheme
|
|
25
30
|
}
|
|
26
31
|
|
|
27
32
|
open func webView(_ webView: WKWebView, start urlSchemeTask: WKURLSchemeTask) {
|
|
28
|
-
let startPath: String
|
|
29
33
|
let url = urlSchemeTask.request.url!
|
|
30
34
|
let stringToLoad = url.path
|
|
31
35
|
let localUrl = URL.init(string: url.absoluteString)!
|
|
32
36
|
|
|
33
37
|
if url.path.starts(with: CapacitorBridge.httpInterceptorStartIdentifier) {
|
|
34
|
-
|
|
38
|
+
// Only serve the proxy when CapacitorHttp is on. A scheme task can't tell a document from
|
|
39
|
+
// a subresource, so keeping documents out relies on the check in decidePolicyFor.
|
|
40
|
+
if configuration?.getPluginConfig("CapacitorHttp").getBoolean("enabled", false) == true {
|
|
41
|
+
handleCapacitorHttpRequest(urlSchemeTask, localUrl, false)
|
|
42
|
+
} else {
|
|
43
|
+
urlSchemeTask.didFailWithError(URLError(.unsupportedURL))
|
|
44
|
+
}
|
|
35
45
|
return
|
|
36
46
|
}
|
|
37
47
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
startPath = router.route(for: stringToLoad)
|
|
48
|
+
guard let startPath = startPath(for: stringToLoad) else {
|
|
49
|
+
urlSchemeTask.didFailWithError(URLError(.fileDoesNotExist))
|
|
50
|
+
return
|
|
42
51
|
}
|
|
43
52
|
|
|
44
53
|
let fileUrl = URL.init(fileURLWithPath: startPath)
|
|
@@ -51,6 +60,8 @@ open class WebViewAssetHandler: NSObject, WKURLSchemeHandler {
|
|
|
51
60
|
"Cache-Control": "no-cache"
|
|
52
61
|
]
|
|
53
62
|
|
|
63
|
+
headers.merge(securityHeaders(forPath: stringToLoad)) { _, new in new }
|
|
64
|
+
|
|
54
65
|
// if using live reload, then set CORS headers
|
|
55
66
|
if isUsingLiveReload(localUrl) {
|
|
56
67
|
headers["Access-Control-Allow-Origin"] = self.serverUrl?.absoluteString
|
|
@@ -100,6 +111,27 @@ open class WebViewAssetHandler: NSObject, WKURLSchemeHandler {
|
|
|
100
111
|
urlSchemeTask.didFinish()
|
|
101
112
|
}
|
|
102
113
|
|
|
114
|
+
/// The file to serve for a request path, or nil if the path must not be served.
|
|
115
|
+
/// `URL.path` decodes `%2F`, so an encoded slash can carry `..` segments the web view did not
|
|
116
|
+
/// resolve. Joined to the base path they would leave it and serve any file the app can read.
|
|
117
|
+
private func startPath(for path: String) -> String? {
|
|
118
|
+
if path.starts(with: CapacitorBridge.fileStartIdentifier) {
|
|
119
|
+
return path.replacingOccurrences(of: CapacitorBridge.fileStartIdentifier, with: "")
|
|
120
|
+
}
|
|
121
|
+
if path.split(separator: "/").contains("..") {
|
|
122
|
+
return nil
|
|
123
|
+
}
|
|
124
|
+
return router.route(for: path)
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/// A proxied file that is ever rendered as a document must stay inert and unframeable.
|
|
128
|
+
private func securityHeaders(forPath path: String) -> [String: String] {
|
|
129
|
+
guard path.starts(with: CapacitorBridge.fileStartIdentifier) else {
|
|
130
|
+
return [:]
|
|
131
|
+
}
|
|
132
|
+
return ["Content-Security-Policy": "sandbox; frame-ancestors 'none'"]
|
|
133
|
+
}
|
|
134
|
+
|
|
103
135
|
open func webView(_ webView: WKWebView, stop urlSchemeTask: WKURLSchemeTask) {
|
|
104
136
|
urlSchemeTask.stopped = true
|
|
105
137
|
}
|
|
@@ -149,15 +181,19 @@ open class WebViewAssetHandler: NSObject, WKURLSchemeHandler {
|
|
|
149
181
|
}
|
|
150
182
|
|
|
151
183
|
if let response = response as? HTTPURLResponse {
|
|
152
|
-
|
|
184
|
+
// The target's CORS grant is not forwarded, so another origin cannot read the proxied response.
|
|
185
|
+
let existingHeaders = response.allHeaderFields.filter {
|
|
186
|
+
($0.key as? String)?.caseInsensitiveCompare("Access-Control-Allow-Origin") != .orderedSame
|
|
187
|
+
}
|
|
153
188
|
var newHeaders: [AnyHashable: Any] = [:]
|
|
154
189
|
|
|
190
|
+
// Nothing should render this. If anything does, sandbox keeps it inert.
|
|
191
|
+
newHeaders["Content-Security-Policy"] = "sandbox; frame-ancestors 'none'"
|
|
192
|
+
|
|
155
193
|
// if using live reload, then set CORS headers
|
|
156
194
|
if self.isUsingLiveReload(url) {
|
|
157
|
-
newHeaders =
|
|
158
|
-
|
|
159
|
-
"Access-Control-Allow-Methods": "GET, HEAD, OPTIONS, TRACE"
|
|
160
|
-
]
|
|
195
|
+
newHeaders["Access-Control-Allow-Origin"] = self.serverUrl?.absoluteString ?? ""
|
|
196
|
+
newHeaders["Access-Control-Allow-Methods"] = "GET, HEAD, OPTIONS, TRACE"
|
|
161
197
|
}
|
|
162
198
|
|
|
163
199
|
if let mergedHeaders = existingHeaders.merging(newHeaders, uniquingKeysWith: { (_, newHeaders) in newHeaders }) as? [String: String] {
|
|
@@ -74,6 +74,12 @@ open class WebViewDelegationHandler: NSObject, WKNavigationDelegate, WKUIDelegat
|
|
|
74
74
|
return
|
|
75
75
|
}
|
|
76
76
|
|
|
77
|
+
// The proxy routes return remote or local content at the app origin, so block them before plugins can allow it.
|
|
78
|
+
if CapacitorBridge.isInternalProxyPath(navURL.path) {
|
|
79
|
+
decisionHandler(.cancel)
|
|
80
|
+
return
|
|
81
|
+
}
|
|
82
|
+
|
|
77
83
|
// first, give plugins the chance to handle the decision
|
|
78
84
|
for pluginObject in bridge.plugins {
|
|
79
85
|
let plugin = pluginObject.value
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@capacitor/ios",
|
|
3
|
-
"version": "8.3.
|
|
3
|
+
"version": "8.3.6",
|
|
4
4
|
"description": "Capacitor: Cross-platform apps with JavaScript and the web",
|
|
5
5
|
"homepage": "https://capacitorjs.com",
|
|
6
6
|
"author": "Ionic Team <hi@ionic.io> (https://ionic.io)",
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
"xc:build:CapacitorCordova": "cd CapacitorCordova && xcodebuild && cd .."
|
|
26
26
|
},
|
|
27
27
|
"peerDependencies": {
|
|
28
|
-
"@capacitor/core": "^8.3.0
|
|
28
|
+
"@capacitor/core": "^8.3.0"
|
|
29
29
|
},
|
|
30
30
|
"publishConfig": {
|
|
31
31
|
"access": "public"
|