Skip to content
XSS Write-up Intermediate

Youtube XSS

The YouTube annotation link whitelist validated the domain but not the protocol, allowing a javascript: URL to be used. An attacker could create a video with a malicious annotation that executes JavaScript when a victim clicks it, leading to XSS on youtube.com.

Frans Rosén Follow

Published on labs.detectify.com

TwitterLinkedIn

Detectify Labs, on labs.detectify.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. 6 min read.

Context

This write-up covers three separate cross-site scripting findings in Google products, found during a few days of research earlier in the year. The targets are the YouTube annotation editor, the Chrome Webstore Translation Manager hosted on translate.google.com, and the Flash-based Trend / Motion Chart in Google Docs. Each one is a different flavour of the same class of bug: user-controlled data reaching an executable context without adequate filtering.

Setup

No special tooling is described. The researcher used a normal Chrome Webstore developer account for the second finding, and a Google Spreadsheet for the third. The YouTube and Google Docs issues required only the ordinary ability to create content (a video with annotations, a spreadsheet with a chart). The Google Translate issue required the victim to be a developer of the affected Chrome application, which is what the social-engineering steps in that section work around.

Finding it

YouTube annotation links

YouTube annotations are active areas placed inside a video that perform an action when clicked. The editor restricts link annotations to a fixed set of destinations:

  • a Google+ link
  • another YouTube video
  • a YouTube playlist
  • a Kickstarter project page

When one of these is selected, the editor sends a request to YouTube containing XML. The XML has an action node of type openUrl together with the URL to use. Everything is accepted when posting values to that URL. When a video starts, a second call fetches a similar XML that tells the player whether any annotation contains a link, and if the URL does not match Google's whitelist the link is omitted from that XML.

The researcher knew several regular expressions were used for this filtering and started by probing the Kickstarter rule with subdomains and userinfo tricks:

Text
<url value="https://xxx.kickstarter.com/x" target="new"> – No luck
<url value="https://[redacted]/x" target="new"> – No luck
<url value="https://notkickstarter.com/x" target="new"> – No luck

That rule held. Moving to the Google+ rule produced the same result for the obvious bypasses, but a malformed scheme slipped through:

Text
<url value="https://plus.google.com.example.com" target="new"> – No luck
<url value="https://[redacted]" target="new"> – No luck
<url value="httpsx://plus.google.com/" target="new"> – Works! WTH!

The domain was validated but the protocol was not. That is the opening for a scheme-based payload.

Google Translate inline script data

Many pages embed dynamic data inside a <script> element as variables. On https://translate.google.com/manager/chrome/inapp/, the data for the current Chrome app was presented inline in a script variable, and one of the parameters was the application name. The data was not sanitised except by escaping quotes:

