Skip to content
XSS Write-up Intermediate

$8,000 Bug Bounty Highlight: XSS to RCE in the Opera Browser

A drag-and-drop handler on the My Flow page inserted attacker-controlled HTML into the page, allowing script execution. The attacker could then use a hidden extension's file functions to write and open a file, achieving remote code execution.

Renwa Hiwa Follow

Published on blogs.opera.com

Bounty$8,000 View original

One of the cooler features of the Opera Browser is My Flow, which is basically a shared space between your computer and your phone, allowing you to share links, images, and videos with yourself. To connect, you just scan a QR code, and then you can send things between devices.

Renwa (@RenwaX23), on blogs.opera.com

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.

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. 5 min read.

Context

Opera's My Flow is a shared space between a user's computer and phone. It lets you send links, images and videos to yourself, and you connect the two devices by scanning a QR code. Once connected, items can be sent between devices.

The My Flow interface is served from web.flow.opera.com as a normal HTML page, so its code and components can be inspected. The page talks to a browser extension. That extension does not appear in the extension list at opera://extensions/; it is a hidden component extension. It can be revealed by starting Opera with the flag , show-component-extension-options. With that flag the extension appears as Opera Touch Background, and its source code can be read.

This write-up covers the second vulnerability Renwa submitted to Opera's Private Bug Bounty Programme: an XSS in the My Flow page that was chained into remote code execution through the privileges of that hidden extension. The vulnerability was fixed immediately after it was reported.

Setup

No accounts or special roles are described. The preconditions are:

  1. Opera with the My Flow feature, where the interface is loaded from web.flow.opera.com.
  2. For source review of the extension, Opera started with the , show-component-extension-options flag so that Opera Touch Background is visible and its code can be read.
  3. The developer tools in Opera, used to inspect the My Flow page and its components.

The researcher's own tooling beyond the browser is not described.

Finding it

Inspecting the My Flow page, the researcher looked for XSS and found this code:

