Open Redirect in Linkedin and Yahoo
The serve-static middleware in Express.js, when mounted at the root, created an open redirect by treating a path beginning with double slashes as a protocol-relative URL. An attacker could craft a link that redirected victims from the affected site to an arbitrary external domain.
Published on medium.com
At our company we had a pentesting job to a Node.js web application. After some research I found https://nodesecurity.io, a great website with node.js vulnerabilities.
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
During a penetration test against a client's Node.js web application, the author looked for known vulnerabilities in the components the application was built on. The client's app used express.js, so the natural next step was to search for advisories affecting express.js and its middleware.
That search led to the Node Security Platform (nodesecurity.io), a site collecting Node.js vulnerabilities, and to an advisory for the serve-static middleware written by Pierre-Élie Fauché. The advisory describes the behaviour as follows:
"When using serve-static middleware version < 1.7.2 and it's configured to mount at the root it creates an open redirect on the site.
For example: If a user visits http://example.com//www.google.com/%2e%2e they will be redirected to //www.google.com/%2e%2e, which some browsers interpret as http://www.google.com/%2e%2e."
The feature involved is ordinary static file serving: the middleware maps request paths to files under a directory. When mounted at the root, a request path beginning with a double slash is treated as a protocol-relative URL by some browsers once it appears in a Location header, so the redirect leaves the site.
The author notes that this behaviour does not work in Google Chrome but does work in Firefox and Opera. That browser dependency matters for the whole write-up: the server-side redirect happens regardless, but whether the browser follows it off-site depends on how it resolves the resulting URL.
Setup
The testing was done with Burp Suite, issuing requests by hand and inspecting the responses. The advisory's precondition is a target running express.js with serve-static below version 1.7.2, mounted at the root of the site; the report does not state which versions the tested sites ran.
The author first confirmed the issue on the client's application, which was vulnerable. After that, together with @fabiopirespt and @fjreis, the team searched for top websites using express.js. That search produced two Yahoo sites and the LinkedIn mobile website:
https://touch.www.linkedin.comdeveloper.yahoo.compublish.yahoo.com
Finding it
The starting point was the published advisory, not a manual review of the targets. The team's contribution was searching for large sites using express.js and then reproducing the documented pattern against them. The LinkedIn mobile site was tested first.
Exploitation
Step 1: reproduce the advisory pattern on LinkedIn
The advisory's example uses two leading slashes. Sent to touch.www.linkedin.com, that form did not work. The team therefore increased the number of slashes and tested with four. The report presents the request and response from touch.www.linkedin.com as a screenshot rather than as text, so the exact bytes of the request are not reproduced here. The result was an open redirect.
Step 2: record the behaviour on mobile clients
The redirect was demonstrated on both mobile platforms. The proof-of-concept recordings are linked in the report:
- Android: https://vimeo.com/126193891
- iOS: https://vimeo.com/126193892
Step 3: LinkedIn timeline
The report gives the following timeline for LinkedIn:
| Date | Event |
|---|---|
| April 28, 2015 | Bug reported to LinkedIn |
| April 28, 2015 | Confirmation from LinkedIn's security team |
| May 28, 2015 | Pinged LinkedIn team |
| May 28, 2015 | Bug fixed |
| September 24, 2015 | Public disclosure |
Step 4: reproduce on the two Yahoo sites
The same class of target was found on developer.yahoo.com and publish.yahoo.com. The report again shows the request and response for each host as screenshots, without reproducing the raw request text. Proof-of-concept recordings were published for both:
- Android: https://vimeo.com/126305222
- iOS: https://vimeo.com/126320994
- Android: https://vimeo.com/126305223
Step 5: Yahoo disclosure path
Yahoo runs its bug bounty on HackerOne, and open redirects are out of scope there. The team therefore contacted Yahoo by email first. The timeline is:
| Date | Event |
|---|---|
| May 28, 2015 | Bug reported to Yahoo |
| May 28, 2015 | Yahoo's security team asks for the report to be filed in HackerOne |
| May 28, 2015 | Bug reported to HackerOne |
| May 28, 2015 | HackerOne response: "Thank you for your submission to Yahoo! We are aware of this functionality on our site and it is working as designed. Open redirects have been out of scope since January 1st, 2014. Please continue to send us vulnerability reports!" |
| September 24, 2015 | Public disclosure |
At the time of writing, both Yahoo websites were still vulnerable.
Root cause
The advisory attributes the flaw to serve-static below version 1.7.2 when mounted at the root; the report does not explain the internal cause. Some browsers then resolve the value as a protocol-relative URL and navigate off-site. The advisory's example shows the mechanism: a request for //www.google.com/%2e%2e produces a redirect to //www.google.com/%2e%2e, which some browsers interpret as http://www.google.com/%2e%2e.
The reason the two-slash form failed on LinkedIn and four slashes were needed is not explained in the report; the team simply observed that the advisory's exact form did not trigger it and adjusted the number of slashes until it did. The browser dependency is explicit: Chrome does not follow the redirect, Firefox and Opera do.
Impact
An open redirect lets a link on the trusted domain send a victim to an arbitrary destination. In practice this is used to make phishing links look legitimate, since the visible host belongs to the target.
Fix
LinkedIn fixed the bug on May 28, 2015, the same day the team pinged them. For Yahoo, no fix is described: the response stated that the behaviour was known and considered working as designed, and that open redirects had been out of scope since January 1st, 2014. Both Yahoo sites were still vulnerable at the time of publication.
Variants to test
- Slash count. The advisory's two-slash payload did not fire on LinkedIn; four slashes did. On a new target, try increasing the number of leading slashes and watch the
Locationheader for a value that a browser would resolve off-site. - Browser matrix. Test the resulting redirect in Firefox and Opera as well as Chrome, since the report shows the behaviour is browser dependent. A positive result is the browser navigating to the external host.
What happened, in plain words
A security tester was hired to break into a company's website on purpose, to find its weaknesses before criminals do. That kind of job is called a penetration test, or pentest. The website was built with a tool called Node.js, and more specifically with a piece of software called express.js. Rather than poking at the site blindly, the tester did something smarter: he looked up known bugs in the building blocks the site was made of. If a building block has a known flaw, every site built with it may share that flaw.
That search led him to a public list of Node.js bugs and to one particular bug in a component called serve-static. The bug is called an open redirect. In plain terms, an open redirect is when a website's own address can be used to send a visitor somewhere else entirely, chosen by whoever wrote the link. The visitor sees a link that starts with the trusted site's name, clicks it, and ends up on a different site. That is useful to scammers, because a link that begins with a familiar name looks safe.
After confirming the bug on his client's site, the tester and two colleagues went looking for big, well-known websites built the same way. They found two Yahoo sites and LinkedIn's mobile website. They reproduced the redirect on all of them. LinkedIn fixed it within a month. Yahoo replied that the behaviour was known, was working as intended, and that open redirects were outside the scope of its bug bounty programme, so no fix is described. At the time of writing, both Yahoo sites were still vulnerable.
The bug report that started it
The tester found a public advisory, which is a short notice describing a known security bug and how to avoid it. It was written by Pierre-Élie Fauché and hosted on nodesecurity.io, a site that collects Node.js vulnerabilities. The advisory says:
"When using serve-static middleware version < 1.7.2 and it's configured to mount at the root it creates an open redirect on the site.
For example: If a user visits http://example.com//www.google.com/%2e%2e they will be redirected to //www.google.com/%2e%2e, which some browsers interpret as http://www.google.com/%2e%2e."
Let us unpack the words in that quote, because each one matters.
- Middleware is a helper program that sits between the incoming request and the main application. Think of a receptionist in an office building: every visitor passes through them before reaching anyone else.
serve-staticis a middleware whose only job is to hand out files, such as images, stylesheets and scripts, from a folder on the server. - Version < 1.7.2 means every release of
serve-staticolder than 1.7.2 has the flaw. Version numbers work like software birthdays: bigger numbers are newer. The fix arrived in 1.7.2. - Mounted at the root means the middleware is in charge of the whole site, starting from the front page, rather than only a subsection such as
/files/. The receptionist analogy holds: this receptionist greets everyone who walks in the main door. http://example.com//www.google.com/%2e%2eis the address a victim would visit. Notice the double slash afterexample.com. In a normal web address, the part after the first single slash is a path on that site, like/about. Two slashes in a row are unusual and are the trick here.%2e%2eis a coded way of writing two dots. In web addresses, certain characters can be written in a percent-coded form so they survive being passed around.%2eis a dot, so%2e%2eis.., which on a computer usually means "go up one folder".- Redirected to
//www.google.com/%2e%2emeans the server answers with an instruction that says, in effect, "the page you want is over there, go to this address instead". That instruction is called a redirect, and the address it points to is sent in a response header namedLocation. A header is a small labelled line of extra information that travels with every web request and response, like the address block on an envelope. - Which some browsers interpret as
http://www.google.com/%2e%2eis the crucial part. An address that starts with//and nohttp:orhttps:in front is called a protocol-relative URL. Browsers read it as "use the same protocol as the current page, but a different host". So//www.google.com/...becomeshttp://www.google.com/...when the current page is plain HTTP. The browser therefore leaves the original site entirely.
The tester adds a note of his own: this does not work in Google Chrome, but does work in Firefox and Opera. That detail runs through the whole story. The server always sends the redirect; whether the browser actually follows it to the outside site depends on how that browser reads the address. Chrome apparently refuses to treat the double slash as a different host in this situation, while Firefox and Opera do.
Setting up the test
The testing was done with a tool called Burp Suite. Burp is a program that sits between your browser and a website and lets you look at, and edit, every request before it is sent. It is the standard tool for this kind of work. A request is simply the message your browser sends to a server asking for a page; the server's answer is the response.
The advisory's condition is specific: serve-static older than 1.7.2, mounted at the root of the site. The report does not state which versions the tested sites ran. The tester first checked his client's application and found it was vulnerable. That confirmed the advisory was real and gave him a working example to compare against.
A few days later, together with @fabiopirespt and @fjreis, he searched for large websites built with express.js. That search turned up two Yahoo sites and LinkedIn's mobile website:
https://touch.www.linkedin.comdeveloper.yahoo.compublish.yahoo.com
Finding it
The starting point was the published advisory, not a slow manual review of each site. The team's own contribution was to search for big sites using express.js, and then to try the documented pattern against them. In other words, they took a known recipe and looked for kitchens that could cook it. LinkedIn's mobile site was tested first.
Exploitation
Step 1: reproduce the advisory pattern on LinkedIn
The advisory's example uses two leading slashes. Sent to touch.www.linkedin.com, that form did not work. The team therefore increased the number of slashes and tested with four. The report shows the request and response from touch.www.linkedin.com as a screenshot rather than as text, so the exact bytes of the request are not reproduced here. The result was an open redirect.
Step 2: record the behaviour on mobile clients
The redirect was demonstrated on both mobile platforms. The proof-of-concept recordings are linked in the report:
- Android: https://vimeo.com/126193891
- iOS: https://vimeo.com/126193892
A proof of concept, often shortened to PoC, is a small demonstration that the bug is real and can actually be triggered.
Step 3: LinkedIn timeline
The report gives the following timeline for LinkedIn:
| Date | Event |
|---|---|
| April 28, 2015 | Bug reported to LinkedIn |
| April 28, 2015 | Confirmation from LinkedIn's security team |
| May 28, 2015 | Pinged LinkedIn team |
| May 28, 2015 | Bug fixed |
| September 24, 2015 | Public disclosure |
A few terms here. Reporting a bug means telling the company that owns the site, privately, so they can fix it before anyone else finds out. Pinging means sending a polite follow-up message because a month had passed without a fix. Public disclosure means making the details public, which usually happens after the fix is in place so that other people can learn from it without putting users at risk.
Step 4: reproduce on the two Yahoo sites
The same class of target was found on developer.yahoo.com and publish.yahoo.com. The report again shows the request and response for each host as screenshots, without reproducing the raw request text. Proof-of-concept recordings were published for both:
- Android: https://vimeo.com/126305222
- iOS: https://vimeo.com/126320994
- Android: https://vimeo.com/126305223
Step 5: Yahoo disclosure path
Yahoo runs its bug bounty programme on HackerOne. A bug bounty programme is a scheme where a company pays people for reporting security bugs, under rules. One of those rules is scope: a list of which kinds of bugs and which parts of the site count. Open redirects were out of scope at Yahoo, meaning reports about them would not be accepted or rewarded. The team therefore contacted Yahoo by email first, hoping to reach the security team directly. The timeline is:
| Date | Event |
|---|---|
| May 28, 2015 | Bug reported to Yahoo |
| May 28, 2015 | Yahoo's security team asks for the report to be filed in HackerOne |
| May 28, 2015 | Bug reported to HackerOne |
| May 28, 2015 | HackerOne response: "Thank you for your submission to Yahoo! We are aware of this functionality on our site and it is working as designed. Open redirects have been out of scope since January 1st, 2014. Please continue to send us vulnerability reports!" |
| September 24, 2015 | Public disclosure |
The reply is worth reading carefully. "We are aware of this functionality" means Yahoo already knew about the behaviour. "Working as designed" means they considered it intended, not a bug. "Out of scope since January 1st, 2014" means their bounty rules had excluded open redirects for over a year. So the report was closed without a fix.
At the time of writing, both Yahoo websites were still vulnerable.
Root cause
The advisory attributes the flaw to serve-static below version 1.7.2 when mounted at the root; the report does not explain the internal cause. Normalising means tidying an address into a standard, predictable form, the way a postal service rewrites an address into a fixed layout before delivery. Because that tidying did not happen, some browsers then resolve the value as a protocol-relative URL and navigate off-site. The advisory's example shows the mechanism: a request for //www.google.com/%2e%2e produces a redirect to //www.google.com/%2e%2e, which some browsers interpret as http://www.google.com/%2e%2e.
The reason the two-slash form failed on LinkedIn and four slashes were needed is not explained in the report; the team simply observed that the advisory's exact form did not trigger it and adjusted the number of slashes until it did. The browser dependency is explicit: Chrome does not follow the redirect, Firefox and Opera do.
Impact
An open redirect lets a link on the trusted domain send a victim to an arbitrary destination. In practice this is used to make phishing links look legitimate, since the visible host belongs to the target. Phishing is the trick of sending someone a link that appears to come from a name they trust, so they hand over a password or download something harmful.
Fix
LinkedIn fixed the bug on May 28, 2015, the same day the team pinged them. For Yahoo, no fix is described: the response stated that the behaviour was known and considered working as designed, and that open redirects had been out of scope since January 1st, 2014. Both Yahoo sites were still vulnerable at the time of publication.
Upgrading means installing the newer version of the component, which contains the corrected behaviour.
Variants to test
- Slash count. The advisory's two-slash payload did not fire on LinkedIn; four slashes did. On a new target, try increasing the number of leading slashes and watch the
Locationheader for a value that a browser would resolve off-site. - Browser matrix. Test the resulting redirect in Firefox and Opera as well as Chrome, since the report shows the behaviour is browser dependent. A positive result is the browser navigating to the external host.
Glossary
- Advisory: a public notice describing a known security bug in a piece of software, usually with the affected versions and a fix.
- Bug bounty programme: a scheme where a company offers rewards, under published rules, to people who report security bugs in its systems.
- Burp Suite: a tool that sits between a browser and a website so you can inspect and edit every request and response.
- express.js: a popular framework for building web applications with Node.js.
- Header: a labelled line of extra information sent with a web request or response, such as
Location. - HackerOne: a platform where companies run their bug bounty programmes and receive reports.
Locationheader: the response header that tells the browser where to go when the server issues a redirect.- Middleware: a helper program that processes requests on their way to the main application.
- Mounted at the root: configured to handle the whole site from the front page, rather than only a subsection.
- Node.js: a runtime that lets JavaScript run on a server, used to build web applications.
- Normalisation: tidying an address into a standard, predictable form before using it.
- Open redirect: a flaw where a trusted site's own address can be used to send a visitor to an arbitrary other site.
- Out of scope: excluded from a bug bounty programme's rules, so reports about it are not accepted or rewarded.
- Penetration test: an authorised attempt to break into a system in order to find its weaknesses.
- Phishing: tricking someone with a link or message that appears to come from a trusted name, to steal information or deliver something harmful.
- Ping: a short follow-up message to someone who has not responded or acted yet.
- Proof of concept (PoC): a small demonstration that a bug is real and can actually be triggered.
- Protocol-relative URL: an address starting with
//and nohttp:orhttps:, which a browser reads as "same protocol, different host". - Public disclosure: making the details of a bug public, usually after it has been fixed.
- Redirect: a server response telling the browser to go to a different address instead.
- Request: the message a browser sends to a server asking for a page or resource.
- Response: the server's answer to a request.
serve-static: a middleware for express.js that serves files from a folder on the server.- Subdomain: a named section of a site, such as
touch.intouch.www.linkedin.com, often built separately from the main site. - Unauthenticated: reachable without logging in or having an account.
- Version number: a label such as 1.7.2 that identifies which release of a piece of software you have; higher numbers are newer.