XSS in twitter.com/safety/unsafe_link_warning
The unsafe link warning page reflected a user-supplied URL into the page without proper encoding, allowing an attacker to inject an event handler. In Internet Explorer, hovering over the 'continue' link executed script, though Firefox and Chrome blocked it via CSP.
Originally disclosed on HackerOne
- Triaged in 24 hours
- Fixed in 3 days
- Paid in 4 days
- Disclosed after 11 days
The following page has XSS. https://twitter.com/safety/unsafe_link_warning?unsafe_link=[vulnerable_param]
Steps to reproduce:
- Go to the following URL using IE:
-
Click "continue".
-
Do mouseover to "continue". XSS occurs.
FYI in Firefox and Chrome, it is blocked by CSP :)
I recommend fixing this. Thanks!
What the report shows
The target is a Twitter safety interstitial at twitter.com/safety/unsafe_link_warning, a page that warns users before they follow a link that has been flagged as unsafe. The page takes a value from a query parameter called unsafe_link. The researcher, masatokinugawa, reported that this reflection can be turned into cross-site scripting.
The vulnerable URL shape given in the report is:
https://twitter.com/safety/unsafe_link_warning?unsafe_link=[vulnerable_param]
The reproduction steps are short and specific to Internet Explorer:
- Open the following URL in IE:
https://twitter.com/safety/unsafe_link_warning?unsafe_link=https%3A%2F%2Ftwitter.com%2Fsafety%2Funsafe_link_warning%3Funsafe_link%3Dhttp%3A%2F%2Fexample.com%2520onmouseover%3Dalert%281%29%2520style=font-size:100pt%2520
-
Click "continue".
-
Move the mouse over "continue". The script executes.
The payload is nested. The outer unsafe_link value is itself a URL pointing back at the same safety page, and that inner URL carries a second unsafe_link value of http://example.com%20onmouseover=alert(1)%20style=font-size:100pt%20. The double encoding (%2520) means the inner value still contains literal %20 sequences. Hovering the "continue" link fires alert(1).
The researcher notes that in Firefox and Chrome the same payload is blocked by Content Security Policy. The report does not describe the CSP directive involved, and it does not give a fix, a severity rating or a CVSS score. The platform records a bounty of 1,400 USD and disclosure on 3 April 2015.
Root cause
Because the decoded value can contain spaces and attribute-like text, an attacker can close the href value and add new attributes such as onmouseover and style.
The report does not state which server-side or client-side code performs the decoding, only that the result is reflected into the page.
Impact
In the demonstrated case the payload fires alert(1) on mouseover in Internet Explorer. The report does not go further than alert(1) and does not describe theft of cookies, tokens or account actions. The practical limit is the browser: the payload as written works in Internet Explorer and is stopped by CSP in Firefox and Chrome, so the affected population is IE users.
How this kind of bug works
Reflected XSS happens when an application takes input from the request and writes it into an HTML response without context-appropriate encoding. The browser then parses the attacker-controlled text as markup or as part of an attribute, not as data. The classic variants are breaking out of a text node with a tag, breaking out of a quoted attribute with a quote or, as here, with whitespace followed by a new attribute name, and injecting into a URL or script context.
Double decoding widens the attack surface. If a value is decoded once when it is read and again when it is rendered, an attacker can encode the dangerous characters twice and have them appear literally at the point of insertion. Any component that decodes, normalises or re-serialises a URL before rendering it is a candidate.
The defences that stop this class are output encoding applied for the exact context (HTML attribute encoding for an href), validation that the value is a well-formed URL of an allowed scheme, and a restrictive Content Security Policy that forbids inline event handlers and inline script. The report shows CSP blocking the payload in Firefox and Chrome.
How to test for it
- Find parameters that are reflected into a page, especially ones that hold URLs, redirect targets or warning destinations. Safety interstitials, logout pages, share dialogs and error pages are common hosts.
- Send a benign marker value and confirm it appears in the response. Note the exact context: inside an
href, inside a text node, inside a script block. - If the value is a URL, try encoding a space and an attribute name, for example a value ending in an encoded space followed by
onmouseover=alert(1). If the application decodes once, try double encoding so the dangerous characters survive to the render step. - If the parameter is itself a URL to the same page, nest the payload one level deeper, as in the report, and check whether the inner value is decoded again.
- Test in more than one browser. A payload that fails in Chrome may execute in Internet Explorer, and CSP behaviour differs between engines.
- A positive result is your marker appearing as executable markup or as an event handler attribute in the rendered DOM, confirmed by the handler firing.
Common false positives: the value is reflected but HTML-encoded, so it renders as text; the reflection sits inside a JavaScript string that is safely escaped; the payload fires only in your own browser because of an extension or a devtools modification; or the page is blocked by CSP in every browser you test, which limits real-world impact even if the reflection is unencoded.
How it is fixed
Hunting notes
Reflected XSS tends to hide in pages that echo user-supplied URLs: redirectors, link warnings, OAuth and login return pages, unsubscribe and confirmation pages, and error pages that print the requested path. Recon signals include parameters named after URLs (url, link, next, return, redirect, unsafe_link) and any endpoint that renders a clickable link from request data. Watch for parameters that are decoded more than once, and for pages that build markup on the client from a query string.
To get a report accepted, show the exact request and the exact response or DOM state where your payload becomes executable, name the browser where it fires, and state clearly which browsers are protected by CSP. If the payload only fires after a user interaction such as a hover or click, say so, because that affects severity. Keep the proof to the minimum that demonstrates execution, and do not claim impact such as session theft unless you have demonstrated it.
What happened, in plain words
Twitter has a safety page at twitter.com/safety/unsafe_link_warning. Think of it like a receptionist who reads out the address on a parcel before letting you take it. The page takes a value from a query parameter called unsafe_link.
The researcher, masatokinugawa, found XSS on the page via the unsafe_link parameter. If the value contains not just a web address but also extra instructions written in the same language web pages are built from (HTML), the browser can be tricked into treating those instructions as part of the page. That is cross-site scripting, usually shortened to XSS: making a trusted site run code that the site's owners never intended.
The vulnerable address has this shape:
https://twitter.com/safety/unsafe_link_warning?unsafe_link=[vulnerable_param]
Everything after the ? is a query string, a list of named values a page receives. Here the name is unsafe_link and [vulnerable_param] is a placeholder for whatever value you supply. The square brackets are not real syntax; they just mark the spot where the dangerous value goes.
The reproduction steps are short and specific to Internet Explorer (IE), Microsoft's older browser:
- Open the following URL in IE:
https://twitter.com/safety/unsafe_link_warning?unsafe_link=https%3A%2F%2Ftwitter.com%2Fsafety%2Funsafe_link_warning%3Funsafe_link%3Dhttp%3A%2F%2Fexample.com%2520onmouseover%3Dalert%281%29%2520style=font-size:100pt%2520
-
Click "continue".
-
Do mouseover to "continue". XSS occurs.
Step 1 matters because the address is the whole attack. Step 3 matters because the payload only runs when the mouse pointer moves over "continue".
The address looks like nonsense at first, so let us unpack it. The % sequences are percent-encoding, a way of writing characters that are awkward or unsafe to put in a web address. %3A is a colon, %2F is a slash, %3D is an equals sign, %28 and %29 are round brackets, and %20 is a space. Decoding the outer value once gives:
So the outer unsafe_link is itself a link back to the very same safety page, and that inner link carries a second unsafe_link value. This nesting is the clever part. The inner value is http://example.com%20onmouseover=alert(1)%20style=font-size:100pt%20. Notice the %2520: %25 is the encoding of a percent sign, so %2520 decodes to the literal text %20, not to a space. The inner value therefore still holds %20 sequences.
In HTML, a space inside a tag ends one attribute and starts the next. Hovering the "continue" link fires alert(1), a pop-up box showing the number 1, the standard harmless proof that code ran.
The researcher adds: "FYI in Firefox and Chrome, it is blocked by CSP :)". CSP stands for Content Security Policy, a set of rules a site sends with its pages telling the browser which kinds of code are allowed. A strict policy can forbid the inline event handlers that this payload relies on, which is why the same trick fails in those two browsers. The report does not say which rule was responsible, and it does not give a fix, a severity rating or a CVSS score. The platform records a bounty of 1,400 USD and disclosure on 3 April 2015.
In general, how this kind of bug works
This is reflected XSS. The word "reflected" means the input bounces straight back: you put something in the request, the server or page puts it into the response, and the browser reads it. The bug appears when that echoed text is treated as page structure rather than as plain text. A useful comparison is a comment box that prints your words on a wall: if someone writes "paint the wall red" and the caretaker reads it as an instruction instead of a comment, the message has escaped its box.
There are several ways out of the box. You can close a piece of text and open a new tag. You can close a quoted attribute with a quote character. Or, as here, you can use a space to end an attribute and start a new one. The last route is easy to miss because a space feels harmless.
Double decoding widens the problem. If a value is decoded once when it is read and again when it is displayed, an attacker encodes the dangerous characters twice so they survive to the moment of insertion. Any part of a system that decodes, tidies up or rebuilds a web address before showing it deserves a second look.
The defences are straightforward in principle.
If you want to look for this yourself, a sensible order is:
- Find parameters that get echoed into a page, especially ones holding web addresses: warning pages, redirect pages, login return pages, error pages.
- Send an ordinary marker value and confirm it appears. Note exactly where: inside a link, in plain text, inside a script block.
- If the value is a web address, try an encoded space followed by an attribute such as
onmouseover=alert(1). If one decode happens, try double encoding. - If the parameter is itself a link to the same page, nest the payload one level deeper and see whether the inner value is decoded again.
- Test in more than one browser, because a payload that fails in Chrome may run in Internet Explorer.
- Treat it as confirmed when your marker becomes executable markup or an event handler in the page and the handler actually fires.
Watch for false positives. The value may be echoed but encoded, so it shows as text. It may sit inside a script string that is safely escaped. It may fire only because of a browser extension or a change you made in developer tools. Or the page may be blocked by CSP in every browser you try, which limits real-world impact even when the echo is unencoded.
When reporting, show the exact request and the exact response or page state where your payload becomes executable, name the browser where it fires, and say which browsers are protected by CSP. If the payload needs a hover or a click, say so, because that affects severity. Keep the proof to the minimum that demonstrates execution, and do not claim consequences such as stolen sessions unless you have shown them.
Glossary
- XSS (cross-site scripting): a bug where a trusted site is made to run code an attacker supplied.
- Reflected XSS: XSS where the attacker's input is echoed back in the response rather than stored on the server.
- Query string: the part of a web address after the
?, holding named values sent to the page. - Parameter: one named value in a query string, such as
unsafe_link. - Payload: the crafted value an attacker sends to trigger the bug.
- HTML: the language web pages are written in, made of tags and attributes.
- Attribute: a setting inside an HTML tag, such as a link destination or an event handler.
- Event handler: an attribute that runs code when something happens, such as
onmouseoverwhen the mouse passes over. - Percent-encoding: writing characters as
%plus a code, such as%20for a space. - Double encoding: encoding an already encoded value, so
%20becomes%2520and survives one round of decoding. - Decoding: turning percent-encoded text back into ordinary characters.
- CSP (Content Security Policy): rules a site sends telling the browser which kinds of code may run.
- Inline event handler: an event handler written directly in an HTML attribute rather than in a separate script file.
- Internet Explorer (IE): Microsoft's older web browser, the one where this payload worked.
- Bounty: a reward a company pays for a responsibly reported security bug.
- CVSS: a standard scoring system for the severity of a vulnerability.