WebView Vulnerabilities
The security problems of embedding a browser inside a native app: a WebView bridges untrusted web content to native capability, so misconfigured settings, weak URL validation, and exposed JavaScript interfaces turn a web bug into device-level compromise.
Why WebViews are dangerous
A WebView is the most widely used — and most error-prone — Android UI component. The risk is the bridge: web content gets a path to native code, local files, cookies, and other app components. The recurring root causes are permissive settings and validation that checks the wrong thing.
Settings that open holes (Android)
Dangerous when combined with loading attacker-influenced URLs:
addJavascriptInterface— exposes a Java object to JS. On all current Android versions, reflection from an injected@JavascriptInterfacemethod can reachjava.lang.Runtimeand run OS commands (WithSecure): MitM on an ad SDK → inject JS → reverse shell / drop a payload. The classic WebView RCE.setAllowUniversalAccessFromFileURLs(true)/setAllowFileAccessFromFileURLs(true)— afile://orcontent://page can XHR/iframe-read the app’s private files (SharedPreferences, tokens) and exfiltrate them.setAllowContentAccess(true)(default on) — WebView can reach the app’s ContentProviders viacontent://, including non-exported ones that perform dangerous actions.setJavaScriptEnabled(true)with cookie-based auth — setting a sensitive cookie for an attacker-controllable URL leaks the session.setAllowFileAccess(true)— in AndroGoat the app’s own URL loader renderedfile:///data/data/<pkg>/shared_prefs/users.xml, exposing stored credentials. A QR scanner fed decoded content into a JS-enabled WebView, and a name field reached a WebView unescaped (XSS). Disable file access and JS where not needed, encode for context, add a CSP AndroGoat.
Hardening: disable geolocation, content access, file access, and universal/file-from-file access unless strictly needed; gate JS; validate URLs properly.
URL-validation failures
The single most common bug is checking host but not scheme. Bypasses against host-only checks:
javascript://legitimate.com/%0aalert(1)— executes JS in the WebView’s context.file://legitimate.com/sdcard/exploit.html— opens a public-directory file.content://legitimate.com/— serves attacker content via a claimed authority.
Other failures: String.contains()/substring checks; android.net.Uri is abstract and a reflection-built Uri$HierarchicalUri subclass can bypass naive checks (works even post-API-28 via RestrictionBypass); backslash parser differences between android.net.Uri and java.net.URL on API ≤24. Use java.net.URI, validate authority not host, and raise minSdkVersion.
Injection and redirection patterns
- Universal XSS / JS injection — attacker controls
baseUri+datainloadDataWithBaseURL, or data is concatenated into JS; an exported WebActivity re-fed viaonNewIntentwith ajavascript:scheme yields UXSS. Sanitize with JSON methods. (Flickr mobile XSS: unanchored regex + CORS misconfig executed external HTML in-origin.) shouldOverrideUrlLoading/shouldInterceptRequestabuse — handlers that launch arbitrary activities, or that re-issue main-frame requests through an OkHttp client that injects auth headers with no domain allowlist. In two bug-bounty cases an app injectedAuthorization: Bearer(+ refresh token) into every WebView request; redirecting the WebView to an attacker (or claimable) domain captured the full session = one-click ATO (see Mobile OAuth and Deep Link Attacks).- File theft via file choosers —
onShowFileChooserreturning an implicit intent lets a malicious app supply the URI of a protected file toonReceiveValue. - Intent redirection → insecure WebView — an exported activity resolving an attacker-supplied class via
Class.forName()can launch an internal WebView activity configured withallowUniversalAccessFromFileURLs, then load acontent://page whose iframes read/data/data/<pkg>/shared_prefs/*(zero-permission app). See intent redirection under Mobile OAuth and Deep Link Attacks.
iOS and cross-platform
WKWebView has analogous risks: JS message handlers as the bridge, and tel:/Shortcuts callback chains bypassing confirmation prompts (Chrome for iOS, CVE-2026-13795). Hybrid frameworks (Cordova/Ionic, React Native WebViews) inherit all of the above.
Testing
Decompile and grep for addJavascriptInterface, setAllowUniversalAccessFromFileURLs, setJavaScriptEnabled, loadDataWithBaseURL, shouldOverrideUrlLoading, shouldInterceptRequest; map exported activities that feed WebViews. OWASP Oversecured’s WebView checklist and OVAA/DeeplinkActivity are reference targets. MASVS-PLATFORM.
Related
- Mobile Application Security · Android App Security · Mobile OAuth and Deep Link Attacks · iOS App Security · OWASP Mobile Top 10 · Cross-Site Scripting
Sources
- Android security checklist: WebView (Oversecured) · original
- WebView addJavascriptInterface Remote Code Execution (WithSecure) · original
- Abusing an Android WebView JavaScript Interface · original
- Stealing App Internal Files via Intent Redirection to Insecure WebView · original
- One-Click ATO via WebView Auth Header Injection · original
- One Missing Anchor, One Flickr XSS · original
- Using Shortcuts to Bypass Chrome for iOS Call Prompts · original
- 33 Cracks in the Armor: Hacking AndroGoat · original