@capacitor/android 7.6.8 → 7.6.10

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.
@@ -391,6 +391,12 @@ public class Bridge {
391
391
  }
392
392
 
393
393
  public boolean launchIntent(Uri url) {
394
+ // The proxy returns a remote body at the app origin, so block it before plugins can allow it.
395
+ String path = url.getPath();
396
+ if (path != null && path.startsWith(CAPACITOR_HTTP_INTERCEPTOR_START)) {
397
+ return true;
398
+ }
399
+
394
400
  /*
395
401
  * Give plugins the chance to handle the url
396
402
  */
@@ -282,7 +282,7 @@ public class BridgeWebChromeClient extends WebChromeClient {
282
282
  boolean captureEnabled = fileChooserParams.isCaptureEnabled();
283
283
  boolean capturePhoto = captureEnabled && acceptTypes.contains("image/*");
284
284
  final boolean captureVideo = captureEnabled && acceptTypes.contains("video/*");
285
- if ((capturePhoto || captureVideo)) {
285
+ if (capturePhoto || captureVideo) {
286
286
  if (isMediaCaptureSupported()) {
287
287
  showMediaCaptureOrFilePicker(filePathCallback, fileChooserParams, captureVideo);
288
288
  } else {
@@ -455,7 +455,7 @@ public class BridgeWebChromeClient extends WebChromeClient {
455
455
  public boolean isValidMsg(String msg) {
456
456
  return !(
457
457
  msg.contains("%cresult %c") ||
458
- (msg.contains("%cnative %c")) ||
458
+ msg.contains("%cnative %c") ||
459
459
  msg.equalsIgnoreCase("[object Object]") ||
460
460
  msg.equalsIgnoreCase("console.groupEnd")
461
461
  );
@@ -218,7 +218,7 @@ public class FileUtils {
218
218
  Cursor cursor = context.getContentResolver().query(uri, null, null, null, null);
219
219
  int nameIndex = cursor.getColumnIndex(OpenableColumns.DISPLAY_NAME);
220
220
  cursor.moveToFirst();
221
- String name = (cursor.getString(nameIndex));
221
+ String name = cursor.getString(nameIndex);
222
222
  String fileName = sanitizeFilename(name);
223
223
  File file = new File(context.getFilesDir(), fileName);
224
224
  try {
@@ -1003,7 +1003,8 @@ public class Plugin {
1003
1003
  * Give the plugins a chance to take control when a URL is about to be loaded in the WebView.
1004
1004
  * Returning true causes the WebView to abort loading the URL.
1005
1005
  * Returning false causes the WebView to continue loading the URL.
1006
- * Returning null will defer to the default Capacitor policy
1006
+ * Returning null will defer to the default Capacitor policy.
1007
+ * Not called for Capacitor's internal HTTP proxy path, which is always blocked.
1007
1008
  */
1008
1009
  @SuppressWarnings("unused")
1009
1010
  public Boolean shouldOverrideLoad(Uri url) {
@@ -185,6 +185,11 @@ public class WebViewLocalServer {
185
185
  Uri loadingUrl = request.getUrl();
186
186
 
187
187
  if (null != loadingUrl.getPath() && loadingUrl.getPath().startsWith(Bridge.CAPACITOR_HTTP_INTERCEPTOR_START)) {
188
+ // Only fetch/XHR should reach the proxy; a document would run remote content at the app origin.
189
+ boolean httpEnabled = bridge.getConfig().getPluginConfiguration("CapacitorHttp").getBoolean("enabled", false);
190
+ if (!httpEnabled || isDocumentRequest(request)) {
191
+ return null;
192
+ }
188
193
  Logger.debug("Handling CapacitorHttp request: " + loadingUrl);
189
194
  try {
190
195
  return handleCapacitorHttpRequest(request);
@@ -210,6 +215,24 @@ public class WebViewLocalServer {
210
215
  }
211
216
  }
212
217
 
218
+ /** isForMainFrame() is false for an iframe and a fetch alike; only navigations send this header. */
219
+ private boolean isDocumentRequest(WebResourceRequest request) {
220
+ if (request.isForMainFrame()) {
221
+ return true;
222
+ }
223
+ Map<String, String> headers = request.getRequestHeaders();
224
+ if (headers == null) {
225
+ // The proxy needs the headers too, so the request fails there anyway.
226
+ return false;
227
+ }
228
+ for (String header : headers.keySet()) {
229
+ if ("Upgrade-Insecure-Requests".equalsIgnoreCase(header)) {
230
+ return true;
231
+ }
232
+ }
233
+ return false;
234
+ }
235
+
213
236
  private boolean isLocalFile(Uri uri) {
214
237
  String path = uri.getPath();
215
238
  return path.startsWith(capacitorContentStart) || path.startsWith(capacitorFileStart);
@@ -221,7 +244,7 @@ public class WebViewLocalServer {
221
244
  }
222
245
 
223
246
  private boolean isMainUrl(Uri loadingUrl) {
224
- return (bridge.getServerUrl() == null && loadingUrl.getHost().equalsIgnoreCase(bridge.getHost()));
247
+ return bridge.getServerUrl() == null && loadingUrl.getHost().equalsIgnoreCase(bridge.getHost());
225
248
  }
226
249
 
227
250
  private boolean isAllowedUrl(Uri loadingUrl) {
@@ -333,6 +356,9 @@ public class WebViewLocalServer {
333
356
  int responseCode = connection.getResponseCode();
334
357
  String reasonPhrase = getReasonPhraseFromResponseCode(responseCode);
335
358
 
359
+ // Nothing should render this. If anything does, sandbox keeps it inert and off the app origin.
360
+ responseHeaders.put("Content-Security-Policy", "sandbox; frame-ancestors 'none'");
361
+
336
362
  return new WebResourceResponse(mimeType, encoding, responseCode, reasonPhrase, responseHeaders, inputStream);
337
363
  }
338
364
 
@@ -722,31 +748,31 @@ public class WebViewLocalServer {
722
748
  @Override
723
749
  public int available() throws IOException {
724
750
  InputStream is = getInputStream();
725
- return (is != null) ? is.available() : -1;
751
+ return is != null ? is.available() : -1;
726
752
  }
727
753
 
728
754
  @Override
729
755
  public int read() throws IOException {
730
756
  InputStream is = getInputStream();
731
- return (is != null) ? is.read() : -1;
757
+ return is != null ? is.read() : -1;
732
758
  }
733
759
 
734
760
  @Override
735
761
  public int read(byte[] b) throws IOException {
736
762
  InputStream is = getInputStream();
737
- return (is != null) ? is.read(b) : -1;
763
+ return is != null ? is.read(b) : -1;
738
764
  }
739
765
 
740
766
  @Override
741
767
  public int read(byte[] b, int off, int len) throws IOException {
742
768
  InputStream is = getInputStream();
743
- return (is != null) ? is.read(b, off, len) : -1;
769
+ return is != null ? is.read(b, off, len) : -1;
744
770
  }
745
771
 
746
772
  @Override
747
773
  public long skip(long n) throws IOException {
748
774
  InputStream is = getInputStream();
749
- return (is != null) ? is.skip(n) : 0;
775
+ return is != null ? is.skip(n) : 0;
750
776
  }
751
777
  }
752
778
 
@@ -192,12 +192,12 @@ public class CapacitorCookieManager extends CookieManager {
192
192
  @Override
193
193
  public void put(URI uri, Map<String, List<String>> responseHeaders) {
194
194
  // make sure our args are valid
195
- if ((uri == null) || (responseHeaders == null)) return;
195
+ if (uri == null || responseHeaders == null) return;
196
196
 
197
197
  // go over the headers
198
198
  for (String headerKey : responseHeaders.keySet()) {
199
199
  // ignore headers which aren't cookie related
200
- if ((headerKey == null) || !(headerKey.equalsIgnoreCase("Set-Cookie2") || headerKey.equalsIgnoreCase("Set-Cookie"))) continue;
200
+ if (headerKey == null || !(headerKey.equalsIgnoreCase("Set-Cookie2") || headerKey.equalsIgnoreCase("Set-Cookie"))) continue;
201
201
 
202
202
  // process each of the headers
203
203
  for (String headerValue : Objects.requireNonNull(responseHeaders.get(headerKey))) {
@@ -215,7 +215,7 @@ public class CapacitorCookieManager extends CookieManager {
215
215
  @Override
216
216
  public Map<String, List<String>> get(URI uri, Map<String, List<String>> requestHeaders) {
217
217
  // make sure our args are valid
218
- if ((uri == null) || (requestHeaders == null)) throw new IllegalArgumentException("Argument is null");
218
+ if (uri == null || requestHeaders == null) throw new IllegalArgumentException("Argument is null");
219
219
 
220
220
  // save our url once
221
221
  String url = uri.toString();
@@ -168,8 +168,8 @@ public class HttpRequestHandler {
168
168
  "://" +
169
169
  uri.getAuthority() +
170
170
  uri.getPath() +
171
- ((!urlQuery.equals("")) ? "?" + urlQuery : "") +
172
- ((uri.getFragment() != null) ? uri.getFragment() : "");
171
+ (!urlQuery.equals("") ? "?" + urlQuery : "") +
172
+ (uri.getFragment() != null ? uri.getFragment() : "");
173
173
  this.url = new URL(unEncodedUrlString);
174
174
 
175
175
  return this;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@capacitor/android",
3
- "version": "7.6.8",
3
+ "version": "7.6.10",
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)",