Abusing CORS for an XSS on flickr
The mobile Flickr site loaded pages via AJAX using a URL from the fragment, and a regex check to ensure the URL was from m.flickr.com was not anchored to the start of the string. An attacker could supply a URL containing m.flickr.com to load an external page, which was then inserted with innerHTML, leading to XSS.
I recently found an XSS on the mobile version of Flickr (http://m.flickr.com). Due to the way the bug is triggered, I thought it deserved a write-up.
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.
Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.
How it worked
Root cause
Likely the domain validation regex was not anchored to the start of the string, allowing a URL containing the trusted domain anywhere to pass, and the response was inserted via innerHTML without sanitisation.
Impact
An attacker could execute arbitrary JavaScript in the context of the mobile Flickr site.
What the attacker needed
Victim visits a crafted URL; attacker controls an external server
The fix
The issue was fixed by anchoring the regex to the start of the string and adding another regex to check for a leading double slash.
How it was found
- Notice that pages are loaded via AJAX with the path stored in the URL fragment.
- Observe that a function checks location.hash and calls showSelectedPage, which prepends a slash if missing and then calls showPageByHref.
- See that showPageByHref uses a regex to ensure the URL is from m.flickr.com, but the regex is not anchored.
- Craft a URL containing m.flickr.com to bypass the check and load an external page.
- The external page responds with CORS headers and a payload, which is inserted via innerHTML and executed.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.
The site used the part of the address after the # symbol to decide which page to load. It tried to check that the address was on its own domain, but the check was flawed and could be fooled by putting the domain name later in the address. The loaded content was then placed directly into the page, so malicious code could run.
What is XSS?
Script an attacker supplies runs in another user's browser, on the target's origin, with that user's session.