@capacitor/ios 6.2.0 → 6.2.2

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.
@@ -210,6 +210,7 @@ open class CapacitorBridge: NSObject, CAPBridgeProtocol {
210
210
  super.init()
211
211
 
212
212
  self.webViewDelegationHandler.bridge = self
213
+ self.webViewAssetHandler.setConfiguration(configuration)
213
214
 
214
215
  exportCoreJS(localUrl: configuration.localURL.absoluteString)
215
216
  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
 
@@ -58,8 +69,7 @@ open class WebViewAssetHandler: NSObject, WKURLSchemeHandler {
58
69
  }
59
70
 
60
71
  if let rangeString = urlSchemeTask.request.value(forHTTPHeaderField: "Range"),
61
- let totalSize = try fileUrl.resourceValues(forKeys: [.fileSizeKey]).fileSize,
62
- isMediaExtension(pathExtension: url.pathExtension) {
72
+ let totalSize = try fileUrl.resourceValues(forKeys: [.fileSizeKey]).fileSize {
63
73
  let fileHandle = try FileHandle(forReadingFrom: fileUrl)
64
74
  let parts = rangeString.components(separatedBy: "=")
65
75
  let streamParts = parts[1].components(separatedBy: "-")
@@ -153,12 +163,13 @@ open class WebViewAssetHandler: NSObject, WKURLSchemeHandler {
153
163
  let existingHeaders = response.allHeaderFields
154
164
  var newHeaders: [AnyHashable: Any] = [:]
155
165
 
166
+ // Nothing should render this. If anything does, sandbox keeps it inert.
167
+ newHeaders["Content-Security-Policy"] = "sandbox; frame-ancestors 'none'"
168
+
156
169
  // if using live reload, then set CORS headers
157
170
  if self.isUsingLiveReload(url) {
158
- newHeaders = [
159
- "Access-Control-Allow-Origin": self.serverUrl?.absoluteString ?? "",
160
- "Access-Control-Allow-Methods": "GET, HEAD, OPTIONS, TRACE"
161
- ]
171
+ newHeaders["Access-Control-Allow-Origin"] = self.serverUrl?.absoluteString ?? ""
172
+ newHeaders["Access-Control-Allow-Methods"] = "GET, HEAD, OPTIONS, TRACE"
162
173
  }
163
174
 
164
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
@@ -497,6 +497,15 @@ var nativeBridge = (function (exports) {
497
497
  if (doPatchHttp) {
498
498
  // fetch patch
499
499
  window.fetch = async (resource, options) => {
500
+ const headers = new Headers(options === null || options === void 0 ? void 0 : options.headers);
501
+ const contentType = headers.get('Content-Type') || headers.get('content-type');
502
+ if ((options === null || options === void 0 ? void 0 : options.body) instanceof FormData &&
503
+ (contentType === null || contentType === void 0 ? void 0 : contentType.includes('multipart/form-data')) &&
504
+ !contentType.includes('boundary')) {
505
+ headers.delete('Content-Type');
506
+ headers.delete('content-type');
507
+ options.headers = headers;
508
+ }
500
509
  const request = new Request(resource, options);
501
510
  if (request.url.startsWith(`${cap.getServerUrl()}/`)) {
502
511
  return win.CapacitorWebFetch(resource, options);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@capacitor/ios",
3
- "version": "6.2.0",
3
+ "version": "6.2.2",
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)",