Don’t put your blame on me
Android apps load URLs into a WebView after checking them with flawed string comparisons such as startsWith, endsWith or contains, so a URL on an attacker-controlled domain passes the check. An attacker could then get their page loaded inside the app's WebView, and where a JavaScript interface is attached this could lead to JavaScript execution or account takeover.
Published on valsamaras.medium.com
I have been assessing Android applications for some time and I must admit that despite the countless write-ups about unprotected WebViews, the particular issue is still on top of my list. Almost 80% of the reviewed apps were vulnerable to forced browsing with the actual impact varying from JavaScript execution to full…
The full write-up lives on its author's site
It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.
Context
WebView is the Android component that lets an app render web content inside its own UI. Its dangerous features are disabled by default, but the researcher's experience across Android assessments is that unprotected WebView handling is still the most common issue he finds: roughly 80% of the apps he reviewed were vulnerable to forced browsing, with impact ranging from JavaScript execution to full account takeover.
The usual pattern is a malicious URL reaching the WebView through an unvalidated query parameter, an intent extra, or an open redirect. Impact is normally low to medium, but it becomes severe when special conditions apply. An attached JavascriptInterface that exposes useful functionality is the classic amplifier, and the researcher links to a published TikTok for Android one-click RCE as an example of that combination.

This post is about the authorisation check that is supposed to stop the malicious URL, and about how often that check is written in a way that looks correct but is not. The applications discussed are anonymised; the proof of concept is a small app written for the post.
Setup
No accounts, roles or specific app versions are involved. The work is an assessment of Android applications, plus a purpose-built sample app. The tooling mentioned is Medusa, a module the researcher wrote, which monitors an application's WebView for risky features including JavaScript interfaces, file access and URL loading. Medusa surfaced findings during assessments, but the cases in this post are ones where the mistake is obvious once you look at the authorisation function itself.
Finding it
A fair question is why this keeps happening when the issue is so widely documented. The researcher's answer is inheritance. In a codebase with multiple layers of Java inheritance, a superclass may load any URL handed to it from an unsanitised parameter. When you are writing code in the child of a child of a child of that parent, the problem is not obvious from where you sit. The unsafe load is far away from the code you are reviewing.
The cases in this post are the opposite: the flaw sits in the check itself, in plain sight.
Exploitation
Step 1: a deeplink that reaches the WebView
The sample app declares a deeplink in its AndroidManifest.xml:
example://webview
The intent filter registers the activity for intents with action android.intent.action.VIEW and data example://webview, so MainActivity is triggered by that URI. The onNewIntent callback inspects the data string and, if it is not empty, calls handleDeeplink to handle the intent. handleDeeplink calls isAuthorisedURL to check the validity of the incoming URL, and if that returns true, the WebView loads the URL.
In the sample, isAuthorisedURL always returns true, so any URL supplied through the deeplink is loaded. That is the baseline: the plumbing from an external URI to the WebView is intact, and only the check stands between an attacker and the load.
Step 2: the check that only looks like a check
The interesting cases are where the check exists but is wrong. Applications often need to load URLs across subdomains that are added or removed over time, so developers reach for startsWith, endsWith or contains from java.lang.String to filter domains. The researcher found this in an application with more than 100,000,000 downloads, where isAuthorisedURL was built around a prefix comparison.
The intent was presumably to allow the foo subdomains of the foobar domain. The implementation is wrong: every URL of the form foo.foobar* is treated as valid and loaded into the WebView. The check matches the beginning of the string, not the host.
Step 3: the same mistake with a suffix, and credentials attached
A similar issue using endsWith turned up in an application with more than 10,000,000 downloads. In that case the request to the loaded URL was authenticated, which raises the stakes: the WebView would carry the user's session to whatever host passed the check. The isAuthorisedURL function compared the end of the string against the trusted domain, so every domain of the form *foobar.com passed the if condition and was loaded.
Step 4: the forgotten staging host
A third pattern does not depend on string functions at all. During staging, development teams sometimes use hostnames that are valid on the company's local network but not on the public internet, and sometimes they are valid on the public internet too. In the example, the developers wanted to allow example.com, google.com and test.com, and during staging they also added staging.site to test the feature. When the app was published, the extra URL was not removed.
If staging.site is available, an attacker can register the domain and take over the WebView. The same condition applies to expired domains that are still on the allow list.
Root cause
The mistake is treating a substring test as a host test. startsWith, endsWith and contains operate on the whole URL string, so an attacker controls the parts the check does not pin down. A prefix check on foo.foobar accepts foo.foobar followed by anything, and a suffix check on foobar.com accepts anything that ends with those characters, including an attacker-owned domain.
The staging case is a configuration and lifecycle failure rather than a parsing one: a host that was only meant for testing stayed in the allow list after release, and nothing in the release process removed it.
In the inheritance scenario, the defence fails because the unsafe load lives in a distant superclass and reviewers of the child code do not see it. Medusa's WebView monitoring is the researcher's answer to that visibility problem.
Impact
The impact depends on what the WebView can do once it loads an attacker-controlled URL. At the low end it is forced browsing. Where a JavascriptInterface is attached and exposes useful functionality, the loaded page can reach that functionality, which is how the issue escalates to JavaScript execution and, in the linked TikTok case, to remote code execution. Where the WebView's requests are authenticated, as in the endsWith case, the attacker's page is loaded with the user's session behind it.
The researcher's own framing is that impact varies from JavaScript execution to full account takeover, and that the dangerous features being off by default is what usually keeps it at low to medium.
Fix
Variants to test
- Prefix allow list. Find an
isAuthorisedURLthat usesstartsWithon a domain. A positive result is a URL of the formfoo.foobar*being loaded. - Suffix allow list. Find a check that uses
endsWith. A positive result is any attacker-owned domain ending in the trusted string, such as*foobar.com, being loaded, especially where the WebView's requests are authenticated. - Substring allow list. Find a check that uses
contains. - Staging and expired hosts. Enumerate every host in the allow list and check whether any is unregistered or available. A positive result is a host you can register that the app will load.
- Deeplink reachability. A positive result is a deeplink that reaches a WebView load without an effective check, as in the
example://webviewsample. - Inherited loaders. Trace WebView loads back through the class hierarchy. A positive result is a superclass that loads a URL from an unsanitised parameter, reachable from a child class you are reviewing.
What happened, in plain words
Many Android apps show web pages inside themselves. The part of Android that draws those pages is called a WebView. It is like a small browser window embedded in the app, so the user never leaves the app to read a page.
A WebView can be told to open a web address (a URL). If an app lets an outside party choose that address without checking it properly, the outside party can make the app open a page of their choosing. This is called forced browsing: the attacker forces the app's built-in browser to visit a page the attacker controls.
Dimitrios Valsamaras (@Ch0pin) has assessed many Android apps. He says that in roughly 80% of the apps he reviewed, the WebView handling was vulnerable to forced browsing. The damage ranged from running JavaScript (code that runs inside a web page) to full account takeover (an attacker getting control of a user's account).
This post is about the check that is supposed to stop a bad URL, and about how often that check is written in a way that looks right but is not. The apps discussed are anonymised, and the proof of concept is a small app the author wrote for the post.
Why this keeps happening
You might ask: if this problem is so common, why do developers not fix it? Sanitising user input sounds easy.
The author's answer is inheritance. In Java (the language Android apps are usually written in), a class can be built on top of another class, which is built on top of another, and so on. Think of it like a family tree of code: a child class inherits behaviour from its parent, and the parent inherits from its parent. Somewhere high up in that tree, a parent class may load any URL it is given from a parameter that was never checked. When you write code in the child of a child of a child of that parent, the unsafe load is far away and not obvious from where you sit.
To help find these problems, the author wrote a tool called Medusa. It is a module (an add-on) that watches an app's WebView for risky features, including JavaScript interfaces, file access and URL loading. Medusa found some good results during assessments, but this post is about cases where the mistake is obvious once you look at the check itself.
When Equal is Not
The cases in this post are the opposite of the hidden-inheritance problem: the flaw sits in the check, in plain sight. The author wrote a simple Android app to prove the concept, and starts with a deeplink declaration in the app's AndroidManifest.xml.
A deeplink is a link that opens a specific screen inside an app instead of a web page. For example, tapping a link in a message can open the app directly. The manifest is a file that tells Android what the app contains and which links it responds to.
The app registers the deeplink example://webview. That means the MainActivity (the app's main screen) is triggered by intents with action android.intent.action.VIEW and data example://webview. An intent is Android's message that asks a component to do something; VIEW means "show this to the user".
Here is how the app handles it, in plain words:
- The
onNewIntentcallback runs when a new intent arrives. It looks at the data string (the URL). - If the data string is not empty, it calls
handleDeeplinkto handle the intent. handleDeeplinkcallsisAuthorisedURLto check whether the incoming URL is allowed.- If
isAuthorisedURLreturns true, the WebView loads the URL.
In the sample app, isAuthorisedURL always returns true, so any URL supplied through the deeplink is loaded. That is the baseline: the path from an outside link to the WebView works, and only the check stands between an attacker and the load.
Equal is ! (Starts || Ends || Contains)
Apps often need to load URLs across subdomains. A subdomain is a prefix on a domain name: in shop.example.com, shop is a subdomain of example.com. Subdomains get added or removed over time as features come and go, so developers cannot always hard-code a fixed list.
To handle this, developers reach for string functions from Java's java.lang.String class: startsWith, endsWith and contains. These functions test whether a piece of text begins with, ends with, or contains some other piece of text. They are easy to use, and that is the problem.
The author found this in an app with more than 100,000,000 downloads. Its isAuthorisedURL was built around a prefix comparison. The intent was presumably to allow the foo subdomains of the foobar domain. The implementation is wrong: every URL of the form foo.foobar* is treated as valid and loaded into the WebView. The check matches the beginning of the string, not the host.
A similar issue using endsWith turned up in an app with more than 10,000,000 downloads. This time the request to the loaded URL was authenticated. The isAuthorisedURL function compared the end of the string against the trusted domain, so every domain of the form *foobar.com passed the if condition and was loaded.
The host is dead, long live the host
A third pattern does not depend on string functions at all. During staging (the testing phase before an app is released), development teams sometimes use hostnames that are valid on the company's local network but not on the public internet. Sometimes they are valid on the public internet too.
In the example, the developers wanted to allow example.com, google.com and test.com. During staging they also added staging.site to test the feature. When the app was published, the extra URL was not removed.
If staging.site is available, an attacker can register the domain and take over the WebView. The same condition applies to expired domains that are still on the allow list.
Conclusion
This post just scratches the tip of the iceberg when it comes to WebView security vulnerabilities. The intention was to point out some cases where small mistakes, even in very popular apps, can have very serious impact.
Glossary
- WebView: the Android component that lets an app render web content inside its own screen.
- URL: a web address, such as
https://example.com/page. - Forced browsing: making an app's WebView open a page the attacker chose, without the user intending it.
- JavaScript: code that runs inside a web page in a browser or WebView.
- Account takeover: an attacker gaining control of a user's account.
- Inheritance: a way of building classes on top of other classes in Java, so a child class reuses behaviour from its parent.
- Class: a blueprint for code in Java; an app is made of many classes.
- Superclass: the parent class that another class inherits from.
- Module: an add-on piece of software that extends a tool's features.
- Medusa: a module the author wrote that monitors an app's WebView for risky features.
- JavascriptInterface: a bridge that lets a web page inside a WebView call functions in the app's Java code.
- Deeplink: a link that opens a specific screen inside an app instead of a web page.
- AndroidManifest.xml: the file that tells Android what an app contains and which links it responds to.
- Intent: Android's message asking a component to do something, such as show a URL.
- Intent filter: a manifest entry that says which intents an activity responds to.
- Activity: a single screen in an Android app.
- Callback: a function that Android calls for you when something happens, such as a new intent arriving.
- Subdomain: a prefix on a domain name, such as
shopinshop.example.com. - startsWith / endsWith / contains: Java string functions that test whether text begins with, ends with, or contains other text.
- Host: the domain-name part of a URL, such as
example.com. - Authenticated request: a request that carries proof of who the user is, so the server treats it as coming from that user.
- Session: the state of a user being logged in, usually carried by a cookie or token.
- Staging: the testing phase before an app is released to the public.
- Allow list: a list of things that are permitted, here the hosts a WebView may load.
- Expired domain: a domain name whose registration has lapsed and which anyone can register.
- Remote code execution (RCE): running an attacker's code on someone else's device or server.