XSS on facebook via png content types
Facebook's CDN served uploaded files with a content type that could be changed to text/html, and angle brackets in PNG IDAT chunks were not encoded, allowing an attacker to upload a crafted PNG that executes JavaScript when served as HTML. By finding a *.facebook.com hostname pointing to the CDN, the attacker could run script in the facebook.com origin and steal CSRF tokens to perform actions as the victim.
Content uploaded to Facebook is stored on their CDN, which is served via various domains (most of which are sub-domains of either akamaihd.net or fbcdn.net).
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 CDN did not enforce a safe content type or Content-Disposition header for user-uploaded files, and the image processing pipeline preserved attacker-controlled data in PNG IDAT chunks without encoding angle brackets, allowing the file to be interpreted as HTML.
Impact
An attacker could execute JavaScript in the facebook.com origin, steal the victim's CSRF token, and perform actions on their behalf such as posting a status; however, session cookies were HTTPOnly and the attacker could not directly read them.
What the attacker needed
Ability to upload images to Facebook ads; victim visits a crafted URL
The fix
Facebook hot-fixed the issue by removing the forward DNS entry for photo.facebook.com, though the content type issue still exists and files are now hosted on a sandboxed domain.
How it was found
- Craft a PNG image whose IDAT chunk contains HTML and JavaScript that will execute when the file is served as HTML.
- Upload the crafted PNG to Facebook's advertiser image library.
- Access the uploaded file's CDN URL with the extension changed to .html, causing the browser to render the embedded HTML and run the JavaScript.
- Find a *.facebook.com hostname (photo.facebook.com) that points to the same CDN and load the crafted file through it to execute script in the facebook.com origin.
- Use document.domain to interact with a Facebook plugin page that sets document.domain to facebook.com and contains the fb_dtsg CSRF token, then extract the token.
- Use the stolen CSRF token to make arbitrary requests on behalf of the victim, such as posting a status.
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.
When you upload a picture to a website, the site stores it on a server and gives it a web address. Normally the server tells the browser 'this is an image', so the browser shows a picture. But if the server can be tricked into saying 'this is a web page', the browser will run any code inside the file. Here, the attacker hid code inside a picture file and changed the address to end in .html, so the browser ran the code as if it were a normal Facebook page.
What is XSS?
Script an attacker supplies runs in another user's browser, on the target's origin, with that user's session.