XSS->Fix->Bypass: 10000$ bounty in Google Maps
A map name containing special characters was placed inside a CDATA block in the KML export, but the closing sequence could be supplied in the name to break out and inject XML, leading to script execution. After Google's fix wrapped the input in an extra CDATA block, the same closing sequence was used twice to escape again.
Published on ehpus.com
Ah, this moment of thrill every Google bug hunter knows, when you see a new ‘buganizer’ email landing in your inbox. Did they accept my new bug submission?
The full write-up lives on its author's site
It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.
Context
Google Maps lets users create their own maps through the My Maps feature at https://www.google.com/maps/d/. Once a map is built, it can be exported in several formats, one of which is KML, an XML-like file format with a few extra features. The export is served by the server as an XML document containing KML tags, and the map name supplied by the user is embedded in that document.
The bug in this write-up is a cross-site scripting issue in that export response, found by Zohar Shachar and reported to Google. It was paid twice: 5000 USD for the original XSS and another 5000 USD for a bypass of the fix, for a total of 10000 USD.
Setup
No special accounts, roles or tooling are described. The researcher used the public My Maps interface to create a map, gave it a name, exported it as KML, and inspected the server's response. The only precondition is the ability to create a map and export it, which any user of the feature has.
Finding it
The starting point was a sample map named:
blabla<script>alert(1)</script>
Exporting that map as KML and reviewing the server's response showed an XML response with KML tags inside, where the map name was placed inside a CDATA section. The researcher's reasoning was that because the name contained special characters such as <, it was wrapped in CDATA, which means the code would not be rendered by the browser.
That raised the obvious question: how do you close a CDATA section? The answer is the sequence ]]>, and the researcher found that placing it at the beginning of the map name escapes the CDATA context and lets arbitrary XML content be added, which the browser then renders as XML. That leads immediately to XSS, for example with a simple SVG XSS payload.
Exploitation
Step 1: escape CDATA with an SVG payload
The map name is set to a payload that begins with ]]> so that the CDATA section is closed, followed by an SVG XSS payload. The complete reproducing steps sent to Google are shown below (the researcher notes there is a missing > in the description in step 3, corrected in a second email):
The important part is the leading ]]>, which terminates the CDATA section the server opened around the map name. Everything after it is interpreted as XML markup rather than text, so the SVG payload is parsed and executed by the browser when the exported KML is rendered. The researcher states that at the time, prior to the fix, this led to XSS, though no image of the result was kept.
Shortly after submission Google replied with a 'Nice catch', and shortly after that a 5000 USD bounty was issued.
Step 2: inspect the fix
Later, a 'fixed' status update arrived for the issue.
The researcher reopened Google Maps, entered the same payload as before, and checked the response. What came back was confusing at first. From what could be seen, the fix for the CDATA closing problem was simply to add another CDATA tag. The transformation was:
<script>becomes<![CDATA[<script>]]>(just like before)]]><script>becomes<![CDATA[<![CDATA[<script>]]>]]>
Step 3: bypass with two closing tags
The reasoning follows directly from the transformation above: if the fix produces two CDATA open tags, then two CDATA closing tags are enough to escape both of them. The bypass payload therefore uses two ]]> sequences.
The researcher was genuinely surprised the bypass was so simple. The report was sent so quickly, literally 10 minutes between checking the mailbox and reporting the bypass, that self-doubt set in immediately afterwards: perhaps some other fix had been missed, or there was some obvious reason the bypass would not work. Less than two hours after the bypass email was sent, a reassuring response arrived.
A few days later another 5000 USD bounty was awarded.
Root cause
The server wraps the user-controlled map name in a CDATA section inside the KML/XML export. CDATA is not an escaping mechanism against an attacker who can supply the terminator: any occurrence of ]]> inside the data closes the section, and whatever follows is parsed as markup. The original code did not neutralise that sequence, so a map name beginning with ]]> broke out of the CDATA context and injected XML, including an SVG payload that executes script.
The fix did not remove or encode the dangerous sequence either. It wrapped the value in an additional CDATA layer, which only raises the number of closing sequences an attacker needs. Because the attacker controls the input, they can simply supply as many ]]> sequences as there are open CDATA sections. The report does not describe what the correct fix would be.
Impact
The report describes the result as XSS reached through the exported KML response, with an SVG payload as the example. It does not spell out which origin the payload executes on, which users would be affected, or what actions an attacker could take beyond script execution. The bounty history (5000 USD for the original issue and 5000 USD for the bypass) indicates Google treated both as valid security bugs.
Fix
The report does not describe a final fix. What it does show is the first attempted fix, which added an extra CDATA wrapper around the value, and that this was insufficient because the attacker can add matching closing sequences.
Variants to test
- Any feature that embeds user input in a CDATA section of an XML, KML, RSS, Atom or SVG response. Try a value beginning with
]]>followed by markup; a positive result is that the markup is parsed rather than shown as text. - Fixes that add another CDATA layer. Send two
]]>sequences, then three, and so on; a positive result is that the payload still escapes and executes. - Export and download endpoints for user-created content (maps, documents, feeds) where the name or title is reflected into the file. A positive result is an XML response where the injected element appears outside any CDATA section.
- SVG payloads in XML contexts, as used here. A positive result is script execution when the exported file is opened in the browser.
- Re-validate every 'fixed' status on your own reports by replaying the original payload and inspecting the new response, as the researcher did here and, as mentioned in the final thoughts, with an SMTP injection bug in G Suite that was re-exploited after being marked fixed.
Timeline
- 04/23/2019 XSS reported to Google.
- 04/27/2019 bug accepted ('nice catch!').
- 05/07/2019 reward (5000 USD) issued.
- 06/07/2019 issue reported as fixed.
- 06/07/2019 fix bypass reported.
- 06/07/2019 bypass confirmed, issue reopened.
- 06/18/2019 second reward (5000 USD) issued.
What happened, in plain words
Google Maps has a feature called My Maps that lets anyone build their own map: you drop pins, draw routes, add notes, and give the whole thing a name. When you are happy with it, you can download it in a few file formats, one of which is KML. KML is a text file format that describes places on a map; it is built on XML, which is a way of writing data using tags in angle brackets, like <name>blabla</name>. Browsers and other programs can read these files and display them.
The researcher, Zohar Shachar, noticed that whatever name you give your map ends up inside the exported KML file. If you name your map something containing a piece of code, that code appears in the file too. Normally the server tries to protect itself by wrapping your name in a special container called CDATA, which tells the browser "treat everything in here as plain text, do not run it". The researcher found a way to break out of that container, which made the browser run the code. That kind of bug, where you get your own code to run inside someone else's website, is called cross-site scripting, or XSS.
Google marked it as fixed and paid 5000 USD. Later the researcher went back, looked at how the fix worked, and found it was incomplete: the fix could be defeated with a slightly longer version of the same trick. He reported that too, and Google paid another 5000 USD. Total: 10000 USD. The lesson he draws is simple: when a bug you reported is marked as fixed, go back and check the fix yourself.
The feature: exporting a map as KML
My Maps lives at https://www.google.com/maps/d/. You do not need any special account or tool to use it; if you can use a browser, you can create a map and export it. That is the whole setup for this bug.
Once your map is built, you choose an export format. KML is one of them. The server takes your map, including the name you gave it, and produces a file. That file is sent back to your browser as an XML document: a structured text file made of tags, with KML tags inside it describing the map.
The researcher started with a map named:
blabla<script>alert(1)</script>
Line by line, this is just a piece of text:
blablais an ordinary word, there to make the name look normal.<script>is the opening tag that tells a browser "here comes some code, run it".alert(1)is the simplest possible piece of code: it makes the browser pop up a small box with the number 1 in it. Security researchers use it because it is harmless and easy to spot.</script>closes the code block.
If a browser ever treats that name as part of a web page rather than as text, it will run alert(1) and show the box. That is the whole goal of an XSS test: get the box to appear.
He exported the map as KML and looked at what the server sent back. The response was an XML document with KML tags, and the map name appeared inside a CDATA section. CDATA is a way of saying "the stuff between these markers is raw text, not markup". It starts with <![CDATA[ and ends with ]]>. The researcher's reasoning was that because the name contained a special character like <, the server wrapped it in CDATA so that the browser would show it as text instead of running it.
That raised the obvious question: how do you close a CDATA section? The answer is the three-character sequence ]]>. If you can get those three characters into the middle of the data, the CDATA section ends right there, and whatever comes after is no longer plain text: it is markup, and the browser will parse it.
Finding the first bug: escaping CDATA
The researcher found that putting ]]> at the beginning of the map name does exactly that. The server opens a CDATA section, your name starts by closing it, and everything you write after that is treated as XML markup. If that markup is an SVG payload, the browser runs it. SVG is a format for drawing pictures, and like HTML it can contain script, so an SVG element is a common way to smuggle code into an XML document.
The complete reproducing steps he sent to Google are shown below. He notes that there is a missing > in his description in step 3, which he corrected in a second email:
The important part of those steps is the leading ]]>. It terminates the CDATA section the server opened around the map name. Everything after it is read as XML markup rather than as text, so the SVG payload is parsed and executed by the browser when the exported KML is opened. The researcher states that at the time, before the fix, this led to XSS, although no image of the result was kept.
Shortly after the submission, Google replied with a 'Nice catch', and shortly after that a 5000 USD bounty was issued.
The fix arrives, and the researcher looks at it
Later, a 'fixed' status update arrived for the issue.
Most people would stop there. The researcher did not. He reopened Google Maps, entered the same payload as before, and looked at the response again. What came back was confusing at first. From what he could see, the fix for the CDATA closing problem was simply to add another CDATA tag around the value. The transformation was:
<script>becomes<![CDATA[<script>]]>(just like before)]]><script>becomes<![CDATA[<![CDATA[<script>]]>]]>
Read the second line slowly. The server takes your input and wraps it in a CDATA section. But your input already contains a ]]> that closes that section, and then a <script>. So the server's wrapper ends up producing two opening CDATA markers, one from its own wrapper and one from your text, and two closing markers, one from your text and one from its wrapper. The fix did not remove the dangerous sequence; it just put another layer around it.
The bypass: two closing tags
The reasoning follows directly from that transformation. If the fix produces two CDATA open tags, then two CDATA closing tags are enough to escape both of them. The bypass payload therefore uses two ]]> sequences.
The researcher was genuinely surprised the bypass was so simple. He sent the report so quickly, literally 10 minutes between checking his mailbox and reporting the bypass, that self-doubt set in immediately afterwards: perhaps some other fix had been missed, or there was some obvious reason the bypass would not work. Less than two hours after the bypass email was sent, a reassuring response arrived.
A few days later another 5000 USD bounty was awarded.
Why it worked
The server wraps the user-controlled map name in a CDATA section inside the KML/XML export. CDATA is not a defence against someone who can supply the terminator: any occurrence of ]]> inside the data closes the section, and whatever follows is parsed as markup. The original code did not neutralise that sequence, so a map name beginning with ]]> broke out of the CDATA context and injected XML, including an SVG payload that runs script.
The fix did not remove or encode the dangerous sequence either. It wrapped the value in an additional CDATA layer, which only raises the number of closing sequences an attacker needs. Because the attacker controls the input, they can simply supply as many ]]> sequences as there are open CDATA sections. The report does not describe what the correct fix would be.
A useful everyday comparison: imagine a form where you write your name, and the form puts your name between two covers that say "do not read what is inside". If you write the words "end of cover" inside your name, the reader stops treating the rest as hidden and starts reading it as instructions. Adding a second cover does not help, because you can write "end of cover" twice.
What the impact was
The report describes the result as XSS reached through the exported KML response, with an SVG payload as the example. It does not spell out which origin the payload executes on, which users would be affected, or what actions an attacker could take beyond script execution. The bounty history, 5000 USD for the original issue and 5000 USD for the bypass, indicates Google treated both as valid security bugs.
What the fix should have been
The report does not describe a final fix. What it does show is the first attempted fix, which added an extra CDATA wrapper around the value, and that this was insufficient because the attacker can add matching closing sequences.
Things worth testing yourself
- Any feature that embeds user input in a CDATA section of an XML, KML, RSS, Atom or SVG response. Try a value beginning with
]]>followed by markup; a positive result is that the markup is parsed rather than shown as text. - Fixes that add another CDATA layer. Send two
]]>sequences, then three, and so on; a positive result is that the payload still escapes and executes. - Export and download endpoints for user-created content (maps, documents, feeds) where the name or title is reflected into the file. A positive result is an XML response where the injected element appears outside any CDATA section.
- SVG payloads in XML contexts, as used here. A positive result is script execution when the exported file is opened in the browser.
- Re-validate every 'fixed' status on your own reports by replaying the original payload and inspecting the new response, as the researcher did here and, as mentioned in his final thoughts, with an SMTP injection bug in G Suite that was re-exploited after being marked fixed.
Timeline
- 04/23/2019 XSS reported to Google.
- 04/27/2019 bug accepted ('nice catch!').
- 05/07/2019 reward (5000 USD) issued.
- 06/07/2019 issue reported as fixed.
- 06/07/2019 fix bypass reported.
- 06/07/2019 bypass confirmed, issue reopened.
- 06/18/2019 second reward (5000 USD) issued.
Glossary
- XSS (cross-site scripting): a bug where an attacker gets their own code to run inside someone else's website, in the browser of a victim.
- XML: a way of writing structured data using tags in angle brackets, such as
<name>blabla</name>. Browsers and programs can read it. - KML: a file format for describing places on a map, built on XML. Google Maps can export your map as KML.
- My Maps: the Google Maps feature that lets anyone create their own map and export it.
- CDATA: a marker inside XML that says "everything between these markers is plain text, do not treat it as markup". It starts with
<![CDATA[and ends with]]>. - SVG: a format for drawing pictures, built on XML. Like HTML, it can contain script, so it is a common way to smuggle code into an XML document.
- Payload: the piece of text or code an attacker sends to try to trigger a bug.
- Bypass: a way of defeating a fix, so the bug still works after it was supposedly closed.
- Bounty: money a company pays a researcher for reporting a valid security bug.
- SMTP injection: a bug where an attacker can insert extra commands into an email-sending conversation, mentioned here only as another example of a bug that was re-exploited after being marked fixed.
- G Suite: Google's collection of business apps (mail, documents and so on), mentioned only in passing.
- Origin: the combination of scheme, host and port that a browser uses to decide which site a piece of code belongs to.