Text
{"src_lang": "all", "title": "</Hello> World " Test"...

Quotes were escaped, nothing else was. The researcher's reasoning is that a closing </script> inside a <script> element always breaks out of the script element, regardless of where it sits, and Chrome's syntax-highlighted view-source makes this visible.

Google Docs Trend / Motion Chart

Google Docs lets you create charts and embed them in a spreadsheet or other document. The Trend / Motion Chart is still built in Flash. The SWF file lives on gstatic.com but is embedded on docs.google.com. The flow the researcher observed:

  • Data is saved in the chart.
  • Flash is loaded and receives a URL as a flash parameter to load the chart data from.
  • Data is presented in the Flash. When the user performs actions in the Flash, it sends data to docs.google.com using ExternalInterface.call through JavaScript.

The issue was that backslashes were never escaped properly in the data presented to the Flash, and Flash does not handle backslashes correctly. The researcher links to a previous write-up on that behaviour.

Exploitation

Step 1: YouTube annotation link XSS

With the scheme check missing, the next step was a scheme payload. The researcher shows a payload that also works, then the result:

The // after javascript: tells the browser that everything after it is a one-line comment. The newline character %0a exits that comment, putting the parser back into JavaScript, where arbitrary code runs. In the demonstration the payload simply triggered an alert. The same payload worked when the player was embedded anywhere, always triggering on www.youtube.com. It was fixed the same week.

Step 2: Google Translate inline script breakout

Because </script> terminates the script element wherever it appears, the application name can be used to close the script and inject a new element. The researcher's example inserts an image with an onerror attribute carrying the payload. Visiting the crafted URL triggers the XSS without any interaction.

The limitation is that the page only renders if the current user is a developer of the current application, which makes it a self-XSS at that point. To reach someone else, the researcher used the Chrome Web Store's developer invitation features:

  1. Create a new Chrome Webstore Developer account.
  2. Activate something called "Google Group publishing", which means all users invited to the group become developers of the application and have access to it.
  3. Invite a victim to the Google Group.
  4. Wait about 30 minutes for it to reflect inside the Chrome Webstore Developer Dashboard.
  5. Send them the vulnerable URL.
  6. The XSS triggers.

Step 3: Google Docs chart XSS via Flash

The researcher created a spreadsheet containing the payload, then created a chart from it. Pressing any object in the Flash that triggered the ExternalInterface call back to docs.google.com executed the payload supplied in the chart data. This attack needed interaction, for example clicking the red dot in the chart. The dot could be made bigger or hidden below another object, but it was sufficient to make Google patch the issue since the link could be shared with anyone. Google patched it.

Root cause

All three are failures to constrain data before it reaches an executable context.

  • YouTube validated the host of the annotation URL but not the scheme, so a javascript: URL passed the whitelist. The // and %0a trick then turns the URL into executable JavaScript.
  • Google Translate escaped quotes in the inline JSON but did not neutralise </script>, so the application name could terminate the script element and inject markup.
  • Google Docs passed chart data to a Flash file without escaping backslashes, and Flash's handling of backslashes allowed the data to break out into the ExternalInterface JavaScript call.

The report does not describe the server-side code, so the exact regexes and escaping routines are not shown.

Impact

The YouTube issue ran in the context of www.youtube.com and fired on click of the annotation, including when the player was embedded elsewhere. The Google Translate issue executed without interaction but only for users who were developers of the affected application, which is why the Google Group publishing route was needed to turn it into an attack on another person. The Google Docs issue required the victim to interact with the chart, for example by clicking the red dot, and the document link could be shared with anyone. The report does not state bounty amounts or severity ratings.

Fix

The YouTube annotation issue was fixed the same week. The Google Docs chart issue was patched by Google.

Variants to test

  • Scheme confusion in URL whitelists. Submit URLs with unusual schemes such as httpsx://, javascript://, and mixed-case variants against any feature that validates a host but not a scheme. A positive result is the URL being accepted and later rendered as a link or navigation target.
  • Newline and comment tricks in scheme payloads. Where a javascript: URL is accepted, try //%0a and encoded newline variants to escape the comment. A positive result is script execution on click.
  • Inline JSON in script elements. Put </script> and a following tag with an event handler into any field reflected inside a <script> block. A positive result is the injected element rendering and firing.
  • Flash ExternalInterface data. Where a SWF receives data and calls back into JavaScript, try backslashes and quote combinations in the data fields. A positive result is the payload executing when the Flash performs its callback.
  • Developer invitation flows. Where a page only renders for application developers, look for group-based or invitation-based publishing that grants developer access to invited users, and test whether the vulnerable page then renders for them.

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

Over a few days, a security researcher poked at several Google products and found three separate bugs of the same family. The family is called cross-site scripting, usually shortened to XSS. The idea behind XSS is simple: a website takes something a user typed or supplied, and later puts it somewhere that a browser treats as instructions rather than as plain text. When that happens, the browser runs the attacker's instructions as if the website itself had written them.

A useful everyday comparison: imagine a noticeboard where the office manager pins up messages. If someone hands the manager a note that says "ignore the previous notice, the fire alarm test is cancelled", and the manager pins it up without reading it, everyone who walks past believes the fake notice. The noticeboard did nothing wrong on its own; it just displayed whatever it was given. XSS is the same: the website displays whatever it was given, and the browser believes it.

The three places the researcher looked were:

  1. YouTube annotations, the clickable boxes you can place on top of a video.
  2. Google Translate, specifically a page used by people who publish apps in the Chrome Web Store (Google's shop for browser extensions and apps).
  3. Google Docs, specifically a type of chart that was built with a technology called Flash.

Each one is a different flavour of the same mistake: data that a user controls reaches a place where it can be executed, without being properly filtered first. The report does not describe the server-side code, so the exact filtering rules are not shown.

The YouTube annotation bug

What annotations are

On YouTube you can add annotations to your own videos. An annotation is an active area placed inside the video: a little box or shape that does a certain thing when a viewer clicks it. Think of it like a sticky note stuck onto the screen of a television. The note is not part of the film, but it sits on top of it and reacts when you touch it.

The editor limits what a link annotation can point to. You can choose:

  • a Google+ link
  • another YouTube video
  • a YouTube playlist
  • a Kickstarter project page

Kickstarter is a crowdfunding site where people raise money for projects. Google+ was Google's social network at the time.

What happens behind the scenes

When you pick one of those destinations in the editor, the editor sends a request to YouTube. A request is just your browser asking a server to do something, the same way you ask a colleague to file a form. The request carries data formatted as XML. XML is a way of writing data using tags in angle brackets, a bit like labelling boxes in a warehouse so each one says what it contains.

The screenshot shows that request. There is an action node with the type openUrl, together with the URL that should be used. A node here just means one labelled piece of the data.

Everything is accepted when posting values to that URL. In other words, the editor does not refuse your input at the moment you save it. Later, when a video starts, a second call fetches a similar XML that tells the player whether any annotation in the video contains a link. If the URL does not match Google's whitelist, the link is left out of that second XML. A whitelist is a list of things that are allowed; anything not on the list is rejected. So the filtering happens at display time, not at save time.

First attempts: the Kickstarter rule

The researcher knew several regular expressions were used for this filtering. A regular expression, or regex, is a pattern used to check whether text has a certain shape, for example "does this start with https:// and end in kickstarter.com?". It is like a bouncer at a door checking IDs against a description: tall, wearing a red hat, and so on. If the description is too loose, the wrong person gets in.

The first idea was to see whether the Kickstarter rule was too loose. The researcher tried different subdomains. A subdomain is the part in front of the main domain: in mail.example.com, mail is the subdomain and example.com is the domain.

Text
<url value="https://xxx.kickstarter.com/x" target="new"> – No luck
<url value="https://[redacted]/x" target="new"> – No luck
<url value="https://notkickstarter.com/x" target="new"> – No luck

Line by line:

  • The first line tries a made-up subdomain xxx in front of kickstarter.com. If the rule only checked that the text contained kickstarter.com, this would pass. It did not.
  • The second line uses the @ trick. In a URL, everything before an @ is treated as a username, and everything after it is the real host. So [redacted] actually points at example.com, not at Kickstarter. A naive check that just looks for the string kickstarter.com somewhere in the URL would be fooled. It was not.
  • The third line uses a domain that merely contains the word kickstarter without being it: notkickstarter.com. Again, a loose check would be fooled. It was not.

So the Kickstarter rule looked well patched. The researcher moved on to the rule for Google's own sites, such as Google+.

Text
<url value="https://plus.google.com.example.com" target="new"> – No luck
<url value="https://[redacted]" target="new"> – No luck
<url value="httpsx://plus.google.com/" target="new"> – Works! WTH!

Line by line:

  • The first line puts plus.google.com at the start of a longer hostname. If the check only looked at the beginning of the host, this would pass. It did not.
  • The second line uses the same @ trick as before, this time with plus.google.com as the fake username. It did not pass either.
  • The third line is the interesting one. It writes httpsx:// instead of https://. That is not a real protocol. A protocol is the part before :// that tells the browser how to talk to the destination: https means a secure web page, ftp means file transfer, and so on. The check accepted httpsx://plus.google.com/ even though httpsx is not a real protocol.

So the domain was validated, but the protocol was not. That is the opening. If the check only cares about the host and ignores the protocol, then any protocol that the browser understands can be smuggled through, including protocols that run code.

The payload

With the protocol check missing, the next step was a scheme payload. A scheme is another word for the protocol part of a URL. The researcher shows a payload that also works:

Then the result:

Line by line:

  • javascript: is a protocol that tells the browser "the rest of this URL is JavaScript code, please run it". It is a legitimate part of how browsers work, and it is exactly why letting arbitrary protocols through a link whitelist is dangerous.
  • // after javascript: is a comment marker in JavaScript. Everything after it on the same line is ignored. So on its own, javascript://%0aalert(1) would just be an empty comment and do nothing.
  • %0a is the URL-encoded form of a newline character. A newline is what happens when you press Enter. Encoding it as %0a lets it travel inside a URL without breaking the URL itself.
  • alert(1) is a tiny piece of JavaScript that pops up a dialog box with the number 1 in it. It is the classic harmless demonstration that code is running.

Put together: the browser sees javascript:, then a comment //, then a newline, then alert(1). The newline ends the comment, so the parser is back in JavaScript-land and runs alert(1). In the demonstration the payload simply triggered an alert.

The animation shows the payload firing. The same payload worked when the player was embedded anywhere, always triggering on www.youtube.com. That matters because it means the code ran in YouTube's own context, with whatever access a normal YouTube page has. It was fixed the same week.

The Google Translate bug

What the page is

First, a bit of background. When you look at the source code of a web page, you have most likely seen something like this: a script element with dynamic data in the variables.

A script element is the part of a page that holds JavaScript, the language browsers run. Dynamic data means values that change depending on who is looking or what they are doing, for example your username or the name of an app you published.

The domain https://translate.google.com is not only the regular translation service. It also helps other Google services with translations. One of those services is the Chrome Webstore Translation Manager, located at:

Text
https://translate.google.com/manager/chrome/inapp/

This URL will not give you anything interesting on its own now, but when provided with the proper variables you are asked to purchase external translators to translate your application. An application here means a Chrome app or extension published in the Chrome Web Store.

On this URL, the data for the current Chrome app was presented inline inside a script variable. One parameter was the application name. A parameter is one named value in a request, like a field on a form. The problem was that the data was not sanitised in any way except by escaping quotes. Sanitising means cleaning input so it cannot do harm. Escaping means putting a backslash in front of a character so it is treated as text rather than as code.

Text
{"src_lang": "all", "title": "</Hello> World " Test"...

Line by line:

  • The outer braces { and } mark this as a JSON object. JSON is a common way of writing data as name and value pairs, like a labelled list.
  • "src_lang": "all" is one pair: the name src_lang (source language) has the value all.
  • "title": "..." is another pair: the name title has a value that starts with </Hello> World and then contains a quote, then Test, then another quote.
  • The quotes inside the title are escaped with backslashes, so the browser does not think the value ends early. But nothing else was escaped.

Quotes were escaped, nothing else was. That is the opening.

Why </script> matters

The researcher's reasoning is that a closing </script> inside a <script> element always breaks out of the script element, regardless of where it sits. Think of it like a conversation where someone says "end of quote". It does not matter what was being quoted; the moment those words are said, the quotation is over. The browser works the same way: the moment it sees </script>, it stops treating what follows as JavaScript and goes back to treating it as ordinary page markup.

Chrome's syntax-highlighted view-source makes this visible. View-source is the browser feature that shows you the raw code of a page, and syntax highlighting colours different kinds of code so you can see the structure.

The screenshot shows the vulnerable example on Google Translate. The application name breaks the current script, and the researcher inserts an image with an onerror attribute carrying the payload. An onerror attribute is a small instruction attached to an image: "if this image fails to load, run this code". Since the image is deliberately broken, the code runs immediately.

The next screenshot shows the payload in action. By going to this URL, the XSS triggers without any interaction. No click, no hover, nothing: just loading the page is enough.

The catch: only developers see the page

There is one problem. This page only renders if the current user is a developer of the current application. In that sense, this is more of a self-XSS: a bug that only affects the person who triggers it, because only they can see the page. That is not very useful for attacking someone else, so the researcher went back to figuring out a way to reach another person.

Reading about the Chrome Web Store, it looked like there were some ways to invite other developers. After spending some time on it, the researcher was able to do the following:

  1. Create a new Chrome Webstore Developer account.
  2. Activate something called "Google Group publishing", which basically means that all users invited to this group get to be a developer of the application. All the users in the group will have access to the application.
  3. Invite a victim to the Google Group.
  4. Wait about 30 minutes for it to reflect inside the Chrome Webstore Developer Dashboard.
  5. Send them the vulnerable URL.
  6. The XSS triggers.

Step by step, in plain words:

  • Step 1 is just signing up as a publisher, the same way you would sign up to sell something on an online marketplace.
  • Step 2 uses a feature where a whole group of people can be made developers at once. A Google Group is a mailing list style group. If the group is granted developer access, everyone in it inherits that access.
  • Step 3 is the social part: the victim is invited to the group.
  • Step 4 is waiting about 30 minutes for it to reflect inside the Chrome Webstore Developer Dashboard.
  • Step 5 is sending the crafted URL. Because the victim is now a developer of the application, the page renders for them.
  • Step 6 is the result: the XSS fires in the victim's browser.

The Google Docs bug

What the chart is

Google Docs lets you create charts and embed them in a spreadsheet or another document. One of those charts is called the Trend / Motion Chart, and it was still built in Flash. Flash was a browser plugin, a separate program that ran inside the browser to display animations and interactive content. It has since been retired, but at the time it was common.

The specific SWF file lives on gstatic.com but is embedded on docs.google.com. An SWF file is the file format Flash uses, like .jpg for images. gstatic.com is a domain Google uses to serve static files such as images and scripts.

The flow the researcher observed:

  • Data is saved in the chart.
  • Flash is loaded and receives a URL as a flash parameter to load the chart data from.
  • Data is presented in the Flash. When the user performs actions in the Flash, it sends data to docs.google.com using ExternalInterface.call through JavaScript.

In plain words: you type data into a chart, the chart is stored, and when you open it, a Flash file loads and fetches that data. When you click around inside the Flash, the Flash talks back to the page using a bridge called ExternalInterface. That bridge lets Flash call JavaScript functions on the page. It is like a translator standing between two people who speak different languages: whatever one says gets passed to the other.

The flaw

The issue was that backslashes were never escaped properly in the data presented to the Flash, and Flash does not handle backslashes correctly. A backslash is the \ character. In many languages it is used to escape the next character, meaning "treat the next character as text, not as code". If the escaping is done wrong, the next character can slip through as code.

The researcher links to a previous write-up on that behaviour. The report does not repeat the details here.

The attack

The researcher created the following spreadsheet:

The screenshot shows the spreadsheet. Then the researcher created a chart from it. Pressing any object in the Flash that triggered the ExternalInterface call back to docs.google.com executed the payload supplied in the chart data.

The animation shows the payload firing. This attack needed interaction, for example clicking the red dot in the chart. The dot could be made bigger or hidden below another object, but it was sufficient to make Google patch the issue since the link could be shared with anyone. Google patched it.

Why all three worked

All three are failures to constrain data before it reaches an executable context. An executable context is any place where the browser will run what it finds rather than display it: a script element, a javascript: URL, a Flash callback.

  • YouTube validated the host of the annotation URL but not the scheme, so a javascript: URL passed the whitelist. The // and %0a trick then turns the URL into executable JavaScript.
  • Google Translate escaped quotes in the inline JSON but did not neutralise </script>, so the application name could terminate the script element and inject markup.
  • Google Docs passed chart data to a Flash file without escaping backslashes, and Flash's handling of backslashes allowed the data to break out into the ExternalInterface JavaScript call.

The report does not describe the server-side code, so the exact regexes and escaping routines are not shown.

What each bug could do

The YouTube issue ran in the context of www.youtube.com and fired on click of the annotation, including when the player was embedded elsewhere. Running in the context of a site means the code has the same access as a normal page on that site: it can read what the page can read, act as the logged-in user, and so on.

The Google Translate issue executed without interaction but only for users who were developers of the affected application, which is why the Google Group publishing route was needed to turn it into an attack on another person.

The Google Docs issue required the victim to interact with the chart, for example by clicking the red dot, and the document link could be shared with anyone.

How they were fixed

The YouTube annotation issue was fixed the same week. The Google Docs chart issue was patched by Google.

Things worth trying if you are learning

These are the kinds of checks a beginner can try, in the spirit of the report. Only ever do this on systems you own or have explicit permission to test.

  • Scheme confusion in URL whitelists. Submit URLs with unusual schemes such as httpsx://, javascript://, and mixed-case variants against any feature that validates a host but not a scheme. A positive result is the URL being accepted and later rendered as a link or navigation target.
  • Newline and comment tricks in scheme payloads. Where a javascript: URL is accepted, try //%0a and encoded newline variants to escape the comment. A positive result is script execution on click.
  • Inline JSON in script elements. Put </script> and a following tag with an event handler into any field reflected inside a <script> block. A positive result is the injected element rendering and firing.
  • Flash ExternalInterface data. Where an SWF receives data and calls back into JavaScript, try backslashes and quote combinations in the data fields. A positive result is the payload executing when the Flash performs its callback.
  • Developer invitation flows. Where a page only renders for application developers, look for group-based or invitation-based publishing that grants developer access to invited users, and test whether the vulnerable page then renders for them.

Glossary

  • Annotation: a clickable area placed on top of a YouTube video that performs an action when clicked.
  • Application (Chrome app): a program or extension published in the Chrome Web Store.
  • Backslash: the \ character, often used to escape the next character so it is treated as text rather than code.
  • Chrome Web Store: Google's shop for browser extensions and apps.
  • Chrome Webstore Developer account: an account that lets you publish apps in the Chrome Web Store.
  • Chrome Webstore Developer Dashboard: the page where a publisher manages their apps.
  • Chrome Webstore Translation Manager: a Google service, hosted on translate.google.com, for managing translations of a Chrome app.
  • Cross-site scripting (XSS): a bug where user-controlled data reaches a place the browser treats as instructions, so the attacker's code runs as if the site wrote it.
  • Domain: the main part of a web address, such as example.com.
  • Dynamic data: values on a page that change depending on who is looking or what they are doing.
  • Escaping: putting a special character in front of another character so it is treated as text rather than as code.
  • Executable context: any place where the browser runs what it finds rather than displaying it, such as a script element or a javascript: URL.
  • ExternalInterface.call: a Flash feature that lets a Flash file call JavaScript functions on the page hosting it.
  • Flash: a browser plugin, now retired, used to display animations and interactive content.
  • Google Group: a mailing-list style group of people managed by Google.
  • Google Group publishing: a Chrome Web Store feature where everyone in a Google Group becomes a developer of an app.
  • Google+: Google's social network at the time of the report.
  • Host: the part of a URL that names the server, such as www.youtube.com.
  • javascript: scheme: a URL protocol that tells the browser the rest of the URL is JavaScript to run.
  • JSON: a way of writing data as name and value pairs, using braces and quotes.
  • Kickstarter: a crowdfunding site where people raise money for projects.
  • Newline: the character produced by pressing Enter, encoded as %0a in a URL.
  • onerror attribute: an instruction attached to an image that runs code if the image fails to load.
  • Parameter: one named value in a request, like a field on a form.
  • Payload: the piece of code or data an attacker wants to get executed.
  • Protocol (scheme): the part of a URL before ://, such as https, ftp or javascript, telling the browser how to talk to the destination.
  • Regular expression (regex): a pattern used to check whether text has a certain shape.
  • Request: a message from a browser asking a server to do something.
  • Sanitising: cleaning input so it cannot do harm when displayed or executed.
  • Self-XSS: a bug that only affects the person who triggers it, because only they can reach the vulnerable page.
  • Server: a computer that answers requests from browsers.
  • Source code (view-source): the raw code of a page, which browsers can display.
  • Subdomain: the part in front of the main domain, such as mail in mail.example.com.
  • SWF file: the file format used by Flash.
  • Syntax highlighting: colouring different kinds of code so the structure is easier to see.
  • URL: a web address.
  • Userinfo: the username part of a URL, before an @, which can be used to disguise the real host.
  • Whitelist: a list of things that are allowed; anything not on the list is rejected.
  • XML: a way of writing data using tags in angle brackets.

More by Frans Rosén

View all

26 more disclosed reports, best first.

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.