web: block mixed content in PWA windows per aggressive shields
- Commit
96b5cb7700d89627b92830a05691f0469c8b07d8- Author
- Vayun Mathur <[email protected]>
- When
- 2026-11-08 03:52 UTC (28 days ago)
- Parents
e291c8d
PwaBrowser hardcoded MIXED_CONTENT_COMPATIBILITY_MODE while its own shields client always resolves the aggressive preset (httpsOnly=true), so installed sites silently allowed plaintext subresources that browser tabs with the same preset refuse outright. Mirror the browser tab logic from applyWebViewSettings: resolve EffectiveShields for AGGRESSIVE_DEFAULTS and map httpsOnly to MIXED_CONTENT_NEVER_ALLOW, falling back to compatibility mode only if the preset ever stops requiring HTTPS-only. User-visible effect: pages loaded in installed-site (PWA) windows no longer pull http:// images, scripts, or other subresources. Verified: new Robolectric test pwaWebViewBlocksMixedContentPerAggressiveShields failed before the fix (COMPATIBILITY_MODE) and passes after; full :web:testDevUnitTest suite green (334 tests, 0 failures).
Diff
web/src/main/java/com/vayunmathur/web/platform/PwaBrowser.kt
diff --git a/web/src/main/java/com/vayunmathur/web/platform/PwaBrowser.kt b/web/src/main/java/com/vayunmathur/web/platform/PwaBrowser.ktindex d779cbacff..3b6bd851d5 100644--- a/web/src/main/java/com/vayunmathur/web/platform/PwaBrowser.kt+++ b/web/src/main/java/com/vayunmathur/web/platform/PwaBrowser.kt@@ -313,7 +313,15 @@ private fun applyPwaWebSettings(webView: WebView, ctx: Context) { settings.displayZoomControls = false settings.useWideViewPort = true settings.loadWithOverviewMode = true- settings.mixedContentMode = WebSettings.MIXED_CONTENT_COMPATIBILITY_MODE+ // Installed sites always run the aggressive shields preset (see createPwaWebViewClient),+ // which resolves httpsOnly=true: refuse plaintext subresources like the browser tab does+ // instead of the permissive default.+ val pwaShields = EffectiveShields.resolve(ShieldsSettings.AGGRESSIVE_DEFAULTS)+ settings.mixedContentMode = if (pwaShields.httpsOnly) {+ WebSettings.MIXED_CONTENT_NEVER_ALLOW+ } else {+ WebSettings.MIXED_CONTENT_COMPATIBILITY_MODE+ } settings.setGeolocationEnabled(true) @Suppress("DEPRECATION") runCatching {
web/src/test/java/com/vayunmathur/web/ui/ChromeGrantAndPwaDownloadTest.kt
diff --git a/web/src/test/java/com/vayunmathur/web/ui/ChromeGrantAndPwaDownloadTest.kt b/web/src/test/java/com/vayunmathur/web/ui/ChromeGrantAndPwaDownloadTest.ktindex 35dbe863c6..5736be52d2 100644--- a/web/src/test/java/com/vayunmathur/web/ui/ChromeGrantAndPwaDownloadTest.kt+++ b/web/src/test/java/com/vayunmathur/web/ui/ChromeGrantAndPwaDownloadTest.kt@@ -10,6 +10,7 @@ import android.view.View import android.view.ViewGroup import android.webkit.GeolocationPermissions import android.webkit.PermissionRequest+import android.webkit.WebSettings import android.webkit.WebView import androidx.activity.ComponentActivity import androidx.compose.ui.test.junit4.createAndroidComposeRule@@ -186,6 +187,18 @@ class ChromeGrantAndPwaDownloadTest { assertNotNull(dm) } + @Test fun pwaWebViewBlocksMixedContentPerAggressiveShields() {+ // PWA windows always run the aggressive shields preset (httpsOnly=true),+ // so the WebView must refuse plaintext subresources like the browser tab does.+ rule.setContent {+ com.vayunmathur.web.platform.PwaBrowser(initialUrl = "https://pwa.example/app", title = "PWA")+ }+ rule.waitForIdle()+ val webView = findWebView(rule.activity.window.decorView)+ assertNotNull(webView)+ assertEquals(WebSettings.MIXED_CONTENT_NEVER_ALLOW, webView.settings.mixedContentMode)+ }+ @Test fun pwaBackPressFinishesWhenNoHistory() { rule.setContent { com.vayunmathur.web.platform.PwaBrowser(initialUrl = "https://pwa.example/app", title = "PWA")