Skip to content

Commit 0294bd9

Browse files
committed
security(webview): lock down the dashboard WebView
The Clash/yacd dashboard WebView loads a user-editable URL (DataStore.yacdURL) with JavaScript + DOM storage enabled (the yacd SPA requires both). Everything else is now explicitly locked down so that page can never read the device filesystem or content providers, escalate from file:// origins, downgrade to cleartext on an https page, or spawn JS popups: - allowFileAccess = false - allowContentAccess = false - allowFileAccessFromFileURLs = false - allowUniversalAccessFromFileURLs = false - mixedContentMode = MIXED_CONTENT_NEVER_ALLOW - javaScriptCanOpenWindowsAutomatically = false; setSupportMultipleWindows(false) Verified on-device: the yacd dashboard (MetaCubeX/yacd 0.3.6) still loads and runs from http://127.0.0.1:9090/ui — no access-denied / mixed-content errors.
1 parent 49d0283 commit 0294bd9

1 file changed

Lines changed: 19 additions & 2 deletions

File tree

app/src/main/java/io/nekohasekai/sagernet/ui/WebviewFragment.kt

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,25 @@ class WebviewFragment : ToolbarFragment(R.layout.layout_webview), Toolbar.OnMenu
3535
// webview
3636
WebView.setWebContentsDebuggingEnabled(BuildConfig.DEBUG)
3737
mWebView = binding.webview
38-
mWebView.settings.domStorageEnabled = true
39-
mWebView.settings.javaScriptEnabled = true
38+
mWebView.settings.apply {
39+
// The Clash/yacd dashboard is a JS SPA talking to the local Clash API, so JS
40+
// and DOM storage are required. Everything else is locked down: the dashboard
41+
// (a user-editable URL) must never be able to read the device filesystem or
42+
// content providers, escalate from file:// origins, or downgrade to cleartext
43+
// resources on an https page.
44+
javaScriptEnabled = true
45+
domStorageEnabled = true
46+
allowFileAccess = false
47+
allowContentAccess = false
48+
@Suppress("DEPRECATION")
49+
allowFileAccessFromFileURLs = false
50+
@Suppress("DEPRECATION")
51+
allowUniversalAccessFromFileURLs = false
52+
mixedContentMode = WebSettings.MIXED_CONTENT_NEVER_ALLOW
53+
// No automatic JS-initiated window.open popups.
54+
javaScriptCanOpenWindowsAutomatically = false
55+
setSupportMultipleWindows(false)
56+
}
4057
mWebView.webViewClient = object : WebViewClient() {
4158
override fun onReceivedError(
4259
view: WebView?, request: WebResourceRequest?, error: WebResourceError?

0 commit comments

Comments
 (0)