Skip to content
XSS Disclosed report Advanced CVE-2020-6506

Android WebViews in Twitter app are vulnerable to UXSS due to configuration and CVE-2020-6506

Twitter for Android's WebView configuration for Video Website Cards left multiwindow support disabled, making it vulnerable to CVE-2020-6506. An attacker could embed a malicious iframe in a card's landing page to execute JavaScript in the top-level document and steal or alter data with a single tap or keypress.

alesandroortiz Follow

Originally disclosed on HackerOne

Bounty$560 High 8.1 View original
  • Triaged in 3 days
  • Fixed in 43 days
  • Paid in 34 days
  • Disclosed after 3 months

Summary by the researcher

More details on CVE-2020-6506 available at: https://alesandroortiz.com/articles/uxss-android-webview-cve-2020-6506/

The report

Summary:

CVSS score: 8.1 / High / CVSS:3.0/AV:N/AC:L/PR:N/UI:R/S:U/C:H/I:H/A:N

Embargo notice: Do Not Disclose publicly until https://crbug.com/1083819 is disclosed.

Twitter for Android is affected by a UXSS vulnerability due to its configuration of Android WebView and CVE-2020-6506.

Vendor mitigation is recommended to protect unpatched WebView users, due to its impact and ease of exploitation. Mitigation options which minimize breaking changes are provided for various use cases.

Android WebView is the system component which allows Android apps to display web pages. Apps typically use Android WebView directly or via frameworks/libraries.

CVE-2020-6506 is a universal cross-site scripting (UXSS) vulnerability in Android WebView which allows cross-origin iframes to execute arbitrary JavaScript in the top-level document. This vulnerability affects vendors which use Android WebView with a default configuration setting, and run on systems with Android WebView version prior to 83.0.4103.106.

All relevant details to understand and mitigate the vulnerability should be in this report. As an affected vendor, you may request access to the restricted crbug for full details and discussion, subject to acceptance by the Chromium Security Team. To request access, send me an email.

CVE-2020-6506 Details:

Embargo notice: Do Not Disclose publicly until https://crbug.com/1083819 is disclosed.

An Android WebView instance with WebSettings.setSupportMultipleWindows() kept at default or set to false allows an iframe on a different origin bypass same-origin policies and execute arbitrary JavaScript in the top document.

To perform the attack, an iframe can call window.open() with a javascript: URL. Other methods of opening a new window, such as a link with target=”_blank” and href=”javascript:...”, can also be used to perform the attack.

Performing the attack requires a single user interaction (a tap/click or a keypress). The malicious iframe does not need to be visible, and can obtain the keypress interaction while a user attempts to type in the top-level document (no direct iframe interaction required).

The patched version of Android WebView (83.0.4103.106) was released on Monday, June 15th, 2020: https://chromereleases.googleblog.com/2020/06/stable-channel-update-for-desktop_15.html

Vendors can and should mitigate CVE-2020-6506 to protect their users using unpatched Android WebView versions.

Vendor Details:

Twitter for Android uses WebViews to render the URL in Video Website Cards. This type of Card uses the vulnerable WebView configuration, therefore there's two ways a user can reach the vulnerable WebView:

  1. Advertiser creates legitimate Video Website Card pointing to the advertiser URL, then shares it via regular Tweets or paid advertising campaigns.
  2. Attacker creates Video Website Card with the user-trusted target URL, then shares it via regular Tweets or paid advertising campaigns.

If the advertiser/target URL has a malicious or compromised iframe, the iframe can perform the UXSS attack with minimal user interaction (tap/click or keypress). If there's sensitive data in the WebView, it is vulnerable to exfiltration. Page contents and data can also be altered to benefit the attacker, such as requesting sensitive info from the user while purporting to be the advertiser/target URL.

Based on Twitter's use case, the suggested solution is option 1a or 1b. The final determination is left to the vendor. Reference implementations for each option is available by request.

If none of these options appear suitable, please provide feedback to address concerns. Other vendors could have the same concerns, so your input is appreciated to best mitigate for all affected vendors.

Potential Solutions:

Vendors generally have two choices to mitigate for unpatched WebView users:

  1. Enable multiwindow support. If needed, implementation options exist to mimic single-window behavior and minimize breaking changes. Does not require multi-tab UI. Suitable for browsers and frameworks.
  2. Keep multiwindow support disabled, and strictly limit WebView rendering to trusted content only. Suitable for non-browser apps, and for frameworks when used in non-browser apps.

