WebUIActivity WebView navigates itself for links outside the module UI
Maintainers usually reply within 4 days
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 84/100
Research direction
Start in app/src/main/java/me/bmax/apatch/ui/WebUIActivity.kt and read the WebViewClient setup, especially shouldInterceptRequest and doUpdateVisitedHistory. Add top-level navigation handling so the module asset origin stays in the WebView and external links open through ACTION_VIEW, handling ActivityNotFoundException. Done when module pages still load internally, external links leave the WebView, and unsupported links do not crash.
Written by the indexing model from the issue text.
Description
Is your request related to a specific issue? | 你的请求是否与某个问题相关?
While reading through WebUIActivity (app/src/main/java/me/bmax/apatch/ui/WebUIActivity.kt) I noticed that the module WebView has no say over where it navigates. The module's webroot is served through a WebViewAssetLoader on https://mui.kernelsu.org/, and the WebViewClient overrides shouldInterceptRequest and doUpdateVisitedHistory, but not shouldOverrideUrlLoading:
val webViewClient = object : WebViewClient() {
override fun shouldInterceptRequest(
view: WebView,
request: WebResourceRequest
): WebResourceResponse? {
...
return webViewAssetLoader.shouldInterceptRequest(url)
}
override fun doUpdateVisitedHistory(view: WebView?, url: String?, isReload: Boolean) {
webCanGoBack = view?.canGoBack() == true
super.doUpdateVisitedHistory(view, url, isReload)
}
}
The asset loader only answers for mui.kernelsu.org. For any other host it returns null, so the WebView fetches the page from the network. When a module page contains an ordinary link to another site (project page, docs, donation link) and the user taps it, the WebView navigates itself to that site:
- The remote page is shown inside the module screen. There is no address bar, so the user cannot tell they have left the module UI.
- The
ksuobject added withaddJavascriptInterface(webViewInterface, "ksu")stays attached to the WebView, so the remote page can callksu.exec(...)andksu.spawn(...)just like the module's own page. - Non http(s) links (
mailto:,tel:,intent:) are not handed to another app. The WebView tries to load them itself and fails.
The second point is the one that matters. A module author is trusted, but a site the module happens to link to is not, and an http:// link can be modified in transit.
Describe the solution you'd like | 描述你想要的解决方案
Override shouldOverrideUrlLoading so only the asset loader origin stays in the WebView and every other top level navigation is sent out via Intent.ACTION_VIEW, wrapped in a try/catch for ActivityNotFoundException:
override fun shouldOverrideUrlLoading(view: WebView, request: WebResourceRequest): Boolean {
if (!request.isForMainFrame) return false
val url = request.url
if (url.scheme == "https" && url.host == "mui.kernelsu.org") return false
try {
startActivity(Intent(Intent.ACTION_VIEW, url))
} catch (_: ActivityNotFoundException) {
}
return true
}
Intent and ActivityNotFoundException are already imported in this file. Module pages keep working as before, and outside links open in the browser, where the ksu bridge does not exist.
Describe the alternatives you've considered | 描述您考虑过的备选方案
I didn't consider any other alternatives
Other information | 其他信息
The same kind of gap was fixed in Nextcloud Notes in nextcloud/notes-android#3192, where the editor WebView now keeps links to its own server and sends everything else out.
- Dominant language
- Kotlin
- Stars
- 8.2k
- Forks
- 809
- Avg merge
- 7d 17h
- Merged PRs (30d)
- 1
Getting set up
This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from bmax121/APatch
-
bug
Difficulty 1/5 Under an hour Newbie friendliness 85/100
bmax121/APatch#1669 · 2 comments ·
Maintainers usually reply within 4 days
-
Direct Install reports success when boot partition write failsMay be free again A pull request for this issue was closed without being merged. Open
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
Maintainers usually reply within 4 days
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Maintainers usually reply within 4 days
-
boot_patch.sh: flash guard precedence allows flash attempt on missing new-boot.imgMay be free again A pull request for this issue was closed without being merged. Open
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
Maintainers usually reply within 4 days
-
HeloOpenbug
Difficulty 1/5 Under an hour Newbie friendliness 5/100
Maintainers usually reply within 4 days
Similar issues
-
enhancement good first issue help wanted
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
getsotto/sotto-authenticator#68 ·
Maintainers usually reply within 1 day
-
mobile prio:low
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
digitalfabrik/entitlementcard#3324 ·
Maintainers usually reply within 2 days
-
Contributions are welcome Type:bug
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
owncloud/android#5065 · 1 comment ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
sameerasw/essentials#1913 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 79/100
micronaut-projects/micronaut-core#14585 ·
Maintainers usually reply within 1 day