Repository navigation
chore: sync upstream PR #8593 - fix(cli): load default exports from JavaScript config #139
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
23ad7f8
b2d7719
76ff70e
b7e167b
de1e506
731a82e
bc74536
93c72de
e456de0
258867b
b4b297a
1d031a4
f1077ef
d4ad7ff
4c6c321
36b729d
41fd9de
28bb2c6
6048e90
7217b52
b789b68
6f2d328
1834b97
f368a1b
4c1c870
3fa04a3
984fa85
3ab4139
5e5bb3b
5ac4dd6
ee586ae
0c9e35d
08c3568
c567328
035b16a
e37d9c6
5e0f678
d140c7a
145560e
24c64b8
ba28569
06e3e19
eb06606
e2fb210
ebaba01
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,6 +10,7 @@ Pods/ | |
| Podfile.lock | ||
| Build/* | ||
| build/ | ||
| .build/ | ||
| Index/ | ||
| .*.sw* | ||
| android-template.iml | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| <?xml version="1.0" encoding="utf-8"?> | ||
| <manifest xmlns:android="http://schemas.android.com/apk/res/android"> | ||
|
|
||
| <application> | ||
| <activity | ||
| android:name="com.getcapacitor.android.TestHostActivity" | ||
| android:theme="@style/AppTheme.NoActionBar" | ||
| android:exported="false" /> | ||
| </application> | ||
| </manifest> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,115 @@ | ||
| package com.getcapacitor.android; | ||
|
|
||
| import static org.junit.Assert.assertFalse; | ||
| import static org.junit.Assert.assertNotNull; | ||
| import static org.junit.Assert.assertNull; | ||
| import static org.junit.Assert.assertTrue; | ||
|
|
||
| import android.net.Uri; | ||
| import android.webkit.WebResourceRequest; | ||
| import androidx.test.core.app.ActivityScenario; | ||
| import androidx.test.ext.junit.runners.AndroidJUnit4; | ||
| import com.getcapacitor.Bridge; | ||
| import java.util.HashMap; | ||
| import java.util.Map; | ||
| import org.junit.Test; | ||
| import org.junit.runner.RunWith; | ||
|
|
||
| /** | ||
| * The proxy path shares the app's host and scheme, so the host/scheme guard alone would let it | ||
| * load in the WebView. | ||
| */ | ||
| @RunWith(AndroidJUnit4.class) | ||
| public class HttpInterceptorNavigationTest { | ||
|
|
||
| private static final String INTERCEPTOR_URL = | ||
| "https://localhost" + Bridge.CAPACITOR_HTTP_INTERCEPTOR_START + "?u=https://example.com/payload.html"; | ||
| private static final String IN_APP_URL = "https://localhost/index.html"; | ||
| private static final String EXTERNAL_URL = "https://example.com/"; | ||
|
|
||
| /** A plugin registered by the test host returns "allow" for the proxy path; it must not win. */ | ||
| @Test | ||
| public void blocksNavigationToInterceptorPath() { | ||
| try (ActivityScenario<TestHostActivity> scenario = ActivityScenario.launch(TestHostActivity.class)) { | ||
| scenario.onActivity((activity) -> { | ||
| Bridge bridge = activity.getBridge(); | ||
| assertNotNull(bridge); | ||
| assertTrue("interceptor navigation must be blocked", bridge.launchIntent(Uri.parse(INTERCEPTOR_URL))); | ||
| assertFalse("in-app navigation must stay in the WebView", bridge.launchIntent(Uri.parse(IN_APP_URL))); | ||
| assertTrue("external navigation must leave the WebView", bridge.launchIntent(Uri.parse(EXTERNAL_URL))); | ||
| }); | ||
| } | ||
| } | ||
|
|
||
| /** An iframe looks like a fetch to isForMainFrame(), so subframe documents must be refused too. */ | ||
| @Test | ||
| public void refusesProxyForDocumentRequests() { | ||
| try (ActivityScenario<TestHostActivity> scenario = ActivityScenario.launch(TestHostActivity.class)) { | ||
| scenario.onActivity((activity) -> { | ||
| Bridge bridge = activity.getBridge(); | ||
| assertNotNull(bridge); | ||
| // Without this the proxy refuses everything and the assertions below prove nothing. | ||
| assertTrue( | ||
| "CapacitorHttp must be enabled for this test to mean anything", | ||
| bridge.getConfig().getPluginConfiguration("CapacitorHttp").getBoolean("enabled", false) | ||
| ); | ||
|
|
||
| Map<String, String> navHeaders = new HashMap<>(); | ||
| navHeaders.put("Accept", "text/html,application/xhtml+xml"); | ||
| navHeaders.put("Upgrade-Insecure-Requests", "1"); | ||
|
|
||
| assertNull( | ||
| "main frame document must be refused", | ||
| bridge.getLocalServer().shouldInterceptRequest(new FakeRequest(INTERCEPTOR_URL, true, navHeaders)) | ||
| ); | ||
| assertNull( | ||
| "iframe document must be refused", | ||
| bridge.getLocalServer().shouldInterceptRequest(new FakeRequest(INTERCEPTOR_URL, false, navHeaders)) | ||
| ); | ||
| }); | ||
| } | ||
| } | ||
|
|
||
| private static class FakeRequest implements WebResourceRequest { | ||
|
|
||
| private final Uri url; | ||
| private final boolean mainFrame; | ||
| private final Map<String, String> headers; | ||
|
|
||
| FakeRequest(String url, boolean mainFrame, Map<String, String> headers) { | ||
| this.url = Uri.parse(url); | ||
| this.mainFrame = mainFrame; | ||
| this.headers = headers; | ||
| } | ||
|
|
||
| @Override | ||
| public Uri getUrl() { | ||
| return url; | ||
| } | ||
|
|
||
| @Override | ||
| public boolean isForMainFrame() { | ||
| return mainFrame; | ||
| } | ||
|
|
||
| @Override | ||
| public boolean isRedirect() { | ||
| return false; | ||
| } | ||
|
|
||
| @Override | ||
| public boolean hasGesture() { | ||
| return false; | ||
| } | ||
|
|
||
| @Override | ||
| public String getMethod() { | ||
| return "GET"; | ||
| } | ||
|
|
||
| @Override | ||
| public Map<String, String> getRequestHeaders() { | ||
| return headers; | ||
| } | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| package com.getcapacitor.android; | ||
|
|
||
| import android.net.Uri; | ||
| import com.getcapacitor.Bridge; | ||
| import com.getcapacitor.Plugin; | ||
| import com.getcapacitor.annotation.CapacitorPlugin; | ||
|
|
||
| /** A plugin that tries to allow the proxy path. The navigation guard must ignore it. */ | ||
| @CapacitorPlugin(name = "InterceptorAllowingPlugin") | ||
| public class InterceptorAllowingPlugin extends Plugin { | ||
|
|
||
| @Override | ||
| public Boolean shouldOverrideLoad(Uri url) { | ||
| String path = url.getPath(); | ||
| if (path != null && path.startsWith(Bridge.CAPACITOR_HTTP_INTERCEPTOR_START)) { | ||
| return false; // "allow this navigation" | ||
| } | ||
| return null; | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| package com.getcapacitor.android; | ||
|
|
||
| import com.getcapacitor.BridgeActivity; | ||
| import com.getcapacitor.CapConfig; | ||
| import org.json.JSONException; | ||
| import org.json.JSONObject; | ||
|
|
||
| /** | ||
| * Host for instrumented tests. CapacitorHttp is on so the proxy is reachable, and a plugin that | ||
| * tries to allow the proxy path is registered so tests can prove the guard still wins. | ||
| */ | ||
| public class TestHostActivity extends BridgeActivity { | ||
|
|
||
| @Override | ||
| protected void load() { | ||
| registerPlugin(InterceptorAllowingPlugin.class); | ||
|
|
||
| try { | ||
| JSONObject plugins = new JSONObject("{\"CapacitorHttp\":{\"enabled\":true}}"); | ||
| config = new CapConfig.Builder(this).setPluginsConfiguration(plugins).create(); | ||
| } catch (JSONException e) { | ||
| throw new IllegalStateException("bad test plugin config", e); | ||
| } | ||
|
|
||
| super.load(); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change | ||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -394,6 +394,12 @@ private int extractWebViewMajorVersion(final PackageManager pm, final String web | |||||||||||||||
| } | ||||||||||||||||
|
|
||||||||||||||||
| public boolean launchIntent(Uri url) { | ||||||||||||||||
| // The proxy returns a remote body at the app origin, so block it before plugins can allow it. | ||||||||||||||||
| String path = url.getPath(); | ||||||||||||||||
| if (path != null && path.startsWith(CAPACITOR_HTTP_INTERCEPTOR_START)) { | ||||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P2: When an external or configured allowed URL has a path beginning with Prompt for AI agents
Suggested change
|
||||||||||||||||
| return true; | ||||||||||||||||
| } | ||||||||||||||||
|
|
||||||||||||||||
| /* | ||||||||||||||||
| * Give plugins the chance to handle the url | ||||||||||||||||
| */ | ||||||||||||||||
|
|
@@ -1262,6 +1268,10 @@ protected Map<String, PermissionState> getPermissionStates(Plugin plugin) { | |||||||||||||||
| } | ||||||||||||||||
| } | ||||||||||||||||
| } | ||||||||||||||||
| } else { | ||||||||||||||||
| Logger.warn( | ||||||||||||||||
| String.format("getPermissionStates: missing @CapacitorPlugin annotation for plugin %s", plugin.getPluginHandle().getId()) | ||||||||||||||||
| ); | ||||||||||||||||
| } | ||||||||||||||||
|
|
||||||||||||||||
| return permissionsResults; | ||||||||||||||||
|
|
||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -412,12 +412,6 @@ private boolean showImageCapturePicker(final ValueCallback<Uri[]> filePathCallba | |
| } | ||
| takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, imageFileUri); | ||
| takePictureIntent.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION | Intent.FLAG_GRANT_READ_URI_PERMISSION); | ||
|
|
||
| // Store in static variables to survive activity recreation | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P1: Removing the static pending state in showImageCapturePicker breaks camera file selection when the Activity is recreated mid-capture. handlePendingFileChooserResult still branches on FileChooserType.IMAGE_CAPTURE and pendingImageFileUri, but with these statics no longer set, the recreation path (activityListener == null, pendingFilePathCallback == null) drops the result and the web file-input callback never fires, leaving the picker hanging. VIDEO_CAPTURE and FILE_PICKER still set the same statics, so IMAGE_CAPTURE is now inconsistent. Restore the stored state (or add a dedicated recreation path for image capture) so captured images are delivered after recreation. Prompt for AI agents |
||
| pendingFilePathCallback = filePathCallback; | ||
| pendingImageFileUri = imageFileUri; | ||
| pendingFileChooserType = FileChooserType.IMAGE_CAPTURE; | ||
|
|
||
| activityListener = (activityResult) -> { | ||
| Uri[] result = null; | ||
| if (activityResult.getResultCode() == Activity.RESULT_OK) { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
P2: This PR raises
timeout-minutesfrom 10 to 30 in every CI job, which contradicts the documented convention in AGENTS.md: 'Timeouts ≤10 min:timeout-minutes: 10or less in CI'. A hung job now burns 30 minutes of macOS/Ubuntu runner time before being killed, and the change is unrelated to the PR's stated purpose (loading default exports from JS config). Revert totimeout-minutes: 10unless there is a concrete need.Prompt for AI agents