Detailed choices:

  • Option 1a: Enable multiwindow support, and create a new tab in UI or block window creation.

    • Suitable and preferred choice for browsers.
    • Implementation: Set WebSettings.setSupportMultipleWindows() to true, and handle onCreateWindow() callback to create new tab in UI or block window creation.
    • Potential downsides: If all window creation is blocked, user experience may be negative.
  • Option 1b: Enable multiwindow support, and mimic single-window behavior via WebView instance replacement.

    • Suitable for browsers and frameworks. Preferred choice for frameworks.
    • Potential implementation: Set WebSettings.setSupportMultipleWindows() to true, and handle onCreateWindow() callback to create a new WebView on top of existing WebView. Rebind any event listeners, state info, and other logic to the new WebView. Finally, destroy the old WebView as soon as possible.
    • Potential downsides: May cause breaking changes if existing code expects a single WebView instance for duration of use. To minimize breaking changes, vendor could add an abstraction layer to internally track WebView instances. The abstraction could perform necessary setup/cleanup for each instance to maintain current WebView behavior (such as JS injection on first page load or each page load, event listeners, state, etc.). The abstraction layer could then seamlessly provide existing interfaces to other layers.
  • Option 1c: Enable multiwindow support, and mimic single-window behavior via WebView instance reuse.

    • Suitable for browsers and frameworks.
    • Only if Option 1b is not feasible, and existing code expects a single WebView instance for duration of use. Minimizes breaking changes at the cost of complexity and fragility.
    • Potential implementation: Set WebSettings.setSupportMultipleWindows() to true, and handle onCreateWindow() callback. In the callback, create a temporary WebView with shouldOverrideUrlLoading() which returns true (prevents loading) and stores the attempted URL in a variable. Filter the attempted URL to ensure it is a safe HTTP(S) URL, then call loadUrl() on the initial WebView with the attempted URL. Finally, destroy the temporary WebView when convenient.
    • Potential downsides: May still cause breaking changes. May break if Android WebView behavior changes in future. Adds complexity which may be difficult to maintain.
  • Option 2: Keep multiwindow support disabled, and enforce strict origin allowlist.

    • Suitable for non-browser apps, and for frameworks when used in non-browser apps.
    • Because the vulnerability is not mitigated with this option, WebViews must only render first-party trusted content in top-level window and iframes. If using cross-origin iframes, they must be properly sandboxed. Cross-origin iframes must avoid sandbox="allow-popups allow-top-navigation allow-scripts" because this allows exploitation.
    • Potential downsides: Any bypass of origin filtering allows exploitation of unpatched WebView users. For frameworks with configurable origin allowlists, developers can misconfigure allowlists and make their apps vulnerable.

Adjacent phishing mitigation: If the current page URL is not guaranteed to be shown to the user, origin allowlists are recommended to mitigate phishing risks. This is an adjacent vulnerability, but it's a good opportunity to mitigate it because URL filtering is likely to be implemented as part of the UXSS mitigation.

Additional implementation details for options 1a and 1b: When using multiple WebView instances simultaneously, ensure to destroy the background WebView, unload the background page, or handle background page events safely. Otherwise, background pages can perform actions which should only be allowed by a foreground page, which often cause other security issues.

Environment:

Device: Samsung Galaxy S10 + Emulated Android device OS version: Android 10 (on both devices) Twitter version: 8.50.0-release.02

Steps To Reproduce:

Prerequisites:

Steps To Reproduce, tap/click interaction, visible iframe:

  1. Using the PoC 1 Card, navigate to https://alesandroortiz.com/security/chromiumwebview/cve-2020-6506.html
  2. Tap/click iframe.

Steps To Reproduce, keypress interaction, hidden iframe:

  1. Using the PoC 2 Card, navigate to https://alesandroortiz.com/security/chromiumwebview/cve-2020-6506-keypress-2.html
  2. Tap the "search this site" input field to focus it. (This input field is in the parent page, not the iframe.)
  3. Start typing. Before/while you type, the focus will be stolen by the hidden iframe. After typing a character while the iframe input is focused, the attack is immediately performed. (This can be made more subtle by delaying the focus theft, see code comments.)

Expected Behavior: JavaScript is not executed in top-level document. HTML is not written to top-level document and JS alert dialog is not shown (or a JS alert dialog is shown but with info from iframe document).

Observed Behavior: JavaScript is executed in top-level document. HTML is written to top-level document, and if the WebView allows JS alert dialogs, a JS alert dialog is also shown with info from top-level document.

Supporting Material/References:

  • twitter-cve-2020-6506.mp4: Screen recording of both reproduction cases.
  • Twitter-CVE-2020-6506-Report.pdf: Original report in PDF, in case any formatting is missing or difficult to parse in HackerOne.

Embargo notice: Do Not Disclose publicly until https://crbug.com/1083819 is disclosed.

Impact

A malicious iframe on any page within the vulnerable WebView can perform a UXSS attack on the top-level document with minimal user interaction.

Attachments

twitter-cve-2020-6506.mp4 From the original on HackerOne

