web: deny PWA permission requests with no camera or mic resource
- Commit
acf42b39a9a47f65a6398c435ea9a15cea658cb2- Author
- Vayun Mathur <[email protected]>
- When
- 2026-11-08 04:02 UTC (28 days ago)
- Parents
96b5cb7
handlePwaPermissionRequest granted any resource list needing neither camera nor mic (MIDI, DRM device id, ...) straight through, with no per-site consent sheet or any other user-visible approval on that path. This mirrors the browser-tab bug fixed earlier: WebView permission requests that map to no SitePermissionType must fail closed. Camera/mic requests are untouched: when the OS permission is already granted the installed-app product shape keeps the grant, otherwise the existing system-permission request flow runs. Only the unmapped, consent-less path now denies. Verified: new Robolectric test pwaChromeClientDeniesResourcesWithNoCameraOrMic failed before the fix (silently granted) and passes after; PwaWebViewClientTest's unmapped-resource expectation updated to fail-closed; full :web:testDevUnitTest suite green.
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 3b6bd851d5..dda1627fd8 100644--- a/web/src/main/java/com/vayunmathur/web/platform/PwaBrowser.kt+++ b/web/src/main/java/com/vayunmathur/web/platform/PwaBrowser.kt@@ -454,7 +454,9 @@ private fun handlePwaPermissionRequest(deps: PwaChromeDeps, request: PermissionR val needsCamera = resources.contains(PermissionRequest.RESOURCE_VIDEO_CAPTURE) val needsMic = resources.contains(PermissionRequest.RESOURCE_AUDIO_CAPTURE) if (!needsCamera && !needsMic) {- request.grant(resources)+ // No per-site sheet exists for these resources (MIDI, DRM device id, ...):+ // fail closed rather than silently granting, mirroring the browser tab.+ request.deny() return } if (hasMediaPermissions(deps.context, needsCamera, needsMic)) {
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 5736be52d2..efbc3dc970 100644--- a/web/src/test/java/com/vayunmathur/web/ui/ChromeGrantAndPwaDownloadTest.kt+++ b/web/src/test/java/com/vayunmathur/web/ui/ChromeGrantAndPwaDownloadTest.kt@@ -199,6 +199,27 @@ class ChromeGrantAndPwaDownloadTest { assertEquals(WebSettings.MIXED_CONTENT_NEVER_ALLOW, webView.settings.mixedContentMode) } + @Test fun pwaChromeClientDeniesResourcesWithNoCameraOrMic() {+ // Mirror of chromeClientDeniesResourcesWithNoPermissionSheet: resources that need+ // neither camera nor mic (MIDI, DRM device id, ...) have no consent path in the+ // PWA window, so they must fail closed, never be silently granted.+ 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)+ val chrome = shadowOf(webView).webChromeClient+ assertNotNull(chrome)+ val req = FakePermissionRequest(+ arrayOf(PermissionRequest.RESOURCE_PROTECTED_MEDIA_ID),+ Uri.parse("https://pwa.example"),+ )+ chrome.onPermissionRequest(req)+ assertTrue(req.denied, "unlisted resource must be denied, granted=${req.granted}")+ assertTrue(req.granted == null, "granted=${req.granted}")+ }+ @Test fun pwaBackPressFinishesWhenNoHistory() { rule.setContent { com.vayunmathur.web.platform.PwaBrowser(initialUrl = "https://pwa.example/app", title = "PWA")
web/src/test/java/com/vayunmathur/web/ui/PwaWebViewClientTest.kt
diff --git a/web/src/test/java/com/vayunmathur/web/ui/PwaWebViewClientTest.kt b/web/src/test/java/com/vayunmathur/web/ui/PwaWebViewClientTest.ktindex 4ca6f525ca..fbe5d3e5d2 100644--- a/web/src/test/java/com/vayunmathur/web/ui/PwaWebViewClientTest.kt+++ b/web/src/test/java/com/vayunmathur/web/ui/PwaWebViewClientTest.kt@@ -99,10 +99,11 @@ class PwaWebViewClientTest { val chrome = webView.webChromeClient!! chrome.onReceivedTitle(webView, "New Title") chrome.onReceivedTitle(webView, "")- // Unmapped resource: granted straight through.+ // Unmapped resource: no consent path, so it fails closed. val unmapped = FakePermissionRequest(arrayOf(PermissionRequest.RESOURCE_PROTECTED_MEDIA_ID)) chrome.onPermissionRequest(unmapped)- assertTrue(unmapped.granted != null)+ assertTrue(unmapped.denied)+ assertTrue(unmapped.granted == null) // Camera without system permission: a system request is launched and // the WebView request is held pending (neither granted nor denied yet). val camera = FakePermissionRequest(arrayOf(PermissionRequest.RESOURCE_VIDEO_CAPTURE))