@capacitor/ios 7.6.7 → 7.6.9

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.
@@ -216,6 +216,7 @@ open class CapacitorBridge: NSObject, CAPBridgeProtocol {
216
216
  super.init()
217
217
 
218
218
  self.webViewDelegationHandler.bridge = self
219
+ self.webViewAssetHandler.setConfiguration(configuration)
219
220
 
220
221
  exportCoreJS(localUrl: configuration.localURL.absoluteString)
221
222
  registerPlugins()
@@ -6,6 +6,7 @@ import MobileCoreServices
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,6 +21,10 @@ 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
  }
@@ -31,7 +36,13 @@ open class WebViewAssetHandler: NSObject, WKURLSchemeHandler {
31
36
  let localUrl = URL.init(string: url.absoluteString)!
32
37
 
33
38
  if url.path.starts(with: CapacitorBridge.httpInterceptorStartIdentifier) {
34
- handleCapacitorHttpRequest(urlSchemeTask, localUrl, false)
39
+ // Only serve the proxy when CapacitorHttp is on. A scheme task can't tell a document from
40
+ // a subresource, so keeping documents out relies on the check in decidePolicyFor.
41
+ if configuration?.getPluginConfig("CapacitorHttp").getBoolean("enabled", false) == true {
42
+ handleCapacitorHttpRequest(urlSchemeTask, localUrl, false)
43
+ } else {
44
+ urlSchemeTask.didFailWithError(URLError(.unsupportedURL))
45
+ }
35
46
  return
36
47
  }
37
48
 
@@ -152,12 +163,13 @@ open class WebViewAssetHandler: NSObject, WKURLSchemeHandler {
152
163
  let existingHeaders = response.allHeaderFields
153
164
  var newHeaders: [AnyHashable: Any] = [:]
154
165
 
166
+ // Nothing should render this. If anything does, sandbox keeps it inert.
167
+ newHeaders["Content-Security-Policy"] = "sandbox; frame-ancestors 'none'"
168
+
155
169
  // if using live reload, then set CORS headers
156
170
  if self.isUsingLiveReload(url) {
157
- newHeaders = [
158
- "Access-Control-Allow-Origin": self.serverUrl?.absoluteString ?? "",
159
- "Access-Control-Allow-Methods": "GET, HEAD, OPTIONS, TRACE"
160
- ]
171
+ newHeaders["Access-Control-Allow-Origin"] = self.serverUrl?.absoluteString ?? ""
172
+ newHeaders["Access-Control-Allow-Methods"] = "GET, HEAD, OPTIONS, TRACE"
161
173
  }
162
174
 
163
175
  if let mergedHeaders = existingHeaders.merging(newHeaders, uniquingKeysWith: { (_, newHeaders) in newHeaders }) as? [String: String] {
@@ -76,6 +76,12 @@ open class WebViewDelegationHandler: NSObject, WKNavigationDelegate, WKUIDelegat
76
76
  return
77
77
  }
78
78
 
79
+ // The proxy returns a remote body at the app origin, so block it before plugins can allow it.
80
+ if navURL.path.starts(with: CapacitorBridge.httpInterceptorStartIdentifier) {
81
+ decisionHandler(.cancel)
82
+ return
83
+ }
84
+
79
85
  // first, give plugins the chance to handle the decision
80
86
  for pluginObject in bridge.plugins {
81
87
  let plugin = pluginObject.value
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@capacitor/ios",
3
- "version": "7.6.7",
3
+ "version": "7.6.9",
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)",