The original report as published on HackerOne, by alesandroortiz. Images and videos are our own copies; raw HTML is shown as text. View it on HackerOne.

Written with AI from the full original report and checked against it passage by passage; anything it could not back up was removed or toned down. The original is the record. 9 min read.

Context

Twitter for Android renders certain content inside Android WebView, the system component that lets Android apps display web pages. Apps use it directly or through frameworks and libraries. In this case, the researcher found that Twitter for Android uses WebViews to render the URL in Video Website Cards, and that this particular WebView is configured in a way that leaves it exposed to CVE-2020-6506, a universal cross-site scripting (UXSS) flaw in Android WebView.

CVE-2020-6506 allows a cross-origin iframe to execute arbitrary JavaScript in the top-level document. It affects vendors that use Android WebView with a default configuration setting and run on systems with an Android WebView version prior to 83.0.4103.106. The patched version was released on Monday, 15 June 2020.

The report was filed under an embargo: it was not to be disclosed publicly until the Chromium bug at https://crbug.com/1083819 was disclosed. More details on CVE-2020-6506 are available at https://alesandroortiz.com/articles/uxss-android-webview-cve-2020-6506/.

Setup

The reproduction environment was:

Item Value
Device Samsung Galaxy S10 + emulated Android device
OS version Android 10 (on both devices)
Twitter version 8.50.0-release.02

Preconditions for the attack:

  • A system with an unpatched Android WebView, prior to version 83.0.4103.106.
  • A Twitter Video Website Card whose landing URL points to a proof-of-concept URL. This provides a WebView with WebSettings.setSupportMultipleWindows() kept at its default or set to false.

The researcher supplied two PoC cards:

Finding it

The core of the issue is a WebView configuration detail. An Android WebView instance with WebSettings.setSupportMultipleWindows() kept at default or set to false allows an iframe on a different origin to bypass same-origin policies and execute arbitrary JavaScript in the top document.

To perform the attack, an iframe can call window.open() with a javascript: URL. Other methods of opening a new window, such as a link with target="_blank" and href="javascript:...", can also be used.

The attack requires a single user interaction: a tap/click or a keypress. The malicious iframe does not need to be visible. It can obtain the keypress interaction while a user attempts to type in the top-level document, with no direct iframe interaction required.

In Twitter for Android, the vulnerable WebView is reached through Video Website Cards. There are two ways a user can get there:

  1. An advertiser creates a legitimate Video Website Card pointing to the advertiser URL, then shares it via regular Tweets or paid advertising campaigns.
  2. An attacker creates a Video Website Card with the user-trusted target URL, then shares it via regular Tweets or paid advertising campaigns.

If the advertiser or target URL has a malicious or compromised iframe, that iframe can perform the UXSS attack with minimal user interaction.

Exploitation

Step 1: Reach the vulnerable WebView through a Video Website Card

Using the PoC 1 Card, navigate to:

Text
https://alesandroortiz.com/security/chromiumwebview/cve-2020-6506.html

Twitter for Android uses this WebView to render the URL in Video Website Cards. That WebView keeps WebSettings.setSupportMultipleWindows() at its default or false, which is the condition CVE-2020-6506 needs.

Step 2: Trigger the attack with a tap or click (visible iframe)

With the PoC 1 page loaded, tap or click the iframe. Tap or click the iframe.

Step 3: Trigger the attack with a keypress (hidden iframe)

Using the PoC 2 Card, navigate to:

Text
https://alesandroortiz.com/security/chromiumwebview/cve-2020-6506-keypress-2.html

Then:

  1. Tap the "search this site" input field to focus it. This input field is in the parent page, not the iframe.
  2. Start typing. Before or while you type, the focus is stolen by the hidden iframe. After typing a character while the iframe input is focused, the attack is immediately performed.

The researcher notes that this can be made more subtle by delaying the focus theft, as described in the code comments on the page.

Expected versus observed behaviour

Expected behaviour: JavaScript is not executed in the top-level document. HTML is not written to the top-level document, and a JS alert dialog is not shown (or a JS alert dialog is shown but with information from the iframe document).

Observed behaviour: JavaScript is executed in the top-level document. HTML is written to the top-level document, and if the WebView allows JS alert dialogs, a JS alert dialog is also shown with information from the top-level document.

Supporting material

The researcher attached a screen recording of both reproduction cases, twitter-cve-2020-6506.mp4, and the original report as a PDF, Twitter-CVE-2020-6506-Report.pdf, in case any formatting was missing or difficult to parse on the platform.

twitter-cve-2020-6506.mp4 From the original on HackerOne

Root cause

The mistake is in the app's WebView configuration rather than in Twitter's own server-side code. Twitter for Android renders the URL in Video Website Cards in a WebView that leaves WebSettings.setSupportMultipleWindows() at its default or sets it to false. Combined with an unpatched Android WebView, that setting lets a cross-origin iframe escape the same-origin policy and run script in the top-level document, for example by calling window.open() with a javascript: URL or by using a link with target="_blank" and a javascript: href.

