Android WebView: which pages should open inside your app?
WebView lets an app embed help pages, an account area or another web interface. That content brings navigation, embedded pages and sometimes access to native functions. Before release, decide which content should receive those capabilities and verify the policy in your own build. This guide uses a fictional flashcard app as its example.
Map the content and its capabilities first
In the example, an app displays its own help pages, keeps an offline copy and links to external reading material. The team decides to keep help inside the app while opening external pages in a browser. This is a fictional scenario for designing a review, not a finding from a client audit.
For each screen, record the HTML source, possible redirects and embedded frames, and whether JavaScript or a native bridge is necessary. Identify who can change the content. If a trusted page includes a third-party iframe or user-provided HTML, checking only the top-level page address does not describe the entire trust boundary.
Validate the parsed components of a URL
Before passing an address to WebView, parse the URI and compare its scheme and complete host with an explicit policy. Also define allowed ports, subdomains and whether userinfo is needed for your navigation design. Unexpected or invalid values should follow a defined rejection path.
HTTPS provides protected transport to the specified site; it does not make every site trusted by the app. Looking for your domain name anywhere in a URL string, or incompletely checking its beginning or ending, can produce mistakes. Put address validation in one function and cover it with tests that have explicit expected outcomes.
Check the initial address and later navigation
Apply the policy before the initial loadUrl call, then account for links and redirects. WebViewClient.shouldOverrideUrlLoading with WebResourceRequest does not run for every navigation: in particular, it is not called for app-initiated loadUrl calls or POST requests. The callback can also involve subframes, so it is not a universal filter for every resource.
Returning true from the callback cancels the current load; false lets it continue. An allowed navigation does not require another loadUrl call with the same address. Decide how external links should behave in advance: for example, open them in a browser without carrying over the native capabilities of the internal screen.
Give a JavaScript bridge minimal capabilities
JavaScript is disabled in WebView by default. Enable it when a particular feature requires it. Assess the need for addJavascriptInterface separately: it exposes a Java object to every frame, including iframes, and does not itself authenticate the calling frame’s origin.
A trusted top-level address therefore does not establish that every bridge call came from trusted content. Remove an unnecessary bridge; where one is needed, reduce its functions and keep arbitrary external pages out of the privileged context. An interface’s presence alone does not prove device compromise: assess its capabilities and the content actually permitted to use them.
Separate local help from arbitrary file access
Android recommends WebViewAssetLoader for HTML and resources packaged in an app. It presents local content through an HTTP(S) origin; that does not mean help content must be downloaded over the network. Configure the required resource paths and verify that the offline experience works.
If the feature does not need filesystem access or content provider URLs, consider setAllowFileAccess(false) and setAllowContentAccess(false). The first flag does not by itself block android_asset or android_res. Avoid expanding access by enabling the deprecated allowFileAccessFromFileURLs or allowUniversalAccessFromFileURLs settings. After a change, test what the screen does, as well as the settings it uses.
Verify the policy in your own release build
The fictional app team prepares two pages it controls and synthetic content. It records expected behavior for each entry point, then tests the build intended for release. The review includes targetSdk, the device and the actual WebView version: a general statement about the Android version does not replace observing the result.
For each matrix entry, record the final address, the context in which it opened and the outcome. Keep tokens, real messages and personal information out of review logs. Repeat affected scenarios when a dependency or setting changes.
- Approved help content opens inside the app and retains the features it needs.
- An initial address with a disallowed scheme or host is rejected before reaching WebView.
- A controlled redirect and an external link open in the context chosen by the policy.
- An embedded test page receives no unnecessary native capabilities; check this separately from the top-level frame’s address.
- Offline help, back navigation and core actions work after unnecessary permissions are disabled.
Keep the results and review the product’s web component
Keep the content map, allowed addresses and capabilities, build details and matrix results with the release. Changes to help pages, redirects or embedded SDKs can then be compared with verified behavior. Review access to native functions whenever a new content source is introduced.
If the app has a website or an accessible web component, start reviewing that part with CheckMyApp’s free audit using the link at the end of this page. A web review does not replace a separate assessment of the Android build and its WebView.