Skip to content
XSS Write-up Intermediate

XSS on Facebook instagram CDN server bypassing signature protection

The CDN server for Facebook and Instagram allowed bypassing URL signature protection by removing the /v/ parameter and changing the file extension, enabling execution of JavaScript on the CDN domain. An attacker could run arbitrary JS on the CDN, which could be used for phishing or as a Linkshim bypass, though cookies were not accessible due to the sandboxed domain.

Amol Baikar Follow

Published on amolbaikar.com

Bounty$1,500 View original

Facebook and Instagram all photos/videos and more content are stored on their CDN Server. Such one of ".fbcdn.net" and ".cdninstagram.com" and they served via various sub-domains.

Amol Baikar (@AmolBaikar), on amolbaikar.com

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.

Written with AI from the full original report and checked against it passage by passage; anything it could not back up was removed or toned down. The original is the record. 4 min read.

Context

Facebook and Instagram store their photos, videos and other content on CDN servers, served through sub-domains of *.fbcdn.net and *.cdninstagram.com. Files on these CDNs normally carry a signature in the URL, expressed through parameters such as oh and oe. If a client modifies the file extension, for example changing .jpg to .html, the signature check fails and an error is thrown.

The researcher's starting question was simple: what happens if the unnecessary parameters are stripped from the URL, leaving a clean path to the object? The target object in the write-up is:

Text
https://instagram.fpnq2-1.fna.fbcdn.net/[redacted].jpg

The response to that request was "Access Denied". After further digging, the researcher found a way to bypass the signature protection for any image or video, including links that had already expired for end users. That meant access to CDN content that had expired for the end-user.

Setup

No accounts, roles, tools or versions are described in the report. The work was done against the public CDN sub-domains of Facebook and Instagram, using the URLs of individual media objects. The only precondition visible in the text is a known media URL on the CDN, with or without a valid signature.

Finding it

The first observation was that a parameter /v/ sits at the front of the path, and the researcher describes it as existing to verify the appropriate hashes in the URL, deciding whether the object is accessible or not. Removing /v/ still returned "Access Denied", so that alone was not the answer.

The next line of thinking was cross-domain access. A DNS lookup showed the relationship between the Instagram CDN host and the Facebook CDN host:

Text
instagram.fpnq2-1.fna.fbcdn.net. 3599 IN CNAME scontent.xx.fbcdn.net.

The researcher reasoned that there was no reason to verify the signature on a cross-origin request when the two sub-domains have no connection between them other than sharing the same origin server. Working from that, raw Image, Video and Srt files could be browsed, and the extension could be changed to anything, such as .html, .svg, or even .php. The PHP shell would obviously not execute, but it demonstrated that the file could be browsed.

Exploitation

Step 1: start from a signed CDN URL

The signed URL used as the starting point was:

Text
https://instagram.fpnq2-1.fna.fbcdn.net/v/t51.2885-15/[redacted].png?_nc_cat=0&oh=[redacted]&oe=5B31E89F

This is a normal CDN object URL: the /v/ prefix, the path to the object, and the signature parameters oh and oe (plus _nc_cat).

Step 2: move to the other CDN host and change the extension

The URL was rewritten to point at the Facebook CDN host, with the /v/ prefix and the signature parameters removed and the extension changed to .html:

Text
https://scontent.xx.fbcdn.net/t51.2885-15/[redacted].html

At this point the researcher was able to execute JavaScript on the CDN server. The same technique worked for expired links, giving access to CDN content that had expired for end users.

Root cause

The report describes the /v/ path parameter as the mechanism that verifies the hashes in the URL and decides whether the object is accessible. The bypass works by requesting the object through the other CDN host (scontent.xx.fbcdn.net, the CNAME target of the Instagram CDN host) without the /v/ prefix and without the signature parameters, while changing the extension. The researcher's stated reasoning is that there was no reason to verify the signature on a cross-origin request when the two sub-domains share only the same origin server. The report does not describe the server-side code, so the exact implementation mistake is not shown;

Impact

The issue could have allowed an attacker to run arbitrary JavaScript on the Facebook CDN. Because the domain is sandboxed, it would not have allowed access to the user's cookies or session. It could, however, have been used in phishing or as a Linkshim bypass. The researcher also notes that expired CDN content could be reached, not just current objects.

Fix

The report does not describe the change that was made. The timeline records that the issue was fixed on 23 March 2018, after the initial report on 8 March 2018 and acknowledgement on 10 March 2018, and that a bounty was awarded by Facebook on 28 March 2018.

Variants to test

  1. Alternate CDN hostnames. Resolve the host serving a signed object and try the same object path on the CNAME target, without the /v/ prefix and without the signature parameters. A positive result is the object body being returned instead of "Access Denied".
  2. Extension changes. On any path that returns the raw object, request the same object with .html, .svg or another extension. A positive result is the object being served with the changed extension.
  3. Expired signatures. Take a URL whose oe expiry has passed and try the alternate host and path form. A positive result is the expired object still being served.
  4. Path prefix removal. Remove the /v/ segment on the original host and on the alternate host, and compare the responses. A positive result is the object being served without the /v/ segment.