The report recommends vendor mitigation to protect users on unpatched WebView versions.

Impact

A malicious iframe on any page within the vulnerable WebView can perform a UXSS attack on the top-level document with minimal user interaction. If there is sensitive data in the WebView, it is vulnerable to exfiltration. Page contents and data can also be altered to benefit the attacker, for example by requesting sensitive information from the user while purporting to be the advertiser or target URL.

The CVSS score given in the report is 8.1, High, with the vector CVSS:3.0/AV:N/AC:L/PR:N/UI:R/S:U/C:H/I:H/A:N, which reflects the required user interaction.

Fix

The report recommends vendor mitigation to protect users on unpatched WebView versions, given the impact and ease of exploitation, and offers options that minimise breaking changes. 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 is suitable for browsers and frameworks.
  2. Keep multiwindow support disabled, and strictly limit WebView rendering to trusted content only. This is suitable for non-browser apps, and for frameworks when used in non-browser apps.

The detailed options are:

  • Option 1a: Enable multiwindow support, and create a new tab in the UI or block window creation. This is suitable and preferred for browsers. Implementation: set WebSettings.setSupportMultipleWindows() to true, and handle the onCreateWindow() callback to create a new tab in the UI or block window creation. Potential downside: if all window creation is blocked, user experience may be negative.
  • Option 1b: Enable multiwindow support, and mimic single-window behaviour via WebView instance replacement. This is suitable for browsers and frameworks, and preferred for frameworks. Potential implementation: set WebSettings.setSupportMultipleWindows() to true, and handle the onCreateWindow() callback to create a new WebView on top of the existing WebView. Rebind any event listeners, state information and other logic to the new WebView, then destroy the old WebView as soon as possible. Potential downside: may cause breaking changes if existing code expects a single WebView instance for the duration of use. To minimise breaking changes, the vendor could add an abstraction layer that internally tracks WebView instances and performs the necessary setup and cleanup for each one, such as JS injection on first page load or each page load, event listeners and state, while seamlessly providing existing interfaces to other layers.
  • Option 1c: Enable multiwindow support, and mimic single-window behaviour via WebView instance reuse. This is suitable for browsers and frameworks, but only if Option 1b is not feasible and existing code expects a single WebView instance for the duration of use. It minimises breaking changes at the cost of complexity and fragility. Potential implementation: set WebSettings.setSupportMultipleWindows() to true, and handle the onCreateWindow() callback. In the callback, create a temporary WebView with shouldOverrideUrlLoading() that returns true (preventing loading) and stores the attempted URL in a variable. Filter the attempted URL to ensure it is a safe HTTP(S) URL, then call loadUrl() on the initial WebView with the attempted URL. Finally, destroy the temporary WebView when convenient. Potential downsides: may still cause breaking changes, may break if Android WebView behaviour changes in future, and adds complexity that may be difficult to maintain.
  • Option 2: Keep multiwindow support disabled, and enforce a strict origin allowlist. Because the vulnerability is not mitigated with this option, WebViews must only render first-party trusted content in the top-level window and iframes. If cross-origin iframes are used, they must be properly sandboxed, and they must avoid sandbox="allow-popups allow-top-navigation allow-scripts" because that allows exploitation. Potential downsides: any bypass of origin filtering allows exploitation of unpatched WebView users, and for frameworks with configurable origin allowlists, developers can misconfigure the allowlists and make their apps vulnerable.

Based on Twitter's use case, the researcher suggested option 1a or 1b, leaving the final determination to the vendor. Reference implementations for each option were available on request.

Two further notes from the report:

  • Adjacent phishing mitigation: if the current page URL is not guaranteed to be shown to the user, origin allowlists are recommended to mitigate phishing risks. This is an adjacent vulnerability, but a good opportunity to mitigate it because URL filtering is likely to be implemented as part of the UXSS mitigation.
  • Additional implementation details for options 1a and 1b: when using multiple WebView instances simultaneously, ensure the background WebView is destroyed, the background page is unloaded, or background page events are handled safely. Otherwise, background pages can perform actions that should only be allowed by a foreground page, which often causes other security issues.

