medium · M4 · MASVS-PLATFORM-2 · PTKD-WEBVIEW-FLUTTER-CHANNEL
Flutter WebView JavaScript channel reaches sensitive app code
A webview_flutter WebView runs JavaScript (JavaScriptMode.unrestricted) and exposes a JavaScript channel whose handler does something sensitive with the message (reads tokens or storage, opens URLs or files, pays, or calls native code). Any script in the page, including one injected through a third-party widget, an open redirect or a compromised CDN, can send that message.
How it is exploited
A support-chat page inside the app's WebView loads a third-party widget script. The app registers a channel 'Bridge' whose handler reads the access token from secure storage and posts it back to the page so the chat can identify the user. A compromised version of the widget script sends Bridge.postMessage('getToken') and forwards the reply to its own server.
Why it matters
Any script the WebView runs can read tokens, open URLs or files, or trigger payments through the channel: web content gets the app's own powers.
How to fix it
- Load only your own HTTPS pages in a WebView that has channels: return NavigationDecision.prevent for every other URL in NavigationDelegate.onNavigationRequest.
- Check the current page's URL before acting on a message (controller.currentUrl()) and treat the message text as hostile input.
- Never return credentials through a channel; give the page a short-lived, single-purpose token from your backend instead.
- Turn JavaScript off (JavaScriptMode.disabled) for WebViews that only show static content.
Does your app have this?
PTKD checks your build or your source project for PTKD-WEBVIEW-FLUTTER-CHANNEL and every other check in this knowledge base.
Scan your appReferences
Related checks (M4)
- Supabase function runs any SQL the caller sends
- Deep link URL loaded or opened without a host check (heuristic)
- Hybrid WebView may open any website inside the app
- Wildcard associated domain (universal-link hijack surface)
- Process execution via system()/exec/popen
- Unsafe C string function (buffer overflow risk)
- Hijackable custom URL-scheme deep link
- SQL built by joining request data into a string (text search)