# 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 `@JavascriptInterface` method can reach `java.lang.Runtime` and run OS commands (WithSecure): MitM on an ad SDK → inject JS → reverse shell / drop a payload. The classic WebView RCE. - `setAllowUniversalAccessFromFileURLs(true)` / `setAllowFileAccessFromFileURLs(true)` — a `file://` or `content://` 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 via `content://`, 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 rendered `file:///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 [[raw/medium.com/33-cracks-in-the-armor-hacking-androgoat-to-learn-how-android-apps-rea-15949|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`+`data` in `loadDataWithBaseURL`, or data is concatenated into JS; an exported WebActivity re-fed via `onNewIntent` with a `javascript:` scheme yields UXSS. Sanitize with JSON methods. (Flickr mobile XSS: unanchored regex + CORS misconfig executed external HTML in-origin.) - **`shouldOverrideUrlLoading` / `shouldInterceptRequest` abuse** — 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 injected `Authorization: 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** — `onShowFileChooser` returning an implicit intent lets a malicious app supply the URI of a protected file to `onReceiveValue`. - **Intent redirection → insecure WebView** — an exported activity resolving an attacker-supplied class via `Class.forName()` can launch an internal WebView activity configured with `allowUniversalAccessFromFileURLs`, then load a `content://` 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 - [[raw/blog.oversecured.com/android-security-checklist-webview-oversecured-blog-4010|Android security checklist: WebView (Oversecured)]] - [[raw/labs.withsecure.com/webview-addjavascriptinterface-remote-code-execution-withsecure-labs-4011|WebView addJavascriptInterface Remote Code Execution (WithSecure)]] - [[raw/medium.com/the-bridge-between-a-web-page-and-the-phone-itself-abusing-an-android-12925|Abusing an Android WebView JavaScript Interface]] - [[raw/abdelnasserr.medium.com/stealing-app-internal-files-via-intent-redirection-to-insecure-webview-13160|Stealing App Internal Files via Intent Redirection to Insecure WebView]] - [[raw/abdelnasserr.medium.com/one-click-account-takeover-via-webview-auth-header-injection-to-claima-13066|One-Click ATO via WebView Auth Header Injection]] - [[raw/masimshahzad.medium.com/one-missing-anchor-one-flickr-xss-14346|One Missing Anchor, One Flickr XSS]] - [[raw/blog.doyensec.com/one-tap-too-far-using-shortcuts-to-bypass-chrome-for-ios-call-prompts-12111|Using Shortcuts to Bypass Chrome for iOS Call Prompts]] - [[raw/medium.com/33-cracks-in-the-armor-hacking-androgoat-to-learn-how-android-apps-rea-15949|33 Cracks in the Armor: Hacking AndroGoat]]