Variants to test

  • Other apps that render third-party URLs in a WebView. Look for any feature that loads advertiser, publisher or user-supplied URLs, such as cards, in-app browsers or embedded content. A positive result is a page whose cross-origin iframe can run script in the top-level document after a single tap or keypress on an unpatched WebView.
  • Hidden-iframe keypress theft. Load a page with a visible input in the parent document and a hidden iframe that steals focus. A positive result is that typing a character while the iframe holds focus triggers the attack, with no direct interaction with the iframe.
  • Alternative window-opening methods. Besides window.open() with a javascript: URL, try a link with target="_blank" and a javascript: href. A positive result is the same top-level script execution.
  • Frameworks with configurable origin allowlists. Check whether the allowlist can be bypassed or misconfigured. A positive result is a cross-origin iframe that still reaches the vulnerable WebView despite the allowlist.
  • Multiple simultaneous WebView instances. Where a fix uses instance replacement or reuse, check whether background pages can still perform actions reserved for foreground pages. A positive result is a background page triggering privileged behaviour.

Hunting notes

This class of bug hides in apps that embed web content rather than in the web application itself. The signal during recon is a feature that loads a URL the app does not fully control, such as advertising cards, in-app browsers or embedded article views, combined with a device running an Android WebView older than 83.0.4103.106. The configuration to look for is WebSettings.setSupportMultipleWindows() left at its default or set to false.

The report gives reproduction steps for a visible-iframe tap/click case and a hidden-iframe keypress case, with expected versus observed behaviour, and attaches a screen recording of both cases. The report also gave the vendor concrete mitigation options with their trade-offs.

Written with AI from the full original report and checked against it passage by passage; anything it could not back up was removed or toned down. The original is the record. 17 min read.

What happened, in plain words

Twitter for Android is the phone app that lets you read and post tweets. Some tweets contain a special kind of advertisement called a Video Website Card: a tweet with a picture or video and a link to a website. Twitter for Android uses a built-in browser window, called an Android WebView, to render the URL in Video Website Cards. That built-in window is called an Android WebView.

A WebView is a piece of software that Android provides to every app. It is a browser engine without the browser around it: an app can put a rectangle on the screen and tell it to show a web page. Many apps use it for in-app browsers, help pages, ads and embedded articles.

The researcher found that Twitter for Android set up this WebView in a way that leaves it open to a known bug in Android WebView itself, tracked as CVE-2020-6506. The bug is a universal cross-site scripting flaw, or UXSS. Cross-site scripting means getting your own JavaScript (the programming language web pages use to make things happen) to run inside a page where it should not run. Universal means it is not limited to one site: a page from one website can run code in a page from a completely different website.

Normally a web page is not allowed to touch another website's page. That rule is called the same-origin policy, and it is one of the main walls that keeps websites apart. CVE-2020-6506 breaks that wall inside Android WebView when a particular setting is left at its default value. The result is that a small embedded frame from an attacker's site can run code in the main page the user is looking at, and can read or change what is there.

The researcher reported this to Twitter through the HackerOne bug bounty platform. The report was filed under an embargo: it was not to be disclosed publicly until the Chromium bug at https://crbug.com/1083819 was disclosed. More details on CVE-2020-6506 are available at https://alesandroortiz.com/articles/uxss-android-webview-cve-2020-6506/.

The report gives a CVSS score of 8.1, High, with the vector CVSS:3.0/AV:N/AC:L/PR:N/UI:R/S:U/C:H/I:H/A:N. CVSS is a standard way of scoring how serious a security bug is. The vector is a compact string that records the reasoning behind the score; the UI:R part means the attacker needs the user to do something, such as tap or type.

Setup

The researcher reproduced the problem on this environment:

Item Value
Device Samsung Galaxy S10 + emulated Android device
OS version Android 10 (on both devices)
Twitter version 8.50.0-release.02

An emulated Android device is a phone simulated in software on a computer, so the same test can be repeated without a second physical handset.

Two things had to be true before the attack could work:

  • The phone had to run an unpatched Android WebView, meaning a version older than 83.0.4103.106.
  • A Twitter Video Website Card had to exist whose landing URL (the address the card links to) points to a proof-of-concept page. A proof-of-concept, or PoC, is a small demonstration page built only to show that a bug is real. Loading it inside the app gives you a WebView where WebSettings.setSupportMultipleWindows() is kept at its default or set to false.

WebSettings is the part of the Android programming interface that controls how a WebView behaves, and setSupportMultipleWindows() is one switch on it. The name suggests it only decides whether a page may open extra windows. The bug is that leaving this switch off allows a cross-origin iframe to bypass same-origin policies.

The researcher supplied two PoC cards:

Finding it

The heart of the issue is a configuration detail, not a mistake in Twitter's servers. An Android WebView instance with WebSettings.setSupportMultipleWindows() kept at default or set to false allows an iframe on a different origin to bypass same-origin policies and execute arbitrary JavaScript in the top document.

An iframe is a page inside a page: a rectangle within a web page that loads content from another address. The top document is the main page around it. An origin is the combination of scheme, host and port, for example https://example.com on the standard port; two pages share an origin only if all three match. The same-origin policy is the browser rule that stops a page from one origin reading or changing a page from another origin. Bypassing it means that rule no longer holds.