Timeline

  • 8 Mar, 2018: initial report sent.
  • 10 Mar, 2018: acknowledgement of report.
  • 23 Mar, 2018: issue fixed.
  • 28 Mar, 2018: bounty awarded by Facebook.

Written with AI from the full original report and checked against it passage by passage; anything it could not back up was removed or toned down. The original is the record. 8 min read.

What happened, in plain words

Facebook and Instagram keep the photos and videos people upload on special computers called CDN servers. CDN stands for Content Delivery Network: a set of servers spread around the world whose only job is to hand out files quickly to whoever asks for them. Think of it like a chain of corner shops that stock copies of the same products so you never have to walk to the main warehouse.

Those files are served through web addresses (URLs) that look like *.fbcdn.net and *.cdninstagram.com. A URL is just the address you type into a browser, like a street address for a file.

Normally, each file URL carries a signature: a long string of characters added to the address that proves the link was handed out by Facebook and has not been tampered with. The signature appears as parameters such as oh and oe. A parameter is a small piece of extra information attached to the end of a URL after a ?, in the form name=value. If someone changes the file extension (the bit at the end such as .jpg), the signature no longer matches and the server throws an error instead of serving the file.

The researcher asked a simple question: what happens if you strip out the unnecessary parameters and leave a clean, short address pointing straight at the file? The file used as the target was:

Text
https://instagram.fpnq2-1.fna.fbcdn.net/[redacted].jpg

Line by line:

  • https:// is the protocol, the language the browser and server use to talk securely.
  • instagram.fpnq2-1.fna.fbcdn.net is the server name (the host). It is one of Facebook's CDN machines that serves Instagram content.
  • /[redacted].jpg is the path to one specific image file on that server.

The server answered "Access Denied". So simply removing the parameters was not enough.

After a lot of digging, the researcher found a way to bypass the signature protection for any image or video, including links that had already expired for normal users. An expired link is one whose signature included a time limit; after that time the server is supposed to refuse it. Bypassing that meant the researcher could reach CDN content that had expired for the end-user.

Vulnerability Discovery

The first thing noticed was a parameter /v/ sitting at the front of the path. The researcher describes it as existing to verify the appropriate hashes in the URL, deciding whether the object is accessible or not. A hash here is a fingerprint the server uses to decide whether the object is accessible. Removing /v/ on its own still returned "Access Denied", so that alone was not the answer.

The next idea was to think about cross-domain access. A domain is the name part of a web address, such as fbcdn.net. Two different sub-domains (like instagram.fpnq2-1.fna.fbcdn.net and scontent.xx.fbcdn.net) are treated by browsers as separate places, even if they belong to the same company. The researcher looked up how the Instagram CDN host relates to the Facebook CDN host using DNS, the internet's address book that maps names to machines. The lookup showed:

Text
instagram.fpnq2-1.fna.fbcdn.net. 3599 IN CNAME scontent.xx.fbcdn.net.

Line by line:

  • instagram.fpnq2-1.fna.fbcdn.net. is the name being looked up (the trailing dot just marks the end of the full name).
  • 3599 is how many seconds the answer may be cached (kept) by whoever asked.
  • IN means the internet class of record, a standard DNS label.
  • CNAME means Canonical Name: this name is an alias for another name.
  • scontent.xx.fbcdn.net. is the real name it points to.

So the Instagram CDN host is just another name for the Facebook CDN host. The researcher reasoned that there was no reason to verify the signature on a cross-origin request when the two sub-domains have no connection between them other than sharing the same origin server. Working from that, raw Image, Video and Srt files could be browsed. Srt files are subtitle text files. The extension could be changed to anything, such as .html, .svg, or even .php. A .php file is a script that runs on the server; the PHP shell would obviously not execute here, but it demonstrated that the file could be browsed.

From the original on amolbaikar.com

The image at the top of the write-up is the title banner for the article, showing the headline "XSS on Facebook-Instagram CDN Server bypassing signature protection".

Exploitation

Step 1: start from a signed CDN URL

The signed URL used as the starting point was:

Text
https://instagram.fpnq2-1.fna.fbcdn.net/v/t51.2885-15/[redacted].png?_nc_cat=0&oh=[redacted]&oe=5B31E89F

Line by line:

  • https://instagram.fpnq2-1.fna.fbcdn.net is the Instagram CDN host, as before.
  • /v/ is the path prefix the researcher says is used to verify the hashes.
  • /t51.2885-15/[redacted].png is the path to the object, ending in .png.
  • ?_nc_cat=0 starts the query string (the part after ?) with a parameter named _nc_cat set to 0.
  • &oh=[redacted] adds the oh signature parameter.
  • &oe=5B31E89F adds the oe parameter, one of the signature parameters.

