@capacitor/ios 8.3.5 → 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
|
|
@@ -30,7 +30,6 @@ open class WebViewAssetHandler: NSObject, WKURLSchemeHandler {
|
|
|
30
30
|
}
|
|
31
31
|
|
|
32
32
|
open func webView(_ webView: WKWebView, start urlSchemeTask: WKURLSchemeTask) {
|
|
33
|
-
let startPath: String
|
|
34
33
|
let url = urlSchemeTask.request.url!
|
|
35
34
|
let stringToLoad = url.path
|
|
36
35
|
let localUrl = URL.init(string: url.absoluteString)!
|
|
@@ -46,10 +45,9 @@ open class WebViewAssetHandler: NSObject, WKURLSchemeHandler {
|
|
|
46
45
|
return
|
|
47
46
|
}
|
|
48
47
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
startPath = router.route(for: stringToLoad)
|
|
48
|
+
guard let startPath = startPath(for: stringToLoad) else {
|
|
49
|
+
urlSchemeTask.didFailWithError(URLError(.fileDoesNotExist))
|
|
50
|
+
return
|
|
53
51
|
}
|
|
54
52
|
|
|
55
53
|
let fileUrl = URL.init(fileURLWithPath: startPath)
|
|
@@ -62,6 +60,8 @@ open class WebViewAssetHandler: NSObject, WKURLSchemeHandler {
|
|
|
62
60
|
"Cache-Control": "no-cache"
|
|
63
61
|
]
|
|
64
62
|
|
|
63
|
+
headers.merge(securityHeaders(forPath: stringToLoad)) { _, new in new }
|
|
64
|
+
|
|
65
65
|
// if using live reload, then set CORS headers
|
|
66
66
|
if isUsingLiveReload(localUrl) {
|
|
67
67
|
headers["Access-Control-Allow-Origin"] = self.serverUrl?.absoluteString
|
|
@@ -111,6 +111,27 @@ open class WebViewAssetHandler: NSObject, WKURLSchemeHandler {
|
|
|
111
111
|
urlSchemeTask.didFinish()
|
|
112
112
|
}
|
|
113
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
|
+
|
|
114
135
|
open func webView(_ webView: WKWebView, stop urlSchemeTask: WKURLSchemeTask) {
|
|
115
136
|
urlSchemeTask.stopped = true
|
|
116
137
|
}
|
|
@@ -160,7 +181,10 @@ open class WebViewAssetHandler: NSObject, WKURLSchemeHandler {
|
|
|
160
181
|
}
|
|
161
182
|
|
|
162
183
|
if let response = response as? HTTPURLResponse {
|
|
163
|
-
|
|
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
|
+
}
|
|
164
188
|
var newHeaders: [AnyHashable: Any] = [:]
|
|
165
189
|
|
|
166
190
|
// Nothing should render this. If anything does, sandbox keeps it inert.
|
|
@@ -74,8 +74,8 @@ open class WebViewDelegationHandler: NSObject, WKNavigationDelegate, WKUIDelegat
|
|
|
74
74
|
return
|
|
75
75
|
}
|
|
76
76
|
|
|
77
|
-
// The proxy
|
|
78
|
-
if navURL.path
|
|
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
79
|
decisionHandler(.cancel)
|
|
80
80
|
return
|
|
81
81
|
}
|
package/package.json
CHANGED