To perform the attack, an iframe can call window.open() with a javascript: URL. Other methods of opening a new window, such as a link with target="_blank" and href="javascript:...", can also be used.

window.open() is the JavaScript function that asks the browser to open a new window or tab. A javascript: URL is an address that, instead of pointing at a page, contains code to run. target="_blank" on a link tells the browser to open the destination in a new tab. In a healthy browser, code in a javascript: URL runs in the context of the page that navigates to it, not in the top document of another origin. Here the WebView gets that wrong and runs the code in the top document.

The attack requires a single user interaction: a tap/click or a keypress. The malicious iframe does not need to be visible. It can obtain the keypress interaction while a user attempts to type in the top-level document, with no direct iframe interaction required.

That last point matters. A user does not have to tap anything suspicious. They only have to tap a normal text field and start typing, and the hidden frame can take the keystroke for itself.

In Twitter for Android, the vulnerable WebView is reached through Video Website Cards. There are two ways a user can get there:

  1. An advertiser creates a legitimate Video Website Card pointing to the advertiser URL, then shares it via regular Tweets or paid advertising campaigns.
  2. An attacker creates a Video Website Card with the user-trusted target URL, then shares it via regular Tweets or paid advertising campaigns.

In the second route, an attacker creates a Video Website Card with the user-trusted target URL.

If the advertiser or target URL has a malicious or compromised iframe, that iframe can perform the UXSS attack with minimal user interaction. A compromised site is a legitimate site that someone else has managed to plant code on, which is why even a trusted advertiser's page can be the entry point.

Exploitation

Step 1: Reach the vulnerable WebView through a Video Website Card

Using the PoC 1 Card, navigate to:

Text
https://alesandroortiz.com/security/chromiumwebview/cve-2020-6506.html

Using the PoC 1 Card, navigate to this address. That WebView keeps WebSettings.setSupportMultipleWindows() at its default or false, which is the condition CVE-2020-6506 needs.

Step 2: Trigger the attack with a tap or click (visible iframe)

With the PoC 1 page loaded, tap or click the iframe. Tap or click the iframe.

The attack requires a single user interaction, and the iframe does not need to be visible.

Step 3: Trigger the attack with a keypress (hidden iframe)

Using the PoC 2 Card, navigate to:

Text
https://alesandroortiz.com/security/chromiumwebview/cve-2020-6506-keypress-2.html

Then:

  1. Tap the "search this site" input field to focus it. This input field is in the parent page, not the iframe.
  2. Start typing. Before or while you type, the focus is stolen by the hidden iframe. After typing a character while the iframe input is focused, the attack is immediately performed.

Focus is simply which element on a page receives your keystrokes. The page shows a normal search box, the user taps it, and the hidden frame quietly takes the focus away. The next character typed goes to the frame instead of the box, and that keystroke is the user interaction the bug needs.

The researcher notes that this can be made more subtle by delaying the focus theft, as described in the code comments on the page. A delay makes the switch harder for a person to notice.

Expected versus observed behaviour

Expected behaviour: JavaScript is not executed in the top-level document. HTML is not written to the top-level document, and a JS alert dialog is not shown (or a JS alert dialog is shown but with information from the iframe document).

Observed behaviour: JavaScript is executed in the top-level document. HTML is written to the top-level document, and if the WebView allows JS alert dialogs, a JS alert dialog is also shown with information from the top-level document.

HTML is the markup language that describes what a page contains. A JS alert dialog is the small pop-up box a page can show with a message. Writing HTML into the top document means the attacker can replace what the user sees; an alert carrying information from the top document proves the frame could read the main page, not just its own.

Supporting material

The researcher attached a screen recording of both reproduction cases, twitter-cve-2020-6506.mp4, and the original report as a PDF, Twitter-CVE-2020-6506-Report.pdf, in case any formatting was missing or difficult to parse on the platform.

twitter-cve-2020-6506.mp4 From the original on HackerOne

The recording shows both reproduction cases.

Root cause

The mistake is in the app's WebView configuration rather than in Twitter's own server-side code. Twitter for Android renders the URL in Video Website Cards in a WebView that leaves WebSettings.setSupportMultipleWindows() at its default or sets it to false. Combined with an unpatched Android WebView, that setting lets a cross-origin iframe escape the same-origin policy and run script in the top-level document, for example by calling window.open() with a javascript: URL or by using a link with target="_blank" and a javascript: href.

The report recommends vendor mitigation to protect users on unpatched WebView versions.

Impact

A malicious iframe on any page within the vulnerable WebView can perform a UXSS attack on the top-level document with minimal user interaction. If there is sensitive data in the WebView, it is vulnerable to exfiltration. Exfiltration means the attacker's code copies that data out to a server they control. Page contents and data can also be altered to benefit the attacker, for example by requesting sensitive information from the user while purporting to be the advertiser or target URL.

