Skip to content

Disable setAllowFileAccess in WebViewActivity#390

Open
jim-daf wants to merge 1 commit into
devgianlu:masterfrom
jim-daf:fix-webview-file-access
Open

Disable setAllowFileAccess in WebViewActivity#390
jim-daf wants to merge 1 commit into
devgianlu:masterfrom
jim-daf:fix-webview-file-access

Conversation

@jim-daf
Copy link
Copy Markdown

@jim-daf jim-daf commented May 13, 2026

Closes #389.

WebViewActivity hosts the in-app browser used to find downloadable links and hand them off to aria2. setAllowFileAccess(true) is on while every request the WebView makes is routed through shouldInterceptRequest:

public WebResourceResponse shouldInterceptRequest(WebView view, WebResourceRequest request) {
    Request req = buildRequest(request);
    if (req == null) return null;
    ...
}

private static Request buildRequest(@NonNull WebResourceRequest req) {
    ...
    HttpUrl url = HttpUrl.parse(req.getUrl().toString());
    if (url == null)
        return null;
    ...
}

OkHttp.HttpUrl.parse only accepts http and https. file:// URIs cause it to return null, buildRequest returns null, and the OkHttp routing silently drops them. The browser is for web download links, so file:// is not a supported user flow.

Change

Flip setAllowFileAccess(true) to setAllowFileAccess(false) so the WebView and the OkHttp interceptor agree on the same scheme allow-list. file:///android_asset/* remains available on every supported Android version regardless of the flag.

One-line semantic change. No other WebView setting touched.

WebViewActivity hosts the in-app browser that lets the user surf to
download links and hand them off to aria2. setAllowFileAccess(true)
was on, even though every request from the WebView is routed through
the WebViewClient.shouldInterceptRequest below, which builds an
OkHttpClient request via HttpUrl.parse:

    private static Request buildRequest(@nonnull WebResourceRequest req) {
        ...
        HttpUrl url = HttpUrl.parse(req.getUrl().toString());
        if (url == null)
            return null;
        ...
    }

OkHttp only accepts http and https. HttpUrl.parse returns null for
file:// URIs, so the existing interception path silently drops them
on the OkHttp side. With setAllowFileAccess(false), WebView itself
also refuses to load file:// URLs at the main-frame level, so the
two layers agree.

file:///android_asset/* remains available on every supported
Android version, so any bundled-asset code path is unaffected.

Assisted-by: Claude (Anthropic)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

WebViewActivity enables setAllowFileAccess but shouldInterceptRequest only routes http/https through OkHttp

1 participant