Universal XSS in Android WebView (CVE-2020-6506)
A universal cross-site scripting (UXSS) vulnerability in Android WebView allowed a cross-origin iframe to execute arbitrary JavaScript in the top-level document when multiple windows support was disabled. An attacker could run code in the context of the top page, potentially accessing privileged APIs and, in rare cases, achieving remote code execution.
Published on alesandroortiz.com
September 10, 2020 about Vulnerabilities, Android, UXSS, CVE-2020-6506
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
Android WebView is a system component that lets Android apps display web pages. Apps use it directly or through frameworks and libraries, and the WebView version an app gets is the one installed on the system, updatable through the Google Play Store like any other app. Modern WebView versions are not tied to an Android OS version or an application build. Most third-party browsers on Android render pages with WebViews, so a flaw in WebView is an attack surface shared by all of them, plus many other apps.
CVE-2020-6506 (crbug.com/1083819) is a universal cross-site scripting (UXSS) vulnerability in Android WebView that lets a cross-origin iframe execute arbitrary JavaScript in the top-level document. It affects vendors that use Android WebView with a default configuration setting and whose apps run on systems with Android WebView prior to 83.0.4103.106 Stable. The vulnerability appears to have been introduced in or around 76.0.3809.21 Beta / 76.0.3809.89 Stable.
Although WebView uses Chromium under the hood, some vulnerabilities that Chrome for Android prevents still work in WebViews under certain configurations. This is one of them.
## Setup
The researcher found the issue while pentesting over a dozen Android web browsers, and traced the cause to Android WebView behaviour rather than to any single browser. A large number of tested browsers were vulnerable, either through their own code or through dependencies, and those dependencies are frameworks widely used in many applications.
The precondition is a WebView instance with `WebSettings.setSupportMultipleWindows()` left at its default or set to `false`. The patched WebView is 83.0.4103.106, released on Monday, June 15th, 2020; users must run at least that version to be fully protected. Systems on WebView 75 or prior do not reproduce the issue, and versions newer than the fix do not either. Mateusz B�
k helped identify the earliest reproducible version.
## Finding it
When multiple windows support is `false`, WebView handles new windows with `javascript:` URLs the same way as new windows with `https://` URLs: it navigates the top document to the provided URL. For a `javascript:` URL that means JavaScript runs in the top document context. An iframe on a different origin can therefore call `window.open()` with a `javascript:` URL and escape the same-origin policy.
Opening a new window requires a user interaction (a tap/click or a keypress), so the attack needs a single activation. The malicious iframe does not need to be visible: it can obtain the keypress while the user types in the top-level document, with no direct interaction with the iframe. That keyboard focus theft is the behaviour described in crbug.com/622714.
In rare configurations no user interaction is required at all (a drive-by attack). The top-level page must be loaded using the `file://` scheme, and the WebView must set both `WebSettings.setJavaScriptCanOpenWindowsAutomatically()` and `WebSettings.setAllowUniversalAccessFromFileURLs()` to `true`.
## Exploitation
### Step 1: Identify a WebView that keeps multiple windows disabled
If an app renders pages using WebViews and handles "new window" navigations in the same window/tab, meaning multiple window support is `false`, it is probably vulnerable. Many apps that implement multiple tabs are affected, because they only allow new tabs to be opened through their own UI and not by pages inside the WebView, so they leave the WebView setting at `false`.
At its simplest, an app is vulnerable if it creates a WebView like this:
```kotlin
class VulnerableActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
val myWebView: WebView = findViewById(R.id.webview)
myWebView.settings.javaScriptEnabled = true
myWebView.loadUrl("https://PARENT_ORIGIN/parent.html")
}
}
```
JavaScript is enabled and the page is loaded over `https://`, and nothing changes the multiple windows setting, which is left at its default.
### Step 2: Load a proof of concept in the target WebView
Navigate the app's WebViews to one of the two PoC URLs:
- PoC 1: https://alesandroortiz.com/security/chromiumwebview/cve-2020-6506.html
- PoC 2: https://alesandroortiz.com/security/chromiumwebview/cve-2020-6506-keypress.html
With these PoCs, the expected behaviour is that the attacker's JavaScript does not execute at all, or executes in an attacker origin. If the app is vulnerable, the observed behaviour is an element added to the top-level document (the target). Depending on the WebView configuration, vulnerable behaviour may also show as an `alert()` dialog with the target origin information.
### Step 3: Trigger the interaction
PoC 1 uses a tap interaction. PoC 2 uses a keypress interaction, where the hidden iframe takes the keystroke while the user types in the top-level document.
{{media:0}}
{{media:1}}
### Step 4: Confirm execution in the top-level document
When testing, do not rely on `alert()` alone. WebViews may not show `alert()` dialog boxes depending on their configuration, so a payload such as `javascript:alert(document.domain)` can produce a false negative. Use a payload that first writes to the top-level document and then tries an `alert()`:
```javascript
javascript:var elem = document.createElement("p"); elem.innerHTML = "<b>Executed JS in parent origin: "+window.location.origin+"</b>"; document.body.append(elem); alert(document.domain)
```
The payload first writes to the top-level document and then tries an `alert()`, so a missing dialog does not hide the result.
### Launch surfaces and nesting
Any iframe on any page inside the vulnerable WebView can perform the attack with minimal user interaction, and the interaction can be unintentional if chained with another bug to steal keyboard focus. Any iframe, visible or hidden, can perform it as long as it can obtain a single user interaction. Hidden iframes can only do so by stealing keyboard input focus; visible iframes can receive a tap/click or keypress, and can also steal focus. The ability to launch from hidden iframes significantly increases the number of potential targets, because hidden iframes are widespread and can take user activations with minimal cooperation from the user.
Attacks work from any iframe regardless of nesting depth: if the malicious iframe sits five iframes deep, `window.open()` or `target="_blank"` still executes code at top level once that iframe obtains user activation, and the keyboard focus theft attack also works at any depth. Launch is possible even in the attacker's worst case where every iframe is on a different origin, for example a top level on `example.com` with iframes nested in `exampleiframe1.com`, `exampleiframe2.com`, `exampleiframe3.com` and so on.
For click activation scenarios, besides display and video ads, common places where visible third-party iframes are likely to get a click from mobile users include video players, in-page chat, comment forms and display, share buttons, documents, and contact or survey forms. If the third party is unscrupulous or has a stored XSS inside the iframe, an attack seems realistic against users of vulnerable browsers and WebViews who browse sites carrying those iframes. Any of these can also combine the keyboard method for greater effectiveness.
## Root cause
With `WebSettings.setSupportMultipleWindows()` at default or `false`, WebView treats a new window with a `javascript:` URL like a new window with an `https://` URL and navigates the top document to it. Because the navigation target is a `javascript:` URL, the script runs in the top document's context, crossing the origin boundary that should have contained the cross-origin iframe. The iframe only needs to call `window.open()` with such a URL; a link with `target="_blank"` and `href="javascript:..."` works too.
Allowing any iframe, including cross-origin ones, to navigate top-level windows to another `https://` URL is intentionally allowed in WebViews for legacy and compatibility reasons. Even after CVE-2020-6506 is fixed, WebViews with this configuration still allow unwanted navigations, which could pose a security risk if the page origin is not safely displayed to the user.
## Impact
In a vast majority of cases the impact is typical for a UXSS: script from an attacker origin runs in the top-level document of whatever page hosts the iframe. In very limited cases the UXSS can be used to access privileged application-exposed APIs, and in very rare cases those APIs allow scoped Remote Code Execution with the privileges of the application. No widely-used production app has been identified as vulnerable to scoped RCE through this UXSS, though the researcher verified it as technically possible. Such privileged APIs are typical in some frameworks, although other security controls and good developer practices make it unusual to find iframes capable of performing the attack inside those privileged pages or WebViews.
Theoretical chained impacts exist only if an appropriate vulnerability is found and chained. A user interaction requirement bypass could in theory make the issue exploitable in drive-by attacks, for example something better than the keyboard method at minimising interactivity. An iframe sandboxing bypass could in theory make it exploitable from sandboxed iframes; crbug.com/845983 is an example of a vulnerability that would have helped bypass iframe sandboxing. As far as the researcher knows, these did not exist recently at the same time as CVE-2020-6506.
## Fix
The vulnerability was fixed in Android WebView 83.0.4103.106 Stable. Users should update Android WebView to that version or higher through the Google Play Store, and keep it updating automatically or regularly to receive other security fixes.
Because users are not guaranteed to be running a patched WebView, apps can and should mitigate for unpatched users. Vendors generally have two choices:
1. Enable multiwindow support. Implementation options exist to mimic single-window behaviour and minimise breaking changes; this does not require a multi-tab UI and suits browsers and frameworks.
2. Keep multiwindow support disabled and strictly limit WebView rendering to trusted content only. This suits non-browser apps, and frameworks when used in non-browser apps.
Apps vulnerable through a dependency, such as a framework, should in most cases update the dependency version, reviewing advisories for breaking changes. For frameworks, mitigation tends to be more complex because of the variety of supported use cases.
As an adjacent phishing mitigation, if the current page URL is not guaranteed to be shown to the user, origin allowlists are recommended. URL filtering is likely to be implemented as part of the UXSS mitigation anyway.
On the website side, iframe sandboxing works as expected to prevent the attack, but common configurations still unexpectedly allow JavaScript from the iframe to execute in the parent document. For example, `sandbox="allow-popups allow-top-navigation allow-scripts"` allows the attack to be performed by the iframe. Similar configurations may also allow it, though the researcher did not test them. Sandboxed iframes should be used for any iframe containing user content or third-party content, and any third-party scripts loaded on the site should also use appropriately sandboxed iframes.
Mitigated vendors listed in the report:
| Vendor | Version | Notes |
| --- | --- | --- |
| React Native WebView (framework component) | 11.0.0 | Mitigation enabled by default |
| Microsoft Xamarin.Forms (framework) | 4.7.0-sr6 and 4.8.0-sr1.2 | Advisory assigned CVE-2020-16873 |
| F-Secure SAFE Browser | 17.8.0114922 | |
| Google Flutter official plugins | webview_flutter 0.3.23, url_launcher 5.7.0 | Only these two official plugins were identified as vulnerable |
| Twitter app | 8.56.0-release.00 | Only WebViews in video website cards were vulnerable |
Pending mitigations: Apache Cordova, where the main app WebView and the InAppBrowser WebView are both vulnerable and using InAppBrowser to render pages does not mitigate. Cordova sets both `WebSettings.setJavaScriptCanOpenWindowsAutomatically()` and `WebSettings.setAllowUniversalAccessFromFileURLs()` to `true`, and when the top-level document is loaded using `file://`, Android WebView does not require user interaction inside a cross-origin iframe to open a new window, so no user interaction is required in the main app WebView. By comparison, WebView requires user interaction if the top-level document is loaded using `https://`, even with automatic window opening enabled. Capacitor by Ionic has issued an advisory and is exploring a built-in mitigation. Trust Wallet (browser) will not mitigate.
## Variants to test
1. **Other WebView-based browsers and apps.** Load the two PoC URLs in any app that renders pages with WebView and keeps multiple windows disabled. A positive result is an element added to the top-level document, or an `alert()` showing the target origin.
2. **Apps with a multi-tab UI.** Check whether new tabs can only be opened through the app's own UI. If so, the WebView setting is likely still `false` and the app is probably vulnerable; a positive result is the same top-level element or dialog.
3. **Hidden iframes with keyboard focus theft.** Place a hidden cross-origin iframe on a page and have the user type in the top-level document. A positive result is the iframe obtaining the keypress activation and executing its `javascript:` URL at top level.
4. **Deeply nested iframes.** Nest the malicious iframe several levels deep, each level on a different origin. A positive result is execution at top level once the innermost iframe obtains activation, which the researcher verified works at any nesting depth.
5. **`target="_blank"` links instead of `window.open()`.** Use a link with `target="_blank"` and `href="javascript:..."` inside the iframe. A positive result is the same top-level execution.
6. **`file://` top-level pages with automatic window opening.** In a WebView that sets both `WebSettings.setJavaScriptCanOpenWindowsAutomatically()` and `WebSettings.setAllowUniversalAccessFromFileURLs()` to `true`, load the top-level page over `file://`. A positive result is execution with no user interaction at all.
7. **Sandboxed iframes.** Try `sandbox="allow-popups allow-top-navigation allow-scripts"` on the iframe. A positive result is JavaScript from the iframe executing in the parent document, which shows the sandbox does not protect the page.
8. **Privileged API reachability.** In apps that expose privileged APIs to WebView content, check whether the injected top-level script can reach them. A positive result is access to an application-exposed API, which in rare cases can extend to scoped RCE with the app's privileges.## What happened, in plain words
Android phones run apps. Many of those apps show web pages inside themselves: a news app showing an article, a shopping app showing a product page, a browser showing any site at all. The piece of Android that draws those web pages is called **Android WebView**. It is a shared component, a bit like a printer driver: many different programs hand it content and let it do the drawing, rather than each writing their own page renderer.
In 2020 a security researcher, Alesandro Ortiz, found a flaw in Android WebView. The flaw let a small piece of a web page, one that comes from a completely different website, run its own code inside the main page. Normally a browser keeps websites apart on purpose, so that a page from one site cannot reach into another. This flaw broke that separation. The class of bug is called **universal cross-site scripting**, or **UXSS** for short, and it was tracked as **CVE-2020-6506**.
The researcher found it while testing more than a dozen Android web browsers. The browsers were not each broken in their own way: the common cause was the WebView underneath them. Because WebView is used by so many apps, the flaw reached far beyond browsers.
Most of the time the result is the usual UXSS outcome: an attacker's script runs in the main page of whatever site the user is looking at. In a small number of apps the script could also reach special features the app exposes to web content, and in very rare cases those features could be abused to run code on the phone with the app's own permissions. The researcher verified that this last step is technically possible, but no widely-used production app has been identified as vulnerable to it.
The article describes the flaw in the present tense, but anyone whose WebView has been updated is no longer affected.
## Android WebView at a glance
To follow the rest, you need one mental picture. An Android app is a program on your phone. Some apps need to show web content, and instead of building their own web page renderer they use the one Android already provides: Android WebView. The app hands WebView a web address, and WebView fetches the page and draws it inside the app's window.
WebView is a **system component**, meaning it is part of the phone's software rather than bundled inside each app. Its version is the version installed on the phone, and it can be updated through the Google Play Store just like a normal app. Modern WebView versions are not tied to the Android operating system version or to when an app was built, so a phone can have an old WebView even if the app itself is new.
Most third-party browsers on Android draw pages with WebViews. That makes WebView an **attack surface**: a part of the system that many programs share and that an attacker can try to influence. A single flaw in WebView can therefore affect all those browsers at once, plus many other apps that show web content.
WebView is built on **Chromium**, the open-source engine behind Google Chrome. You might expect that a flaw fixed in Chrome would also be fixed in WebView. Not always: some attacks that Chrome for Android blocks still work inside WebViews under certain settings. CVE-2020-6506 is one of those.
## CVE-2020-6506 vulnerability details
Here is the heart of the bug. A WebView has a setting called `WebSettings.setSupportMultipleWindows()`. It controls whether the WebView is allowed to open a new window when a page asks for one. If the setting is left at its default, or set to `false`, the WebView does not open a separate window. Instead, when a page asks for a new window, WebView handles it in the same window.
That behaviour is fine for ordinary web addresses. But WebView treats a new window whose address starts with `javascript:` exactly the same way it treats a new window whose address starts with `https://`. In both cases it navigates the main page to the given address. For an `https://` address that means loading a page. For a `javascript:` address it means running the JavaScript that follows the colon, and it runs it in the main page.
That is the escape. A page can contain an **iframe**, which is a web page embedded inside another web page, like a picture frame hanging on a wall. An iframe can come from a different website than the page around it. Normally the browser keeps the iframe's code inside the iframe. Here, the iframe can call `window.open()` with a `javascript:` address, and because of the setting above, that code ends up running in the main page instead. The iframe has crossed the boundary that was supposed to contain it.
There are other ways to ask for a new window. A link with `target="_blank"` and `href="javascript:..."` does the same job, so the attack does not depend on `window.open()` alone.
Opening a new window needs one **user interaction**: a tap or a click, or a keypress. So the attack needs a single activation from the user. The malicious iframe does not have to be visible. It can take the keypress while the user is typing in the main page, without the user ever touching the iframe. The videos below show both variants.
In rare configurations no user interaction is needed at all, which makes it a **drive-by attack**: the user does nothing and the code still runs. For that, the main page must be loaded using the `file://` scheme (a local file on the device rather than a web address), and the WebView must set both `WebSettings.setJavaScriptCanOpenWindowsAutomatically()` and `WebSettings.setAllowUniversalAccessFromFileURLs()` to `true`.
The fix arrived in Android WebView version 83.0.4103.106, released on Monday, June 15th, 2020. Users need at least that version to be fully protected. Apps can and should add their own protections for users who are still on older versions, because there is no guarantee that every phone has been updated.
One related point is worth keeping in mind. Allowing any iframe, including one from another website, to navigate the main window to another `https://` address is deliberately allowed in WebViews for legacy and compatibility reasons. Even after CVE-2020-6506 is fixed, WebViews with this setting still allow unwanted navigations, which can be a security risk if the page's address is not clearly shown to the user.
## Impacts and attack launch surfaces
An **impact** is what an attacker can actually do once the bug is triggered. An **attack launch surface** is the place from which the attack is started, here the iframe.
Confirmed impacts and launch surfaces:
A malicious iframe on any page inside the vulnerable WebView can run a UXSS attack on the main page with minimal user interaction. The interaction can even be unintentional if the attacker chains another bug to steal keyboard focus.
In rare configurations no interaction is needed at all, as described above: the main page must be loaded over `file://` and the WebView must set both `WebSettings.setJavaScriptCanOpenWindowsAutomatically()` and `WebSettings.setAllowUniversalAccessFromFileURLs()` to `true`.
Any iframe, visible or hidden, can perform the attack as long as it can get a single user interaction. Hidden iframes can only do it by stealing keyboard input focus, using behaviour described in crbug.com/622714. Visible iframes can get a tap or click, or a keypress, and can also steal focus.
Being able to launch from hidden iframes matters a lot, because hidden iframes are everywhere and can take a user's activation with very little cooperation from the user. That greatly increases the number of websites that could be targeted.
In some apps the UXSS can be used to reach **privileged APIs**. An **API** (application programming interface) is a set of functions one piece of software offers to another, like a service counter where you can ask for specific things. A privileged API is one that only trusted code is supposed to reach, for example one that can read files or control parts of the phone. Some of those APIs can lead to **Remote Code Execution** (RCE), meaning an attacker gets code of their own to run on the device, here with the app's permissions. This pattern is typical in some frameworks, though other security controls and good developer practice make it unusual to find iframes able to launch the attack inside those privileged pages or WebViews.
For click-based scenarios, besides display and video ads, other common places where visible third-party iframes are likely to get a click from mobile users include video players, in-page chat, comment forms and comment display, share buttons, documents, and contact or survey forms. If the third party is unscrupulous, or has a stored XSS inside the iframe, an attack looks realistic against users of vulnerable browsers and WebViews who browse sites carrying those iframes. Any of these can also be combined with the keyboard method for greater effect.
The researcher verified that attacks work from any iframe regardless of nesting depth. If the malicious iframe sits five iframes deep, `window.open()` or `target="_blank"` still runs code at the top level once that deep iframe gets user activation. The keyboard focus theft attack also works at any depth. Launch is possible even in the attacker's worst case, where every iframe is on a different origin, for example a top level on `example.com` with iframes nested in `exampleiframe1.com`, `exampleiframe2.com`, `exampleiframe3.com` and so on.
Theoretical chained impacts and launch surfaces:
The items below are theoretical. They are possible only if a suitable vulnerability is found and chained with this one. They may have existed in the past and may exist again in the future, but as far as the researcher knows they did not exist recently at the same time as CVE-2020-6506.
If a way to bypass the user interaction requirement is found, it could in theory be chained to make CVE-2020-6506 exploitable in drive-by attacks, for example something better than the keyboard method at reducing how much the user has to do.
If a way to bypass iframe sandboxing is found, it could in theory be chained to make CVE-2020-6506 exploitable from sandboxed iframes. crbug.com/845983 is an example of a vulnerability that would have helped bypass iframe sandboxing.
## How to identify vulnerable apps
If an app draws pages with WebViews and handles "new window" navigations in the same window or tab, meaning multiple window support is `false`, it is probably vulnerable. Surprisingly, many apps that offer multiple tabs are affected, because they only let new tabs be opened through their own interface, not by pages inside the WebView, so they leave the WebView setting at `false`.
At its simplest, an app is vulnerable if it creates a WebView like this:
```kotlin
class VulnerableActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
val myWebView: WebView = findViewById(R.id.webview)
myWebView.settings.javaScriptEnabled = true
myWebView.loadUrl("https://PARENT_ORIGIN/parent.html")
}
}
```
Line by line:
- `class VulnerableActivity : AppCompatActivity() {` declares a screen of the app, called an activity in Android, built on a standard base class. Think of it as one window of the app.
- `override fun onCreate(savedInstanceState: Bundle?) {` is the code that runs when that screen is created. `savedInstanceState` is a bundle of saved state the system may pass in.
- `val myWebView: WebView = findViewById(R.id.webview)` finds the WebView widget on the screen by its identifier and stores it in a variable. This is the frame that will draw the web page.
- `myWebView.settings.javaScriptEnabled = true` switches JavaScript on for pages shown in this WebView. JavaScript is the programming language web pages use to be interactive, and it is also what an attacker's payload is written in.
- `myWebView.loadUrl("https://PARENT_ORIGIN/parent.html")` tells the WebView to load a page over `https://`. `PARENT_ORIGIN` is a placeholder for the site's address.
- The closing braces end the method and the class.
What is missing is the important part. Nothing in this code changes the multiple windows setting, so it stays at its default. JavaScript is on and the page is loaded over `https://`, and that is enough for the flaw to apply.
### Proof of concepts
A **proof of concept** (PoC) is a small, safe demonstration that shows a bug is real. To test an app, navigate its WebViews to these PoC addresses:
- PoC 1: https://alesandroortiz.com/security/chromiumwebview/cve-2020-6506.html
- PoC 2: https://alesandroortiz.com/security/chromiumwebview/cve-2020-6506-keypress.html
With these PoCs, the expected behaviour is that the attacker's JavaScript does not run at all, or runs in the attacker's own origin. If the app is vulnerable, what you see instead is an element added to the main page, the target. Depending on the WebView configuration, the vulnerable behaviour may also show as an `alert()` dialog with the target's origin information. An `alert()` is the small pop-up box a web page can show with a message.
### Pitfalls when testing
A **pitfall** is a trap that makes a test give the wrong answer. Depending on their configuration, WebViews may not show `alert()` dialog boxes at all. So a payload such as `javascript:alert(document.domain)` is not a good test: if the dialog never appears, you might wrongly conclude the app is safe. That wrong conclusion is called a **false negative**: the test says no when the answer is yes.
Instead, use a payload that first writes to the main page and only then tries an `alert()`:
```javascript
javascript:var elem = document.createElement("p"); elem.innerHTML = "<b>Executed JS in parent origin: "+window.location.origin+"</b>"; document.body.append(elem); alert(document.domain)
```
Line by line:
- `javascript:` tells the browser that what follows is JavaScript to run, not a web address to load. This is the same prefix that makes the whole attack possible.
- `var elem = document.createElement("p")` creates a new paragraph element in memory. Nothing is on the page yet.
- `elem.innerHTML = "<b>Executed JS in parent origin: "+window.location.origin+"</b>"` fills that paragraph with bold text saying the script ran in the parent origin, followed by the current page's origin. `window.location.origin` is the site address the script is running in, so the message proves where the code ended up.
- `document.body.append(elem)` adds the paragraph to the page's body. This is the visible proof: if the paragraph appears in the main page, the code ran there.
- `alert(document.domain)` then tries to show a pop-up with the domain. It is a bonus, not the proof, because the pop-up may be suppressed.
The element is added to the main page, which proves execution in the parent origin even if the dialog never appears.
### Difficulties with repro?
**Repro** is short for reproduction: making the bug happen again on demand. The vulnerability appears to start reproducing in or around Android WebView version 76.0.3809.21 Beta / 76.0.3809.89 Stable. If the system runs Android WebView 75 or earlier, it will not reproduce. The flaw was fixed in 83.0.4103.106 Stable, so newer versions will not reproduce either. Mateusz B�
k helped identify the earliest reproducible version.
## Potential mitigations
A **mitigation** is a change that reduces the risk even when the underlying flaw is still present. In an ideal world, users update their system components and apps regularly. In the real world, apps may stay vulnerable because users do not update their WebView for all sorts of reasons. For those users, apps and websites can add protections that keep them safer even on a vulnerable WebView, and that protect websites while they are browsed in vulnerable apps.
### Android applications and frameworks
For Android applications, mitigation is simple in most cases. In others there is a bit more work, but it is feasible overall. For **frameworks**, mitigation tends to be more complex because a framework supports many different use cases. A framework here is a reusable set of code that many apps are built on, like a prefabricated building kit: the app developer assembles their app from it, and a flaw in the kit reaches every app built with it.
For Android applications that are vulnerable because of a dependency, updating the dependency version should be enough in most cases. A **dependency** is another piece of software that your app relies on. Some dependencies' mitigation strategies may introduce breaking changes in certain use cases, so advisories should be reviewed for those. An **advisory** is an official notice from a vendor about a security issue and what to do about it.
Vendors generally have two choices to protect users on unpatched WebViews:
1. Enable multiwindow support. If needed, there are implementation options that mimic single-window behaviour and keep breaking changes small. This does not require a multi-tab interface and suits browsers and frameworks.
2. Keep multiwindow support disabled and strictly limit WebView rendering to trusted content only. This suits non-browser apps, and frameworks when used in non-browser apps.
To keep the article from becoming extremely long, the detailed mitigation options are left out. Anyone who needs the details to mitigate CVE-2020-6506 in an app can send the researcher an email.
There is an adjacent phishing mitigation. **Phishing** is tricking a user into trusting a page that is not what it claims to be. If the current page address is not guaranteed to be shown to the user, origin allowlists are recommended. An **allowlist** is a list of things that are permitted, here a list of origins a page may navigate to. This is an adjacent vulnerability, but it is a good opportunity to fix it because URL filtering is likely to be implemented as part of the UXSS mitigation anyway.
### Websites
**iframe sandboxing** is a way to put an iframe in a restricted box, declared with a `sandbox` attribute, that limits what the embedded page may do. It works as expected to prevent the attack. However, there are common configurations that still unexpectedly let JavaScript from the iframe run in the parent page. For example, using `sandbox="allow-popups allow-top-navigation allow-scripts"` allows the attack to be performed by the iframe. Similar sandbox configurations may also allow it, but the researcher did not test them.
iframe sandboxing has other benefits too, including protection from other existing and future attacks. The recommendation is to use sandboxed iframes for any iframe that contains user content or third-party content, to keep a website from being vulnerable. Any third-party scripts loaded on the site should also use appropriately sandboxed iframes.
### Android Users
Update Android WebView to version 83.0.4103.106 or higher through the Google Play Store. Users should let Android WebView update automatically, or update it regularly, to receive other security fixes and improvements as well.
## Affected vendors
There is a long list of identified affected vendors, and a vast majority of them received a security report within the past few months. Many vendors responded by mitigating the vulnerability for users who may be on unpatched WebView versions. Some vendors are still pending mitigations, and others have not responded with any substantial details about what they intend to do. More vendors will be added to the list as disclosure approvals or disclosure deadlines arrive. **Disclosure** is the process of making a security issue public.
### Mitigated
- React Native WebView (framework component), version 11.0.0
- Advisory published
- 11.0.0 release notes (mitigation enabled by default)
- Microsoft Xamarin.Forms (framework), versions 4.7.0-sr6 and 4.8.0-sr1.2
- Advisory, assigned CVE-2020-16873
- F-Secure SAFE Browser, version 17.8.0114922
- Google Play Store listing
- Google Flutter (framework) official plugins: webview_flutter version 0.3.23, url_launcher version 5.7.0
- Fixed in pull request 2991
- Only these two official plugins were identified as vulnerable.
- Twitter app, version 8.56.0-release.00
- HackerOne public report
- Only WebViews in video website cards were vulnerable.
### Pending mitigations
- Apache Cordova (framework), **drive-by attack**
- Advisory issued. No built-in mitigation available yet.
- The main app WebView and the InAppBrowser WebView are both vulnerable. Using InAppBrowser to render pages does not mitigate.
- **No user interaction required to exploit** in the main app WebView, for two reasons:
1. Cordova sets both `WebSettings.setJavaScriptCanOpenWindowsAutomatically()` and `WebSettings.setAllowUniversalAccessFromFileURLs()` to `true`.
2. If the main page is loaded using the `file://` scheme, Android WebView does not require user interaction inside a cross-origin iframe to open a new window. By comparison, Android WebView does require user interaction if the main page is loaded using `https://`, even when automatic window opening is enabled.
- Capacitor by Ionic (framework)
- Advisory issued. Built-in mitigation being explored.
### Will not mitigate
- Trust Wallet (browser)
There are several vendors pending mitigations, many for reasons outside their control, because a dependency introduced the vulnerability. They will be added under "Mitigated" once they have mitigated and approved disclosure, or if they pass their individual disclosure deadlines without mitigating.
For apps affected through a dependency, the identified dependency vendors have received security reports and are at various stages of response. The vulnerable dependencies are included in the vendor list above. Identified apps that are vulnerable through dependencies will only be listed after they have received a security report and approved disclosure, or passed their individual disclosure deadlines. Those apps have now received a security report, since the dependencies have issued security advisories.
## Videos
### PoC 1: Tap interaction
{{media:0}}
This video shows the first proof of concept, where the attack is triggered by a tap.
### PoC 2: Keypress interaction
{{media:1}}
This video shows the second proof of concept, where the attack is triggered by a keypress while the user types in the main page.
- Vulnerability report submitted to Chromium: https://bugs.chromium.org/p/chromium/issues/detail?id=1083819
- Chrome patch release announcement: https://chromereleases.googleblog.com/2020/06/stable-channel-update-for-desktop_15.html
- iframe keyboard focus theft bug: https://bugs.chromium.org/p/chromium/issues/detail?id=622714
- Android WebView on Google Play Store: https://play.google.com/store/apps/details?id=com.google.android.webview
## Glossary
- **Android WebView**: the Android system component that apps use to draw web pages inside themselves.
- **API (application programming interface)**: a set of functions one piece of software offers to another so it can ask for things to be done.
- **Advisory**: an official vendor notice about a security issue and what to do about it.
- **Allowlist**: a list of things that are explicitly permitted, here a list of origins a page may navigate to.
- **Attack surface**: the parts of a system an attacker can try to influence or abuse.
- **Chromium**: the open-source web engine that Chrome and Android WebView are built on.
- **CVE**: a public identifier given to a known security vulnerability, here CVE-2020-6506.
- **Dependency**: another piece of software that an app relies on to work.
- **Disclosure**: the process of making a security issue public.
- **Drive-by attack**: an attack that runs without the user doing anything.
- **False negative**: a test result that says there is no problem when there actually is one.
- **Framework**: a reusable set of code that many apps are built on, so a flaw in it reaches every app built with it.
- **iframe**: a web page embedded inside another web page.
- **iframe sandboxing**: restricting what an embedded page may do, using the `sandbox` attribute on the iframe.
- **Impact**: what an attacker can actually do once a vulnerability is triggered.
- **JavaScript**: the programming language web pages use to be interactive, and the language of the attack payloads here.
- **Mitigation**: a change that reduces risk even while the underlying flaw is still present.
- **Origin**: the combination of scheme, host and port that identifies a website, for example `https://example.com`.
- **Phishing**: tricking a user into trusting a page that is not what it claims to be.
- **Pitfall**: a trap in testing that can lead to a wrong conclusion.
- **PoC (proof of concept)**: a small, safe demonstration that a bug is real.
- **Privileged API**: an API that only trusted code is supposed to reach, for example one that can read files or control parts of the phone.
- **RCE (Remote Code Execution)**: an attacker getting code of their own to run on a device.
- **Repro (reproduction)**: making a bug happen again on demand.
- **Same-origin policy**: the browser rule that keeps pages from different origins apart so one cannot reach into another.
- **System component**: software that is part of the phone's system rather than bundled inside each app, and that can be updated separately.
- **Third-party iframe**: an iframe whose content comes from a different company or site than the page around it.
- **User interaction / activation**: a tap, click or keypress from the user that the browser requires before allowing certain actions, such as opening a new window.
- **UXSS (universal cross-site scripting)**: a cross-site scripting flaw that is not limited to one site, letting an attacker's script run in the main page of whatever site is being viewed.
- **Vendor**: the company that makes an app, framework or browser.
- **XSS (cross-site scripting)**: a class of flaw where an attacker gets their own script to run inside a page it should not be able to reach.