MASTG-DEMO-0158: Runtime Use of WebViewClient URL Loading Handlers with Frida
Download MASTG-DEMO-0158 APK Open MASTG-DEMO-0158 Folder Build MASTG-DEMO-0158 APK
Sample¶
This sample demonstrates how to dynamically analyze the runtime behavior of WebViewClient URL interception methods using Frida to understand how the app handles URL loading in WebViews.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 | |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | |
The code configures a WebView with a custom WebViewClient that intercepts URL loading via shouldOverrideUrlLoading and shouldInterceptRequest methods. The implementation does not perform proper URL validation, potentially allowing navigation to untrusted content.
Steps¶
- Install the app on a device ( Installing Apps).
- Make sure you have Frida (Android) installed on your machine and the frida-server running on the device.
- Run
run.shto spawn the app with Frida. - Optionally, interact with the app and tap links in the WebView to trigger further navigation.
- Stop the script by pressing
Ctrl+Cand/orqto quit the Frida CLI.
1 2 | |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 | |
The Frida script does three things:
- It hooks
setWebViewClientto reveal, at launch, theWebViewClientimplementation the app registers and which URL loading handlers it overrides. This requires no navigation. - It hooks the
shouldOverrideUrlLoadingandshouldInterceptRequestmethods to log each URL they receive at runtime and the value they return. - It hooks the URL inspection accessors
Uri.getHost,Uri.getScheme, andUri.getPathand records any call made while a handler is executing. A genuine allowlist check must read the host (and usually the scheme) to decide whether a URL is trusted, so if a handler runs without ever calling these, it performs no host-based validation.
Observation¶
The output shows the custom WebViewClient registered by the app, the URL loading handlers it overrides, the URLs intercepted at runtime along with their return values, and whether each handler inspected the URL host, scheme, or path.
| output.txt | |
|---|---|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | |
Evaluation¶
The test case fails because the app registers a custom WebViewClient (MastgTestWebView$mastgTest$2) that overrides shouldInterceptRequest and shouldOverrideUrlLoading, but neither handler validates the requested URL:
- Every intercepted request falls through to the default loading behavior, including requests to third-party hosts such as
fonts.googleapis.comandcdn.datatables.net. - For every handler invocation, the
URL inspection during handlerline reportsNONE: the handler returned without ever reading the URL's host, scheme, or path. Since an allowlist check must inspect at least the host to decide whether a URL is trusted, this shows the handlers make no host-based validation decision rather than merely failing to block the specific URLs observed. - When
shouldOverrideUrlLoadingis exercised (by tapping a link), it returnsfalse, so every URL the user is directed to is loaded.
Because the handlers perform no host/scheme/path inspection, the WebView loads content from any host, which could allow navigation to untrusted content or open redirect vulnerabilities.
Note: this technique observes host-, scheme-, and path-based validation, which covers the standard allowlist pattern. It would not detect validation performed purely by matching the raw URL string (for example with
String.contains). Combine it with the static analysis in Uses of WebViewClient URL Loading Handlers with semgrep for full certainty.