WebUIActivity WebView navigates itself for links outside the module UI

Aperta Adatta ai principianti
#1,697 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 4 giorni

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
84/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
android, kotlin
Ambito
mobile, security

Direzione di ricerca

Inizia da app/src/main/java/me/bmax/apatch/ui/WebUIActivity.kt e leggi la configurazione di WebViewClient, in particolare shouldInterceptRequest e doUpdateVisitedHistory. Aggiungi la gestione della navigazione di primo livello, in modo che l’origine degli asset del modulo rimanga in WebView e i link esterni si aprano tramite ACTION_VIEW; gestisci ActivityNotFoundException. Il lavoro è completato quando le pagine del modulo continuano a caricarsi internamente, i link esterni escono da WebView e i link non supportati non causano arresti anomali.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

enhancement
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:

  1. 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.
  2. The ksu object added with addJavascriptInterface(webViewInterface, "ksu") stays attached to the WebView, so the remote page can call ksu.exec(...) and ksu.spawn(...) just like the module's own page.
  3. 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.

Lingua principale
Kotlin
Stelle
8.2k
Fork
809
Merge medio
7g 17h
PR unite (30g)
1

Preparare l'ambiente

Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di bmax121/APatch

Tutte le issue di bmax121/APatch

Issue simili

Altre issue su Kotlin

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.