This is a normal CDN object URL: the /v/ prefix, the path to the object, and the signature parameters oh and oe (plus _nc_cat).

Step 2: move to the other CDN host and change the extension

The URL was rewritten to point at the Facebook CDN host, with the /v/ prefix and the signature parameters removed and the extension changed to .html:

Text
https://scontent.xx.fbcdn.net/t51.2885-15/[redacted].html

Line by line:

  • https://scontent.xx.fbcdn.net is the Facebook CDN host, the CNAME target found earlier.
  • /t51.2885-15/[redacted].html is the same object path, but with no /v/ prefix, no ? query string, no oh and no oe, and the extension changed from .png to .html.

At this point the researcher was able to execute JavaScript on the CDN server. JavaScript is the programming language browsers run to make pages interactive; if an attacker can get their own JavaScript to run on a site's domain, that is called XSS (Cross-Site Scripting). The same technique worked for expired links, giving access to CDN content that had expired for end users.

Impact

The issue could have allowed an attacker to run arbitrary JavaScript on the Facebook CDN. Because the domain is sandboxed, it would not have allowed access to the user's cookies or session. A cookie is a small piece of data a site stores in your browser to remember who you are; a session is the logged-in state built on that cookie. A sandboxed domain is one the browser treats as separate from the main site, so scripts there cannot read the main site's cookies. It could, however, have been used in phishing or as a Linkshim bypass. Phishing is tricking someone into trusting a link or page that looks genuine. Linkshim is Facebook's system that warns users before they leave for an external link; bypassing it means a malicious link would not trigger that warning.

Fix

The report does not describe the change that was made. The timeline records that the issue was fixed on 23 March 2018, after the initial report on 8 March 2018 and acknowledgement on 10 March 2018, and that a bounty was awarded by Facebook on 28 March 2018. A bounty is a reward a company pays to someone who reports a security problem responsibly.

Variants to test

  1. Alternate CDN hostnames. Resolve the host serving a signed object and try the same object path on the CNAME target, without the /v/ prefix and without the signature parameters. A positive result is the object body being returned instead of "Access Denied". A 200 is the standard HTTP status code meaning the request succeeded.
  2. Extension changes. On any path that returns the raw object, request the same object with .html, .svg or another extension. A positive result is the object being served with the changed extension. Content type is the label a server attaches to a file saying what kind of file it is.
  3. Expired signatures. Take a URL whose oe expiry has passed and try the alternate host and path form. A positive result is the expired object still being served.
  4. Path prefix removal. Remove the /v/ segment on the original host and on the alternate host, and compare the responses. A positive result is the object being served without the /v/ segment.

Timeline

  • 8 Mar, 2018: initial report sent.
  • 10 Mar, 2018: acknowledgement of report.
  • 23 Mar, 2018: issue fixed.
  • 28 Mar, 2018: bounty awarded by Facebook.

Glossary

  • CDN (Content Delivery Network): a network of servers that store and serve copies of files close to users.
  • URL: the address of a file or page on the web.
  • Host: the server-name part of a URL, such as scontent.xx.fbcdn.net.
  • Path: the part of a URL after the host that points to a specific file, such as /t51.2885-15/....
  • Parameter: a name=value pair attached to a URL after a ?, used to pass extra information.
  • Signature: a string in a URL that proves the link was issued by the site and has not been altered.
  • Hash: a short fingerprint computed from data, used to check that something has not changed.
  • Extension: the suffix at the end of a filename, such as .jpg or .html, that hints at the file type.
  • Domain / sub-domain: the name part of a web address; a sub-domain is a name under a larger domain.
  • Cross-domain / cross-origin: a request from one domain to another, which browsers treat as a separate trust boundary.
  • DNS: the internet's address book, mapping names to machines.
  • CNAME: a DNS record saying one name is an alias for another.
  • XSS (Cross-Site Scripting): getting an attacker's JavaScript to run in the context of a site's domain.
  • JavaScript: the programming language browsers run to make pages interactive.
  • Cookie: a small piece of data a site stores in your browser to remember you.
  • Session: the logged-in state a site maintains, usually tied to a cookie.
  • Sandboxed domain: a domain the browser treats as isolated, so scripts there cannot read another site's data.
  • Phishing: tricking someone into trusting a fake link or page.
  • Linkshim: Facebook's system that warns users before they follow an external link.
  • HTTP status code: a number a server returns to say how a request went; 200 means success.
  • Content type: the label a server attaches to a file saying what kind of file it is.
  • Bounty: a reward paid for reporting a security problem responsibly.
  • Srt: a subtitle text file format.

More by Amol Baikar

View all

3 more disclosed reports, best first.

More from Meta

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Cross-site scripting (XSS)

The lesson behind this report.

Script an attacker supplies runs in another user's browser, on the target's origin, with that user's session.