The CVSS score given in the report is 8.1, High, with the vector CVSS:3.0/AV:N/AC:L/PR:N/UI:R/S:U/C:H/I:H/A:N, which reflects the required user interaction.

Fix

The report recommends vendor mitigation to protect users on unpatched WebView versions, given the impact and ease of exploitation, and offers options that minimise breaking changes. A breaking change is a fix that forces other parts of the app to be rewritten because they relied on the old behaviour. 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 is suitable for browsers and frameworks.
  2. Keep multiwindow support disabled, and strictly limit WebView rendering to trusted content only. This is suitable for non-browser apps, and for frameworks when used in non-browser apps.

A framework here is a reusable set of code that many apps build on, so a fix there reaches every app that uses it. An origin allowlist is a list of web addresses the app is permitted to load; anything not on the list is refused.

The detailed options are:

  • Option 1a: Enable multiwindow support, and create a new tab in the UI or block window creation. This is suitable and preferred for browsers. Implementation: set WebSettings.setSupportMultipleWindows() to true, and handle the onCreateWindow() callback to create a new tab in the UI or block window creation. Potential downside: if all window creation is blocked, user experience may be negative. A callback is a function the system calls for you when something happens; onCreateWindow() fires when a page asks for a new window, giving the app a chance to decide what to do.
  • Option 1b: Enable multiwindow support, and mimic single-window behaviour via WebView instance replacement. This is suitable for browsers and frameworks, and preferred for frameworks. Potential implementation: set WebSettings.setSupportMultipleWindows() to true, and handle the onCreateWindow() callback to create a new WebView on top of the existing WebView. Rebind any event listeners, state information and other logic to the new WebView, then destroy the old WebView as soon as possible. Potential downside: may cause breaking changes if existing code expects a single WebView instance for the duration of use. To minimise breaking changes, the vendor could add an abstraction layer that internally tracks WebView instances and performs the necessary setup and cleanup for each one, such as JS injection on first page load or each page load, event listeners and state, while seamlessly providing existing interfaces to other layers. An event listener is code that waits for something to happen, such as a tap; an abstraction layer is a piece of code that hides complexity behind a simple interface so the rest of the app does not need to change.
  • Option 1c: Enable multiwindow support, and mimic single-window behaviour via WebView instance reuse. This is suitable for browsers and frameworks, but only if Option 1b is not feasible and existing code expects a single WebView instance for the duration of use. It minimises breaking changes at the cost of complexity and fragility. Potential implementation: set WebSettings.setSupportMultipleWindows() to true, and handle the onCreateWindow() callback. In the callback, create a temporary WebView with shouldOverrideUrlLoading() that returns true (preventing loading) and stores the attempted URL in a variable. Filter the attempted URL to ensure it is a safe HTTP(S) URL, then call loadUrl() on the initial WebView with the attempted URL. Finally, destroy the temporary WebView when convenient. Potential downsides: may still cause breaking changes, may break if Android WebView behaviour changes in future, and adds complexity that may be difficult to maintain. shouldOverrideUrlLoading() is a hook that lets the app inspect a URL before the WebView loads it and say yes or no; returning true means "do not load it".
  • Option 2: Keep multiwindow support disabled, and enforce a strict origin allowlist. Because the vulnerability is not mitigated with this option, WebViews must only render first-party trusted content in the top-level window and iframes. If cross-origin iframes are used, they must be properly sandboxed, and they must avoid sandbox="allow-popups allow-top-navigation allow-scripts" because that allows exploitation. A sandbox is an attribute on an iframe that restricts what the frame may do; the listed permissions would let it open windows, navigate the top page and run scripts, which is exactly the combination the attack needs. Potential downsides: any bypass of origin filtering allows exploitation of unpatched WebView users, and for frameworks with configurable origin allowlists, developers can misconfigure the allowlists and make their apps vulnerable.

Based on Twitter's use case, the researcher suggested option 1a or 1b, leaving the final determination to the vendor. Reference implementations for each option were available on request.

Two further notes from the report:

  • Adjacent phishing mitigation: if the current page URL is not guaranteed to be shown to the user, origin allowlists are recommended to mitigate phishing risks. This is an adjacent vulnerability, but a good opportunity to mitigate it because URL filtering is likely to be implemented as part of the UXSS mitigation. Phishing is tricking a user into trusting a page that imitates a real one; showing or restricting the address helps users spot it.
  • Additional implementation details for options 1a and 1b: when using multiple WebView instances simultaneously, ensure the background WebView is destroyed, the background page is unloaded, or background page events are handled safely. Otherwise, background pages can perform actions that should only be allowed by a foreground page, which often causes other security issues.