JavaScript
const html = e.dataTransfer.getData('text/html');const src = html.match(//);if (src && src[1]) {   const parser = document.createElement("span");   parser.innerHTML = src[1];}

The code handles drag-and-drop. When a user drops an image onto the page, it creates a span element and sets its innerHTML to the location of the image taken from the dropped data. Two properties of browsers make this dangerous:

  1. The dataTransfer can be set to any arbitrary value.
  2. If you create a new element and set its innerHTML to an <img> tag, the image is still loaded in the background, even though nothing is shown on screen.

So the following causes an alert box even though no image is displayed:

JavaScript
const parser = document.createElement("span");parser.innerHTML = '<img src=x onerror=alert(1)>';

Exploitation

Step 1: A minimal XSS proof of concept

The researcher built a small proof-of-concept XSS. To show how easy it was to trigger, the page redirected to the web.flow.opera.com page a couple of seconds after the user began dragging an image. The user only had to begin dragging an image and then let go of the mouse for the XSS to fire.

Step 2: Reviewing the extension's privileges

To show greater impact, the researcher examined what the Opera Touch Background extension does. It has higher privileges and access to native functions, including opr.operaTouchPrivate, a collection of functions developed for the My Flow application. Two of those functions stood out: SEND_FILE and OPEN_FILE.

  • SEND_FILE retrieves information about a file provided by the user, uploads it to My Flow, and also saves the file to the user's computer in Downloads/MyFlow.
  • OPEN_FILE is intended for image files in My Flow, but while testing the researcher found that any type of file could be opened, not just images.

Together these give an arbitrary file write and open on the targeted computer.

Step 3: From file write to code execution

The proof of concept first creates a file exploit.bat containing calc, then opens it, which executes it and launches the Windows calculator:

JavaScript
operaTouchBackground.port.postMessage({   type: "SEND_FILE",    name: 'exploit.bat',   content: 'calc',   file_type: 'image/png'});operaTouchBackground.port.postMessage({   type: 'OPEN_FILE',   localFileName: 'exploit.bat'});

The first message sends the file through SEND_FILE with the name exploit.bat, the content calc and the file type image/png. The second message opens the written file by name, which caused it to be executed.

With a convincing user interface for the single click (the drag) needed to activate the exploit, the researcher demonstrated how the simple XSS could be turned into remote code execution for users of the My Flow system.

Root cause

The My Flow page takes the text/html entry from a drag-and-drop dataTransfer and assigns a match from it directly to innerHTML of a newly created span. The dropped value is fully attacker-controlled, and assigning HTML to innerHTML parses and loads it, so an <img> with an onerror handler executes even when the image is never displayed. The page therefore trusts data that the browser lets be set to any arbitrary value.

The impact is amplified by the extension the page communicates with. Opera Touch Background exposes native functions through opr.operaTouchPrivate, including SEND_FILE and OPEN_FILE, and the page can call them. OPEN_FILE was intended for images but accepts any file type, so a written file can be executed.

Impact

An attacker who gets a My Flow user to begin dragging an image and then release the mouse can run script in the context of web.flow.opera.com. From there, the script can use the extension's privileged functions to write a file to Downloads/MyFlow and open it, which in the demonstrated case executed the batch file. The result is remote code execution for users of the My Flow system. The attack requires that single user interaction (the drag), and the researcher built a convincing interface to obtain it.

Fix

The vulnerability was fixed within a few days of being reported, and a bounty of $8,000 USD was awarded around three weeks later. The report does not describe the specific code change.

Variants to test

  1. Other drag-and-drop sinks. Look for handlers that read e.dataTransfer.getData('text/html') or text/uri-list and feed the result to innerHTML, insertAdjacentHTML or similar. A positive result is an <img src=x onerror=...> payload firing without any visible element.
  2. Hidden component extensions. Start the browser with flags that reveal component extensions and review their exposed native APIs. A positive result is a page-reachable function that writes files, opens files or otherwise crosses from web content into the OS.
  3. File-type checks on open. Where an extension opens files by name, try opening a non-image type after writing it. A positive result is execution of a file that was declared as an image.
  4. Write paths outside the intended directory. Check whether the file-saving function constrains the destination. A positive result is a file landing somewhere other than the intended Downloads/MyFlow location.
From the original on blogs.opera.com

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. 14 min read.

What happened, in plain words

Opera is a web browser, the program you use to visit websites. One of its features is called My Flow. Think of My Flow as a private shared drawer between your computer and your phone: you put a link, a picture or a video in it on one device, and it appears on the other. To set it up, you scan a QR code (the square barcode you point a phone camera at) and the two devices are linked.

A security researcher called Renwa looked at the web page that powers My Flow. He found a way to make that page run code that he chose, by tricking a user into a simple drag of an image. That kind of flaw is called XSS, short for cross-site scripting: a website ends up running code supplied by an attacker, as if the site itself had written it. He then found that the page could talk to a hidden helper program inside Opera, and that this helper could save a file to the computer and open it. In the demonstrated case, opening a Windows batch file ran it. So the small flaw grew into remote code execution (RCE): the attacker's code runs as a normal program on the victim's machine.

The picture above shows the My Flow feature, the shared space between computer and phone that the whole story revolves around.

This was the second bug Renwa reported to Opera's private bug bounty programme. A bug bounty programme is a scheme where a company pays people for finding and reporting security problems instead of exploiting them. Opera fixed the problem within a few days and paid a bounty of $8,000 USD around three weeks later.

The pieces involved

Before the attack makes sense, you need to know what the moving parts are.

A web page is just text the browser interprets. When you open a site, your browser downloads files (mostly HTML, the language that describes a page, plus JavaScript, the language that makes pages interactive) and runs them. Anyone can press a key in the browser to open the developer tools, a panel that shows the page's code and lets you inspect it. That is how Renwa started: he opened the My Flow page and read its code.

An extension is a small add-on program inside the browser. You know browser extensions as things that block ads or manage passwords. Normally you can see them in a list. Opera has a special kind: a component extension, which is built into the browser and hidden from the normal list. It is still an extension, with extra powers a normal web page does not have.

A flag is a startup option. When you launch a program from a command line, you can add words starting with dashes to change how it starts. Opera has a flag that makes hidden component extensions visible.

An API is a set of functions one program offers to another. A good everyday comparison is a restaurant menu: you do not walk into the kitchen, you order from a list of dishes the kitchen is willing to make. An API is that menu. The hidden extension offered a menu of functions to the My Flow page, and the page could order from it.

innerHTML is a property of a web page element that holds its HTML content. Setting it is like telling the browser "here is some HTML, please build it". The browser does not just store the text: it parses it and acts on it, including loading images.

dataTransfer is the clipboard-like object used during drag-and-drop. When you drag something, the browser carries data along with the drag, and the page can read it. Crucially, a page can put anything it likes into that data.

Step 1: Reading the My Flow page

Renwa used Opera's developer tools to inspect the My Flow interface. He found that it is loaded from the domain web.flow.opera.com, and that it is an ordinary HTML page, so its code and components can be viewed.

While reading the page's source, he noticed that the page communicated with a browser extension. But when he looked at the extension list at opera://extensions/ (a special address inside the browser that lists installed extensions), nothing appeared. After some research he learned it was a hidden component extension. To see it, he started Opera with a special flag, , show-component-extension-options. With that flag, the extension appeared under the name Opera Touch Background, and he could read its source code.

Why bother? Because a web page on its own is fairly limited: browsers deliberately stop websites from touching your files. An extension is not limited in the same way. If the page can be made to send instructions to a powerful extension, the page's limits stop mattering. That is the direction the rest of the attack takes.

Step 2: Finding the XSS

Back on the web.flow.opera.com page, Renwa went looking for XSS flaws: places where the page takes something a user or another page supplies and treats it as code. One piece of code caught his eye:

JavaScript
const html = e.dataTransfer.getData('text/html');const src = html.match(//);if (src && src[1]) {   const parser = document.createElement("span");   parser.innerHTML = src[1];}

Line by line, in plain words:

  1. const html = e.dataTransfer.getData('text/html'); reads whatever HTML was carried by the drag-and-drop event and stores it in a variable called html. The event is the thing that happens when you drag and drop; e is the event object.
  2. const src = html.match(//); searches that dragged HTML for an image address, using a pattern (a regular expression, a way of describing text to search for). The result is stored in src.
  3. if (src && src[1]) { checks that a match was found and that it has a captured part, meaning an address was actually extracted.
  4. const parser = document.createElement("span"); creates a new, invisible element of type span (a generic container in HTML).
  5. parser.innerHTML = src[1]; puts the extracted address into that element as HTML, which makes the browser parse and act on it.

This code exists to support drag-and-drop: when a user drops an image onto the page, the page builds an element whose content is the image's location. The intent is harmless. The problem is where the value comes from.

Two facts about browsers turn this into a vulnerability:

  1. In browsers, the dataTransfer can be set to any arbitrary value. A page cannot rely on it containing only what a well-behaved page would put there.
  2. In browsers, if you create a new element and set its innerHTML to an <img> tag, the image is still loaded in the background, even if nothing is shown on screen.

The second point is the key. An <img> tag can carry an onerror attribute: a piece of code the browser runs if the image fails to load. If the address is deliberately broken, the image fails, and the code runs. Nothing needs to be visible. So this causes an alert box even though no image is displayed:

JavaScript
const parser = document.createElement("span");parser.innerHTML = '<img src=x onerror=alert(1)>';

Line by line:

  1. const parser = document.createElement("span"); creates the same invisible container as before.
  2. parser.innerHTML = '<img src=x onerror=alert(1)>'; hands the browser an image tag whose address is x, which will not load, and whose onerror handler is alert(1), a command that shows a pop-up box. Because the browser tries to load the image in the background, it fails, and the handler fires.

alert(1) is the classic harmless proof: it shows a box with the number 1. If you can make a page show that box, you can make it run other code too.

Step 3: A minimal proof of concept

Renwa built a small proof-of-concept XSS. A proof of concept is a demonstration that a flaw is real, kept as small as possible. To show how easy it was to trigger, he made a web page that, once you began dragging an image, redirected to the web.flow.opera.com page after a couple of seconds. The user only had to begin dragging an image and then let go of the mouse for the XSS to happen.

The image above shows that proof of concept in action.

Why design it that way? Because the flaw lives on a page the attacker does not control, and the victim has to be on that page with a drag in progress. The redirect does the work of getting the victim there at the right moment, so the only thing the victim does is start a drag and release the mouse. That is a very small ask, which is what makes the attack realistic.

Step 4: Looking at what the hidden extension can do

A pop-up box is not a serious impact by itself. To show a greater impact, Renwa examined what the Opera Touch Background extension actually does. It turns out it has higher privileges and access to native functions, meaning functions that reach out of the browser and into the operating system. Among them is opr.operaTouchPrivate, a collection of functions developed for use with the My Flow application.

Think of the extension as a member of staff behind a counter, and the web page as a customer. The customer cannot walk into the back room, but the staff member will fetch things from it if asked in the right way. opr.operaTouchPrivate is the counter: the list of things the page is allowed to ask for.

Two of those functions stood out: SEND_FILE and OPEN_FILE.

  • SEND_FILE retrieves information about a file provided by the user, uploads it to My Flow, and also saves the file to the user's computer in Downloads/MyFlow.
  • OPEN_FILE is intended for image files in My Flow, but while testing Renwa found that any type of file could be opened, not just images.

Together these give an arbitrary file write and open on the targeted computer. "Arbitrary file write" means writing a file of the attacker's choosing, with the attacker's content, to the victim's disk. "Open" means asking the system to open it, which for some file types means running it.

Why does the second point matter so much? Because the two functions were meant to work together for pictures: save a picture, open a picture. If the open step only accepted pictures, a written file would be harmless. Because it accepts any type, a written batch file can be opened and run.

Step 5: From a written file to running code

To create a real scenario, Renwa built a proof of concept that first creates a file exploit.bat containing calc, and then opens it. A .bat file is a Windows batch file: a list of commands that Windows runs when the file is opened. calc is the command that starts the Windows calculator, a harmless stand-in for any program.

JavaScript
operaTouchBackground.port.postMessage({   type: "SEND_FILE",    name: 'exploit.bat',   content: 'calc',   file_type: 'image/png'});operaTouchBackground.port.postMessage({   type: 'OPEN_FILE',   localFileName: 'exploit.bat'});

Line by line:

  1. operaTouchBackground.port.postMessage({ starts a message to the extension. postMessage is the browser's way for one part of the browser to send a message to another; port is the channel the two sides talk over. The object that follows is the order being placed from the menu.
  2. type: "SEND_FILE", says which function to use: the one that saves a file.
  3. name: 'exploit.bat', is the file name to save it under.
  4. content: 'calc', is what goes inside the file: the single command calc.
  5. file_type: 'image/png' declares the file as a PNG image, even though it is a batch file. The message declares the file as a PNG image even though it is a batch file.
  6. The second postMessage call uses type: 'OPEN_FILE' and localFileName: 'exploit.bat' to ask the extension to open the file that was just written, by name.

So the first message writes the file through the extension's file-saving path, declaring it as image/png even though it is a batch file. The second message opens the written file by name, and because any file type can be opened, the batch file runs. The result is the Windows calculator appearing, which proves that code of the attacker's choosing ran on the machine.

Finally, with a convincing user interface for the single click (the drag) needed to activate the exploit, Renwa demonstrated how the simple XSS could be turned into remote code execution for users of the My Flow system.

From the original on blogs.opera.com

Why it worked

The root cause is a trust mistake. The My Flow page takes the text/html entry from a drag-and-drop dataTransfer and assigns a match from it directly to innerHTML of a newly created span. The dropped value is fully attacker-controlled, and assigning HTML to innerHTML parses and loads it, so an <img> with an onerror handler executes even when the image is never displayed. The page therefore trusts data that the browser lets be set to any arbitrary value.

The impact is amplified by the extension the page communicates with. Opera Touch Background exposes native functions through opr.operaTouchPrivate, including SEND_FILE and OPEN_FILE, and the page can call them. OPEN_FILE was intended for images but accepts any file type, so a written file can be executed.

A useful way to hold the whole chain in your head: a small hole in the front door (the page trusting dragged data) led to a key cabinet (the extension's functions), and one of the keys opened a door the designers did not mean it to open (opening any file type).

What an attacker gets

An attacker who gets a My Flow user to begin dragging an image and then release the mouse can run script in the context of web.flow.opera.com. "In the context of" means the code runs as if the site itself had written it, with the site's permissions. From there, the script can use the extension's privileged functions to write a file to Downloads/MyFlow and open it, which in the demonstrated case executed the batch file. The result is remote code execution for users of the My Flow system. The attack requires that single user interaction (the drag), and Renwa built a convincing interface to obtain it.

The fix and the reward

The vulnerability was fixed within a few days of being reported, and a bounty of $8,000 USD was awarded around three weeks later. The report does not describe the specific code change.

Where else to look

These are the general lessons the report points to, written as things a tester would try next.

  1. Other drag-and-drop sinks. Look for handlers that read e.dataTransfer.getData('text/html') or text/uri-list and feed the result to innerHTML, insertAdjacentHTML or similar. A positive result is an <img src=x onerror=...> payload firing without any visible element.
  2. Hidden component extensions. Start the browser with flags that reveal component extensions and review their exposed native APIs. A positive result is a page-reachable function that writes files, opens files or otherwise crosses from web content into the OS.
  3. File-type checks on open. Where an extension opens files by name, try opening a non-image type after writing it. A positive result is execution of a file that was declared as an image.
  4. Write paths outside the intended directory. Check whether the file-saving function constrains the destination. A positive result is a file landing somewhere other than the intended Downloads/MyFlow location.

Glossary

  • API: a set of functions one program offers to another, like a menu of things you are allowed to ask for.
  • Batch file (.bat): a Windows file containing a list of commands that run when the file is opened.
  • Bug bounty programme: a scheme where a company pays researchers for reporting security flaws.
  • Component extension: an extension built into a browser and hidden from the normal extension list.
  • Developer tools: a panel in the browser that shows a page's code and lets you inspect it.
  • Domain: the name part of a web address, such as web.flow.opera.com.
  • Drag-and-drop: the mouse action of picking something up and releasing it somewhere else.
  • dataTransfer: the object that carries data during a drag-and-drop.
  • Extension: a small add-on program inside a browser with extra powers.
  • Flag: a startup option, usually starting with dashes, that changes how a program starts.
  • HTML: the language that describes the structure of a web page.
  • innerHTML: the property of a page element that holds its HTML content; setting it makes the browser parse and act on that HTML.
  • JavaScript: the programming language that makes web pages interactive.
  • My Flow: Opera's shared space between a computer and a phone for sending links, images and videos to yourself.
  • onerror: an attribute on an image tag holding code the browser runs if the image fails to load.
  • Proof of concept: a small demonstration that a flaw is real.
  • QR code: the square barcode scanned with a phone camera to link devices.
  • Regular expression: a way of describing text to search for in a string.
  • Remote code execution (RCE): running the attacker's code as a program on the victim's machine.
  • Root cause: the underlying mistake that makes a vulnerability possible.
  • span: a generic, usually invisible container element in HTML.
  • XSS (cross-site scripting): a flaw where a website runs code supplied by an attacker as if the site had written it.

More by Renwa Hiwa

View all

10 more disclosed reports, best first.

More from Opera

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.