--- name: android-webview-attacks description: "Attack Android WebViews — JS-to-native bridge abuse (addJavascriptInterface), file/universal access for local-file theft, remote debugging via chrome://inspect, and loading attacker-controlled URLs. Tier 1. Use when the app embeds WebViews. Aligns to OWASP MASTG MASVS-PLATFORM. Payloads: payloads/client-side.md, payloads/xss.md." --- # Android WebView Attacks A WebView that loads attacker-influenced content plus a JS bridge or file access is local-file theft and sometimes JS-to-native code execution. ## Trigger phrases `webview, addjavascriptinterface, javascript bridge, setallowfileaccess, universal access from fileurls, webcontentsdebugging, chrome inspect, webview xss` ## Method 1. **Grep WebView settings** in decompiled code: ``` grep -rniE "setJavaScriptEnabled|addJavascriptInterface|setAllowFileAccess|AllowUniversalAccessFromFileURLs|AllowFileAccessFromFileURLs|setWebContentsDebuggingEnabled|loadUrl" app_java/ ``` Flag: `addJavascriptInterface(obj,"bridge")` (+ `@JavascriptInterface` methods), `setAllowUniversalAccessFromFileURLs(true)`, `setAllowFileAccess(true)`, `setWebContentsDebuggingEnabled(true)`, and `loadUrl(attackerControlledUrl)`. 2. **Determine attacker reach** — can a deep link (`android-deeplink-applink-abuse`), intent (`android-intent-injection-redirection`), or MITM content reach the WebView? 3. **Local file theft** (universal/file access enabled): ```javascript var x=new XMLHttpRequest(); x.open('GET','file:///data/data//databases/app.db',true); x.onreadystatechange=function(){ if(x.readyState==4){ /* exfil x.responseText */ } }; x.send(); ``` 4. **JS bridge invocation:** from injected JS, call exposed `@JavascriptInterface` methods; enumerate the bridge object's methods. 5. **Remote debug:** if `setWebContentsDebuggingEnabled(true)`, attach via `chrome://inspect` and drive the DOM/JS context. ## Modern / rare techniques - **[NEW/RARE] Universal XSS → local file read** via `setAllowUniversalAccessFromFileURLs(true)` — a `file://` page reads any app-private file cross-origin. - **[NEW/RARE] Pre-4.2 bridge RCE** via reflection (legacy devices): ```javascript var rt=bridge.getClass().forName('java.lang.Runtime').getMethod('getRuntime',null).invoke(null,null); rt.exec(['/system/bin/sh','-c','id']); ``` - **XSS-to-native:** reflected/stored XSS in WebView content that reaches a powerful bridge = JS→native method invocation (${CLAUDE_PLUGIN_ROOT}/payloads/xss.md, ${CLAUDE_PLUGIN_ROOT}/payloads/client-side.md). ## Bypass / evasion If the app only loads HTTPS, obtain the injection via MITM after `android-ssl-pinning-bypass`, or via a deep-link/intent-redirection load of a `file://`/attacker URL. ## Escalation / chaining Local file/credential exfil, session theft, JS→native RCE on legacy/bridged apps. Entry chains: `android-deeplink-applink-abuse`, `android-intent-injection-redirection`, `android-ssl-pinning-bypass` (for MITM injection). ## Backend & tooling Preferred Kali path (native Kali / WSL+Kali / Kali-SSH / Kali-MCP / HexStrike) + a headless browser / `chrome://inspect` for client-side. Needs the user's device/emulator (adb; MITM proxy for injection). Route via Burp if a Burp MCP is present. Windows-local last resort. See `zazy-orchestrator`. ## Verification (background, before reporting) Confirm injected JS actually read a local file / called a native method (capture the exfil out-of-band or the returned data), or that DevTools attached, before marking CONFIRMED. Re-run independently. ## Evidence The dangerous WebView settings (file+line), the injection path, and proof (exfiltrated file contents, bridge method output, or DevTools session). Remediation: disable file/universal access; minimal `@JavascriptInterface` surface; app-bundled JS only; validate loaded URLs; gate debugging on `FLAG_DEBUGGABLE`; external links to the browser.