Variants to test

  • Other apps that render third-party URLs in a WebView. Look for any feature that loads advertiser, publisher or user-supplied URLs, such as cards, in-app browsers or embedded content. A positive result is a page whose cross-origin iframe can run script in the top-level document after a single tap or keypress on an unpatched WebView.
  • Hidden-iframe keypress theft. Load a page with a visible input in the parent document and a hidden iframe that steals focus. A positive result is that typing a character while the iframe holds focus triggers the attack, with no direct interaction with the iframe.
  • Alternative window-opening methods. Besides window.open() with a javascript: URL, try a link with target="_blank" and a javascript: href. A positive result is the same top-level script execution.
  • Frameworks with configurable origin allowlists. Check whether the allowlist can be bypassed or misconfigured. A positive result is a cross-origin iframe that still reaches the vulnerable WebView despite the allowlist.
  • Multiple simultaneous WebView instances. Where a fix uses instance replacement or reuse, check whether background pages can still perform actions reserved for foreground pages. A positive result is a background page triggering privileged behaviour.

Hunting notes

This class of bug hides in apps that embed web content rather than in the web application itself. The signal during recon is a feature that loads a URL the app does not fully control, such as advertising cards, in-app browsers or embedded article views, combined with a device running an Android WebView older than 83.0.4103.106. Recon means the early look around a target to see what it is made of. The configuration to look for is WebSettings.setSupportMultipleWindows() left at its default or set to false.

The report gives reproduction steps for a visible-iframe tap/click case and a hidden-iframe keypress case, with expected versus observed behaviour, and attaches a screen recording of both cases. The report also gave the vendor concrete mitigation options with their trade-offs.

Glossary

  • Android WebView: the browser engine component that Android provides so apps can display web pages inside themselves.
  • API: a defined set of functions one piece of software offers to another so they can talk to each other.
  • Breaking change: a fix or update that forces other code to be rewritten because it relied on the old behaviour.
  • Callback: a function the system calls for you when a particular event happens.
  • Compromised site: a legitimate website that an attacker has managed to plant code on.
  • Cookie: a small piece of data a site stores in the browser to remember who you are between requests.
  • Cross-origin iframe: a frame inside a page that loads content from a different origin than the page around it.
  • Cross-site scripting (XSS): getting attacker-supplied JavaScript to run inside a page where it should not run.
  • CVE: a public identifier for a known security vulnerability, so people can refer to the same bug unambiguously.
  • CVSS: a standard scoring system for the severity of a security vulnerability, with a vector string recording the reasoning.
  • Emulated device: a phone simulated in software on a computer.
  • Event listener: code that waits for something to happen, such as a tap or a keypress, and then reacts.
  • Exfiltration: copying data out of a system to a place the attacker controls.
  • Focus: which element on a page currently receives your keystrokes.
  • Framework: a reusable set of code that many apps are built on, so a fix there reaches every app using it.
  • HTML: the markup language that describes the content and structure of a web page.
  • HTTP(S): the protocol used to fetch web pages; the S means the connection is encrypted.
  • Iframe: a rectangle inside a web page that loads another page.
  • JavaScript: the programming language web pages use to make things happen in the browser.
  • javascript: URL: an address that contains code to run instead of pointing at a page.
  • Origin: the combination of scheme, host and port that identifies where a page came from.
  • Origin allowlist: a list of web addresses an app is permitted to load, with everything else refused.
  • Phishing: tricking a user into trusting a page that imitates a real one.
  • Proof-of-concept (PoC): a small demonstration built only to show that a bug is real.
  • Recon: the early look around a target to understand what it is made of.
  • Same-origin policy: the browser rule that stops a page from one origin reading or changing a page from another origin.
  • Sandbox: an attribute on an iframe that restricts what the frame is allowed to do.
  • Token: a piece of data, often secret, that proves a request comes from an authenticated user.
  • Top-level document: the main page in a window, as opposed to a frame inside it.
  • Universal cross-site scripting (UXSS): cross-site scripting that is not limited to one site, so a page from one origin can run code in a page from another.
  • Video Website Card: a Twitter advertisement format with a video or image and a link to a website.
  • window.open(): the JavaScript function that asks the browser to open a new window or tab.
  • WebSettings: the part of the Android programming interface that controls how a WebView behaves.
  • setSupportMultipleWindows(): the WebSettings switch that decides whether a page may open extra windows; leaving it off is what exposes the bug.
  • onCreateWindow(): the callback that fires when a page asks for a new window.
  • shouldOverrideUrlLoading(): a hook that lets an app inspect a URL before the WebView loads it and allow or refuse it.
  • loadUrl(): the method that tells a WebView to load a given address.

More by alesandroortiz

View all

1 more disclosed report, best first.

More from X / xAI

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Cross-site scripting (XSS)

The lesson behind this report.

Script an attacker supplies runs in another user's browser, on the target's origin, with that user's session.