@capacitor/android 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.
@@ -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
  */
@@ -345,6 +345,7 @@ public class BridgeWebChromeClient extends WebChromeClient {
345
345
  return false;
346
346
  }
347
347
  takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, imageFileUri);
348
+ takePictureIntent.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION | Intent.FLAG_GRANT_READ_URI_PERMISSION);
348
349
  activityListener = (activityResult) -> {
349
350
  Uri[] result = null;
350
351
  if (activityResult.getResultCode() == Activity.RESULT_OK) {
@@ -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);
@@ -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
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@capacitor/android",
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)",