Skip to content

Tighten AdvWebView WebView posture#150

Open
jim-daf wants to merge 1 commit into
slartus:masterfrom
jim-daf:fix-webview-mixed-and-file-urls
Open

Tighten AdvWebView WebView posture#150
jim-daf wants to merge 1 commit into
slartus:masterfrom
jim-daf:fix-webview-mixed-and-file-urls

Conversation

@jim-daf
Copy link
Copy Markdown

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

Closes #149.

AdvWebView.init() turns on three settings that loosen the WebView sandbox more than the forum-client actually needs:

getSettings().setMixedContentMode(WebSettings.MIXED_CONTENT_ALWAYS_ALLOW);
...
getSettings().setAllowFileAccessFromFileURLs(true); //Maybe you don't need this rule
getSettings().setAllowUniversalAccessFromFileURLs(true);

The HTML rendered into AdvWebView is always built locally by HtmlBuilder, TopicBodyBuilder or QmsHtmlBuilder. The page is either pointed at an https://forum-host/forum/ base URL (BbCodesQuickView.loadDataWithBaseURL) or references bundled resources via file:///android_asset/. The android_asset scheme is permitted regardless of the file flags, so neither FromFileURLs flag is load-bearing for any of the existing WebView paths. The dev comment on the first call (Maybe you don't need this rule) already flags the uncertainty.

Change

  1. setMixedContentMode(MIXED_CONTENT_ALWAYS_ALLOW) -> setMixedContentMode(MIXED_CONTENT_COMPATIBILITY_MODE). COMPATIBILITY_MODE keeps passive sub-resources (images, fonts) loading on an https forum page while blocking active mixed content like remote scripts. This is the right default for user-generated forum content.

  2. Drop setAllowFileAccessFromFileURLs(true) and setAllowUniversalAccessFromFileURLs(true). Neither one takes effect when the main frame is an https URL, and they are CWE-200 sandbox-escape vectors when left on.

Out of scope

setAllowFileAccess(true) is left in place. Removing it would need a wider audit of every fragment that builds its own AdvWebView (ForumRulesFragment, SpecialView, ProfileEditFragment, QmsChatFragment, SearchPostFragment, PostPreviewFragment, ThemeFragment, MentionsListFragment), so I have kept this PR to the central AdvWebView only.

AdvWebView.init() turned on three settings that loosen the WebView
sandbox more than the forum-client code actually needs:

  - setMixedContentMode(MIXED_CONTENT_ALWAYS_ALLOW)
  - setAllowFileAccessFromFileURLs(true)
  - setAllowUniversalAccessFromFileURLs(true)

The HTML rendered into AdvWebView is always built locally by
HtmlBuilder / TopicBodyBuilder / QmsHtmlBuilder and either points the
WebView at an https://forum-host/forum/ base URL or references
bundled resources via file:///android_asset/. The android_asset
scheme is permitted regardless of the file flags, so neither
FromFileURLs flag is load-bearing for any of the existing call sites.

Replace MIXED_CONTENT_ALWAYS_ALLOW with MIXED_CONTENT_COMPATIBILITY_MODE,
which keeps passive sub-resources (images, fonts) loading on https
forum pages while blocking active mixed content like remote scripts.

Remove the two setAllow*FromFileURLs(true) calls. The dev comment
on the first one already said 'Maybe you don't need this rule' --
confirmed, neither is needed.

setAllowFileAccess(true) is left in place because removing it would
require a wider audit of every fragment that constructs an
AdvWebView.
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.

AdvWebView enables MIXED_CONTENT_ALWAYS_ALLOW and the FromFileURLs flags despite only loading https + android_asset

1 participant