Skip to content

fix(whatif): narrow MathJax file-URL access to allowFileAccessFromFileURLs#357

Open
jim-daf wants to merge 1 commit into
tom-anders:mainfrom
jim-daf:fix-universal-file-access
Open

fix(whatif): narrow MathJax file-URL access to allowFileAccessFromFileURLs#357
jim-daf wants to merge 1 commit into
tom-anders:mainfrom
jim-daf:fix-universal-file-access

Conversation

@jim-daf
Copy link
Copy Markdown

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

Closes #356.

WhatIfActivity.kt sets, with the comment `// These are needed for MathJax`:

binding.web.settings.allowFileAccess = true
binding.web.settings.domStorageEnabled = true
binding.web.settings.allowUniversalAccessFromFileURLs = true

The article is loaded with a file:///android_asset/. base URL, so the WebView is on a file:// origin and allowUniversalAccessFromFileURLs actually takes effect. With it on, any script reachable through the article HTML can issue cross-origin XHR against any origin, including the app's internal storage path served by the WebView's data dir. MathJax only needs to XHR other bundled assets (/extensions/*.js, fonts), which is what the narrower allowFileAccessFromFileURLs already covers.

Change

Swap the universal flag for the narrow one:

- binding.web.settings.allowUniversalAccessFromFileURLs = true
+ binding.web.settings.allowFileAccessFromFileURLs = true

MathJax continues to load because every resource it XHRs lives at `file:///android_asset/`. `allowFileAccess` and DOM storage stay where they are.

…eURLs

The WhatIf WebView is loaded via loadDataWithBaseURL with a
file:///android_asset/. base URL, so the page lives on a file scheme.
allowUniversalAccessFromFileURLs(true) was set with a comment that it
was needed for MathJax, but MathJax only needs to XHR other bundled
assets, all of which are reached via file://. That is the narrower
allowFileAccessFromFileURLs flag.

allowUniversalAccessFromFileURLs is the documented CWE-200 broad
variant that also lets the file URL page issue cross-origin XHR
against any other origin, including app-private content. Swapping to
the narrow flag keeps MathJax loading the way it did while removing
the cross-origin escape.
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.

What-If WebView enables allowUniversalAccessFromFileURLs for MathJax

1 participant