web: deny WebView permissions with no per-site sheet
- Commit
e291c8d3de7ac5e263f2f41f7827010ea32fd3ab- Author
- Vayun Mathur <[email protected]>
- When
- 2026-11-08 03:37 UTC (28 days ago)
- Parents
902d2dc
onPermissionRequest mapped camera/mic resources to the per-site permission sheets but granted every other resource unconditionally. Any site could obtain RESOURCE_PROTECTED_MEDIA_ID (a persistent DRM device identifier) or MIDI sysex access with zero user signal, bypassing the app's permission model entirely - and private tabs already denied everything, so normal tabs were strictly less protected than private ones for these resources. Fix: fail closed with request.deny() when no requested resource maps to a known SitePermissionType. This matches the private-tab behavior and the privacy-browser default; the tradeoff is that EME playback requiring a distinctive identifier now fails rather than silently fingerprinting, which is the correct side to err on until a dedicated sheet exists. Verified red-then-green (new deny test plus updating the legacy test that pinned the silent-grant behavior) and the full :web:testDevUnitTest suite: 331 tests, 0 failures, 0 errors.
Diff
web/src/main/java/com/vayunmathur/web/ui/WebViewClients.kt
diff --git a/web/src/main/java/com/vayunmathur/web/ui/WebViewClients.kt b/web/src/main/java/com/vayunmathur/web/ui/WebViewClients.ktindex 93c24ada94..cf1e327e9c 100644--- a/web/src/main/java/com/vayunmathur/web/ui/WebViewClients.kt+++ b/web/src/main/java/com/vayunmathur/web/ui/WebViewClients.kt@@ -212,7 +212,10 @@ internal fun createBrowserWebChromeClient( if (resources.contains(PermissionRequest.RESOURCE_AUDIO_CAPTURE)) types.add(SitePermissionType.MICROPHONE) if (types.isEmpty()) {- request.grant(resources)+ // No per-site sheet exists for these resources (protected media ID, MIDI+ // sysex, ...): fail closed. Silently granting would hand out persistent+ // device identifiers without any user signal.+ request.deny() return }
web/src/test/java/com/vayunmathur/web/ui/BrowserInteractionTest.kt
diff --git a/web/src/test/java/com/vayunmathur/web/ui/BrowserInteractionTest.kt b/web/src/test/java/com/vayunmathur/web/ui/BrowserInteractionTest.ktindex 07cd7e7699..90d757d9a6 100644--- a/web/src/test/java/com/vayunmathur/web/ui/BrowserInteractionTest.kt+++ b/web/src/test/java/com/vayunmathur/web/ui/BrowserInteractionTest.kt@@ -199,16 +199,18 @@ class BrowserInteractionTest { assertEquals(false, geoResult) } - @Test fun chromeClientGrantsUnmappedResources() {+ @Test fun chromeClientDeniesUnmappedResources() { val v = vm() v.newTab(url = "https://pub.example") val tabId = v.activeTabId!! val chrome = createBrowserWebChromeClient(tabId, v, false, deps(), onRequestNewTab = {}) val webView = WebView(context)- // A protected-media-id request maps to no site-permission type and is granted through.+ // A protected-media-id request maps to no site-permission type, so it fails+ // closed instead of being silently granted. val req = FakePermissionRequest(arrayOf(PermissionRequest.RESOURCE_PROTECTED_MEDIA_ID)) chrome.onPermissionRequest(req)- assertTrue(req.granted?.contains(PermissionRequest.RESOURCE_PROTECTED_MEDIA_ID) == true)+ assertTrue(req.denied)+ assertTrue(req.granted == null) chrome.onProgressChanged(webView, 100) assertEquals(1f, v.getProgress(tabId)) }
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 f33087b7c3..35dbe863c6 100644--- a/web/src/test/java/com/vayunmathur/web/ui/ChromeGrantAndPwaDownloadTest.kt+++ b/web/src/test/java/com/vayunmathur/web/ui/ChromeGrantAndPwaDownloadTest.kt@@ -140,6 +140,23 @@ class ChromeGrantAndPwaDownloadTest { assertEquals(false, geoAllow) } + @Test fun chromeClientDeniesResourcesWithNoPermissionSheet() {+ // RESOURCE_PROTECTED_MEDIA_ID (persistent DRM device identifier) has no+ // per-site sheet: it must fail closed, never be silently granted.+ val v = vm()+ v.newTab(url = "https://media.example/watch")+ val tabId = v.activeTabId!!+ val deps = WebViewClientDeps(context, launcher()) { _, _, _ -> }+ val chrome = createBrowserWebChromeClient(tabId, v, false, deps, onRequestNewTab = {})+ val req = FakePermissionRequest(+ arrayOf(PermissionRequest.RESOURCE_PROTECTED_MEDIA_ID),+ Uri.parse("https://media.example"),+ )+ chrome.onPermissionRequest(req)+ assertTrue(req.denied, "unlisted resource must be denied, granted=${req.granted}")+ assertTrue(req.granted == null, "granted=${req.granted}")+ }+ private fun findWebView(view: View): WebView? { if (view is WebView) return view if (view is ViewGroup) for (i in 0 until view.childCount) findWebView(view.getChildAt(i))?.let { return it }