xss in Yahoo Fantasy Sport
A stored cross-site scripting flaw existed in Yahoo Fantasy Sports message boards, allowing an attacker to inject script that executed when any user viewed a malicious post. This could let an attacker steal cookies and access the victim's Yahoo account across services.
web.archive.org
Published on web.archive.org
This will be my first write up with regards to my security research. The following post will walk through a stored Cross Site Scripting (XSS) bug that I found that was affecting all of Yahoo!'s different Fantasy Sport Leagues.
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
Yahoo! runs a Fantasy Sports platform covering a range of sports, each hosted on its own subdomain. Every sport subdomain shares some common features, and one of them is the message board: a forum-like area where users who have joined a league can create posts, share images and otherwise interact. The message board lets users who have joined the league create posts, and the stored payload fired for anyone who viewed the post, including league administrators.
This write-up covers a stored Cross-Site Scripting (XSS) issue in that message board functionality, affecting all of Yahoo!'s Fantasy Sport leagues.
Setup
The only precondition described is membership of a league or group on any Yahoo! Fantasy Sports league. From there, the researcher used the standard message board interface: the 'Post New Topic' button and the rich text editor. No special tools, versions or elevated roles are mentioned.
Finding it
The message board behaves like a typical online forum: members create topics with a title and a body.
Exploitation
Step 1: open the message board
After joining any league or group for any Yahoo! Fantasy Sports league, go to the league's Message Board. The board looks like this:
Step 2: start a new topic
Clicking the 'Post New Topic' button opens the post creation screen:
Step 3: switch to the rich text editor
Switch the editor into Rich Text mode:
Step 4: submit the payload
The title was set to random plain text, because adding any HTML to the title caused a validation error. The body received the following payload:
<img src="x:? title=" onerror=alert(document.domain)//">
The application then rendered it as:
<img src="x:? title=" title="" onerror="alert(document.domain)//">
The parsing is the interesting part. The payload deliberately omits a closing double quote after x:, so the double quote that opens the title attribute closes the src attribute value instead. Yahoo! then added an empty title attribute of its own (title=""). The rendered tag carries the onerror handler, and the XSS fired any time anyone viewed the post. The XSS fired any time anyone viewed the post, including the researcher immediately after submitting it, and it worked across all browsers.
Root cause
The application accepts HTML in the post body through the rich text editor and re-renders it, and its handling of attribute quoting lets an attacker break out of an attribute value. The payload shows the sanitiser or parser reconstructing the tag rather than rejecting it: the unclosed src value is closed by the attacker's own quote, and an empty title attribute is appended. Adding HTML to the title caused a validation error, while the body accepted the payload. The report does not describe the underlying cause.
Impact
The stored XSS could be used to execute malicious JavaScript against any user who viewed the message, including league administrators. Because Yahoo! uses shared cookies across its services and those cookies are accessible to JavaScript, an attacker could have stolen cookies and logged into the victim's account on any Yahoo! service. Because the shared cookies were accessible to JavaScript, stolen cookies could be used to log into the victim's account on any Yahoo! service.
Fix
Yahoo! patched the vulnerability; the report does not describe the code change.
Variants to test
- Unclosed attribute values in any rich text field: submit a tag whose attribute value is left open, as in the payload above, and check whether the application closes it with your own quote and appends attributes of its own. A positive result is a rendered tag where your quote terminates the attribute and your event handler survives.
- Attribute injection through a second attribute: place a quote inside a value that the application later re-quotes, and look for a new attribute appearing in the output. A positive result is an event handler such as
onerrororonloadin the rendered markup. - Title versus body handling: the title rejected HTML while the body did not. Try the same payload in every field of the form and compare validation behaviour. A positive result is any field that accepts markup the others reject.
- Cross-subdomain reach: if cookies are shared and readable from JavaScript, a payload stored on one subdomain can act on the others. A positive result is
document.cookiereturning session material on a sibling service.
Timeline
- 11/23/2016: vulnerability found and reported via Yahoo's bug bounty programme on HackerOne
- 11/25/2016: vulnerability accepted and triaged by the Yahoo team
- 12/03/2016: vulnerability patched by Yahoo Security
- 12/05/2016: report marked 'Resolved' on HackerOne
- 12/07/2016: Yahoo awarded an $800 bounty
What happened, in plain words
Yahoo! runs a Fantasy Sports platform for a variety of sports, each hosted on its own subdomain. Each sport (football, baseball and so on) lives on its own subdomain, which is a separate address under the main yahoo.com name, like a different room in the same building. Each sport subdomain has a message board, a forum where league members can create posts and share images.
The researcher found that the message board stored HTML containing an event handler that ran when the post was viewed. Whenever any league member opened that post, the instruction ran in their browser. This kind of bug is called stored Cross-Site Scripting, or stored XSS: "stored" because the malicious content is saved on the server and served to everyone who looks at it, and "scripting" because the attacker gets to run their own JavaScript, the programming language browsers use to make pages interactive.
Because Yahoo! shares login cookies across its services, and those cookies can be read by JavaScript, the attacker could in principle have taken over the victim's account on any Yahoo! service, not just the sports site. Yahoo! patched it and awarded an $800 bounty.
Background: the product and the feature
Yahoo! hosts its own Fantasy Sports platform for a variety of sports. Each sport sits on its own subdomain. Some features are common to all of them, such as the message board, and others are specific to a sport. The message board works like a typical online forum: users who have joined the league can create posts, share images and so on. It was in this message board that the researcher found a stored XSS vulnerability that could be exploited against any user who viewed the malicious message.
A few ideas worth having straight before we go further:
- HTML is the markup language that describes what a page contains: paragraphs, images, links. It is written as tags in angle brackets, such as
<img>for an image. - An attribute is an extra setting written inside a tag, in the form
name="value". For an image,srcsays where the picture file lives andtitleis the tooltip text shown when you hover over it. - JavaScript is code that the browser runs. A page can include it, and so can an attribute such as
onerror, which the browser runs when something goes wrong, for example when an image fails to load. - A cookie is a small piece of text a website asks your browser to keep and send back on every later request. It is how a site remembers that you are logged in, a bit like a wristband at an event: show it at the door and you get in without proving who you are again.
- XSS means an attacker manages to get their own JavaScript into a page that other people view, so it runs with the trust of the real site. "Stored" means the malicious content is saved on the server first, so it fires for every visitor, not just whoever clicks a crafted link.
Setup
The only precondition described is membership of a league or group on any Yahoo! Fantasy Sports league. From there, the researcher used the standard message board interface: the 'Post New Topic' button and the rich text editor. No special tools, versions or elevated roles are mentioned.
A rich text editor is the box on a web page that lets you format a post with bold, italics and images, instead of typing raw HTML. Under the hood it usually produces HTML for you, which is exactly why it is interesting to a security researcher: whatever you type has to be turned into markup, and that conversion is where mistakes happen.
Finding it
The message board behaves like a typical online forum: members create topics with a title and a body.
Parsing means reading text according to a set of grammar rules and working out its structure. Browsers are famously forgiving parsers: given slightly broken HTML, they do not give up, they guess what you meant and build a page anyway. That forgiving behaviour is what this bug turns against the site.
Exploitation
Step 1: open the message board
After joining any league or group for any Yahoo! Fantasy Sports league, go to the league's Message Board. The board looks like this:
The screenshot shows the ordinary message board of a league, the starting point any member sees.
Step 2: start a new topic
Clicking the 'Post New Topic' button opens the post creation screen:
This is the form where a member writes a title and a body. Nothing unusual so far; the researcher simply wanted to see what the form would accept.
Step 3: switch to the rich text editor
Switch the editor into Rich Text mode:
The payload was submitted after switching the editor into Rich Text mode.
Step 4: submit the payload
The title was set to random plain text, because adding any HTML to the title caused a validation error. The body received the following payload:
<img src="x:? title=" onerror=alert(document.domain)//">
Line by line, in plain words:
<imgstarts an image tag. The browser now expects a list of attributes.src="x:?begins thesrcattribute, the address of the image, and opens a double quote.title="is where the trick happens. The researcher's text contains a second double quote, and because thesrcvalue was never closed, the browser treats that quote as the end of thesrcvalue. Everything after it is read as a new attribute,title, whose value is opened by the next quote.onerror=alert(document.domain)//adds an event handler calledonerror. The browser runs this code when the image fails to load.alert(document.domain)pops up a box showing the domain of the current page, which is a harmless way of proving that code of the attacker's choosing really ran.">closes the tag.
The application then rendered it as:
<img src="x:? title=" title="" onerror="alert(document.domain)//">
Compare the two and you can see what the site did:
- The
srcvalue is nowx:? title=, because the site accepted the researcher's quote as the closing quote ofsrc. In other words, the site did not reject the unclosed attribute; it rebuilt the tag around it. - The site then added an empty
titleattribute of its own,title="". - The
onerrorhandler survived intact and is now a real attribute of the image.
The parsing is the interesting part. The payload deliberately omits a closing double quote after x:, so the double quote that opens the title attribute closes the src attribute value instead. Yahoo! then added an empty title attribute of its own (title=""). The result is an img element whose src is invalid, which triggers the onerror handler and runs alert(document.domain). The XSS fired any time anyone viewed the post, including the researcher immediately after submitting it, and it worked across all browsers.
Root cause
The application accepts HTML in the post body through the rich text editor and re-renders it, and its handling of attribute quoting lets an attacker break out of an attribute value. The payload shows the sanitiser or parser reconstructing the tag rather than rejecting it: the unclosed src value is closed by the attacker's own quote, and an empty title attribute is appended. Adding HTML to the title caused a validation error, while the body accepted the payload. The report does not describe the underlying cause.
Two terms there are worth unpacking:
- A sanitiser is a filter that is supposed to strip dangerous parts out of HTML before it is stored or shown. A good sanitiser removes the whole tag if it cannot make sense of it.
- A parser differential is when two programs read the same text differently.
Impact
The stored XSS could be used to execute malicious JavaScript against any user who viewed the message, including league administrators. Because Yahoo! uses shared cookies across its services and those cookies are accessible to JavaScript, an attacker could have stolen cookies and logged into the victim's account on any Yahoo! service. Because the shared cookies were accessible to JavaScript, stolen cookies could be used to log into the victim's account on any Yahoo! service.
To see why that is serious, remember the wristband comparison. If a script running on a Yahoo! page can read the cookie, it can copy the wristband and use it elsewhere. The report says the cookies were accessible to JavaScript and shared across services.
Fix
Yahoo! patched the vulnerability; the report does not describe the code change.
Variants to test
These are the follow-up checks a researcher would run on a similar feature. Each one is a small experiment you could repeat on a site you are allowed to test.
- Unclosed attribute values in any rich text field: submit a tag whose attribute value is left open, as in the payload above, and check whether the application closes it with your own quote and appends attributes of its own. A positive result is a rendered tag where your quote terminates the attribute and your event handler survives.
- Attribute injection through a second attribute: place a quote inside a value that the application later re-quotes, and look for a new attribute appearing in the output. A positive result is an event handler such as
onerrororonloadin the rendered markup. - Title versus body handling: the title rejected HTML while the body did not. Try the same payload in every field of the form and compare validation behaviour. A positive result is any field that accepts markup the others reject.
- Cross-subdomain reach: if cookies are shared and readable from JavaScript, a payload stored on one subdomain can act on the others. A positive result is
document.cookiereturning session material on a sibling service.
Timeline
- 11/23/2016: vulnerability found and reported via Yahoo's bug bounty programme on HackerOne
- 11/25/2016: vulnerability accepted and triaged by the Yahoo team
- 12/03/2016: vulnerability patched by Yahoo Security
- 12/05/2016: report marked 'Resolved' on HackerOne
- 12/07/2016: Yahoo awarded an $800 bounty
A bug bounty programme is a scheme where a company invites outsiders to report security problems and pays for good ones. Triaged means the company's security team looked at the report, confirmed the bug is real and put it in the queue to be fixed. Resolved is the status the report was given once the fix was out.
Glossary
- Attribute: a setting inside an HTML tag, written as
name="value", such assrcortitleon an image. - Bug bounty programme: a scheme where a company pays outsiders for reporting security vulnerabilities.
- Bounty: the reward paid for a valid report.
- Cookie: a small piece of text a site stores in your browser and receives back on later requests, commonly used to keep you logged in.
- Cross-Site Scripting (XSS): a bug where an attacker gets their own JavaScript to run in another user's browser on a trusted site.
- Stored XSS: XSS where the malicious content is saved on the server and served to every visitor of the affected page.
- document.cookie: the JavaScript property that reads the cookies belonging to the current page.
- document.domain: the JavaScript property that returns the domain of the current page, used here to prove code ran.
- Event handler: an attribute such as
onerrororonloadwhose value is JavaScript the browser runs when that event happens. - HTML: the markup language that describes the structure and content of a web page.
- HackerOne: the platform where the report was submitted and tracked.
- JavaScript: the programming language browsers run to make pages interactive.
- onerror: an event handler that fires when a resource, such as an image, fails to load.
- Parsing: reading text according to grammar rules to work out its structure; browsers parse HTML very forgivingly.
- Parser differential: a situation where two programs read the same input differently, which an attacker can exploit.
- Payload: the piece of input an attacker submits to trigger a vulnerability.
- Rich text editor: a form control that lets you format a post and produces HTML behind the scenes.
- Sanitiser: a filter that removes or neutralises dangerous parts of HTML before it is stored or displayed.
- src: the HTML attribute that gives the address of an image or other resource.
- Subdomain: a separate address under a main domain, such as one per sport on the Fantasy Sports platform.
- title: the HTML attribute that holds tooltip text for an element.
- Triaged: reviewed and confirmed by the company's security team, and queued for a fix.
- Validation error: a message from a form refusing input it considers invalid, as happened when HTML was put in the title field.
- Vulnerability: a weakness in software that an attacker can use to do something the designers did not intend.