Skip to content
XSS Write-up Advanced

Exploring the World of ESI Injection

The application reflected user input without proper sanitisation, allowing Edge Side Include (ESI) tags to be injected and rendered by the caching server. An attacker could use ESI tags to execute JavaScript, steal session cookies, and achieve account takeover.

Sudhanshu Rajbhar Follow

Published on sudhanshur705.medium.com

In this writeup I will be sharing my findings related to ESI (Edge Side Include) Injection which me and my friend nytr0gen found on a Private bug bounty program. We found a bunch of them so make sure you read it till the last , as you won’t miss the most interesting findings in that manner :)

Sudhanshu Rajbhar, on sudhanshur705.medium.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. 13 min read.

Context

This write-up covers a series of Edge Side Include (ESI) injection findings that Sudhanshu Rajbhar (@sudhanshur705) and nytr0gen (@nytr0gen_) reported on a private bug bounty program. The target is referred to as redacted.com, described only as a very famous sports organisation. The work spans several subdomains of that target and, in one case, a proxy feature that fetches URLs from a whitelist of hosts.

ESI is a markup language that caching servers (in this case Akamai) use to assemble dynamic fragments into a cached page. Tags such as esi:include let the edge pull in fragments, and variables such as $(HTTP_COOKIE) and $(QUERY_STRING{x}) let the edge insert request data into the response. When user input reaches an ESI tag that the caching server renders, the attacker controls what the edge assembles into the page.

Setup

The testing was done against a private program, so no hostnames, versions or account details are given beyond the redacted naming. The tools mentioned are a Burp Suite Pro trial with the Active Scan++ extension, and testing in Firefox, Chrome and Safari. The program allowed collaboration on reports, which is how the two researchers worked together: the collaborator section of the program was used to contact nytr0gen.

A precondition that matters throughout: the application session cookies were marked httponly and scoped to .redacted.com. A plain XSS therefore could not read them, which is why the ESI variable tricks became the interesting part.

Finding it

The starting point was an XSS hunt. The researcher found an endpoint that reflected <>'" characters as they were, but could not get XSS because of the Akamai WAF in place. Looking at the page source, a block of code looked suspicious:

From the original on sudhanshur705.medium.com

Knowing about ESI, the researcher stopped trying to pop an alert and started checking whether the caching server would render inputted ESI tags:

From the original on sudhanshur705.medium.com

The first payload was blocked by the WAF. Further testing showed the WAF looked for patterns like <esi:placeholderhere> and blocked them if they contained any valid ESI tag such as include. Sending just <esi:> returned a 500 Internal Server Error, which confirmed the caching server was actually trying to render ESI tags. Various characters such as %00 and %0A were tried to bypass the check, and none worked.

At that point Burp Pro's Active Scan++ extension produced this output for the parameter:

Text
https://globe.redacted.com/?showFooter=um6k%3c!--esi--%3e8omf%3c!--esx--%3eekdiNote: This issue was generated by the Burp extension: Active Scan++.Issue detailThe application appears to support Edge Side Includes:  The following probe was sent: um6k<!--esi-->8omf<!--esx-->ekdi In the response, the ESI comment has been stripped: um6k8omf<!--esx-->ekdi  Refer to https://gosecure.net/2018/04/03/beyond-xss-edge-side-include-injection/ for further information

The probe um6k<!--esi-->8omf<!--esx-->ekdi came back with the ESI comment stripped, leaving um6k8omf<!--esx-->ekdi. That confirmed ESI injection through the comment tag, but it was not yet useful, so the endpoint went into the researcher's notes.

A couple of months later the program launched a promotion paying 2x for all high and critical submissions. That made escalating the endpoint worth another attempt. Since the researcher judged the WAF bypass to be beyond their own skillset, they used the program's collaborator section to contact nytr0gen, a member of the WreckTheLine CTF team.

Exploitation

Step 1: a working ESI payload for XSS

Within roughly 30 minutes nytr0gen produced a working ESI payload that pops an XSS alert box:

From the original on sudhanshur705.medium.com

The payload uses variables inside the ESI comment tag, which the researcher had not known was possible. The relevant documentation is the Oracle ESI language tags page:

https://docs.oracle.com/cd/A97335_02/caching.102/a90372/esi.htm#633138 From the original on sudhanshur705.medium.com

https://docs.oracle.com/cd/A97335_02/caching.102/a90372/esi.htm#633138

When the caching server renders the payload, only this remains in the page source:

From the original on sudhanshur705.medium.com

$(QUERY_STRING{countryCode}) returned the value of the countryCode parameter. Because the session cookies were httponly, a normal XSS could not read them, but the ESI variables made it possible to reach them. A full account takeover proof of concept was included in the report, the issue was triaged, and it was rewarded with a high severity rating, doubled by the 2x multiplier:

From the original on sudhanshur705.medium.com

Step 2: a second subdomain with case mangling

nytr0gen found another subdomain where XSS worked through ESI tags and the caching server rendered them. That suggested more ESI injection bugs across the target. This application performed an odd uppercase/lowercase transformation of input, so variables such as HTTP_COOKIE could not be used directly: it was transformed into something like http_COOKIE. nytr0gen went back to the docs and found another ESI function that decodes URL-encoded strings:

https://www.akamai.com/site/zh/documents/technical-publication/akamai-esi-developers-guide-technical-publication.pdf From the original on sudhanshur705.medium.com

https://www.akamai.com/site/zh/documents/technical-publication/akamai-esi-developers-guide-technical-publication.pdf

The payload was URL-encoded twice to make sure Akamai would not block it:

From the original on sudhanshur705.medium.com

Step 3: ESI on a subdomain with no ESI in the source

The researcher had already found an XSS on another subdomain where there were no signs of ESI tags in the page source, but decided to try anyway with this payload:

Text
aaa<!--esi-->bbb<!--esx-->ccc

The server rendered it, confirming ESI injection, and the same payload was used for account takeover:

From the original on sudhanshur705.medium.com

The account takeover proof of concept placed the JavaScript after the hash, shown below the main payload for readability:

From the original on sudhanshur705.medium.com

Because HTTP_COOKIE and QUERY_STRING{x} are already understood by this point, the PoC is easy to follow. It turned out nytr0gen had submitted this XSS bug 10 months earlier; it was reported again because the ESI version had much more impact than a normal XSS:

From the original on sudhanshur705.medium.com

Another high severity bug.

Step 4: JSON content type and add_header

A few days later nytr0gen found another vulnerable endpoint:

From the original on sudhanshur705.medium.com

The response Content-Type for this endpoint was application/json, and the ESI tags were still rendered by the caching server. The problem was that XSS does not normally work with Content-Type: application/json, so stealing the cookie in the page response looked impossible.

The answer is the $add_header() method, which can overwrite any response header:

From the original on sudhanshur705.medium.com
https://www.akamai.com/site/zh/documents/technical-publication/akamai-esi-developers-guide-technical-publication.pdf

The payload below changes the response content-type to text/html:

From the original on sudhanshur705.medium.com

The final payload executes JavaScript by first using HTTP_COOKIE, then add_header, then the url_decode function:

From the original on sudhanshur705.medium.com

HTTP_COOKIE returns the cookies in the response, add_header changes the content type, and url_decode delivers the XSS payload, URL-encoded twice to avoid the WAF, which can then steal the page response. The bug was rewarded:

From the original on sudhanshur705.medium.com

Step 5: the proxy endpoint and a third-party XSS

The next endpoint looked like a proxy that takes a URL parameter and fetches the response of that URL:

From the original on sudhanshur705.medium.com

It only whitelisted a few domains, some on redacted.com and some on third-party sites. Because of how it worked, the pair started testing for SSRF, and since only whitelisted hosts could be requested, they looked for open redirects on those hosts.

They found one on redacted.com, but it only worked for authenticated users. Visiting this URL:

loaded another URL inside an iframe which then redirected to the supplied URL. XSS was attempted but did not work because the redirect happened via the Location header:

From the original on sudhanshur705.medium.com

They moved on to the third-party sites in the whitelist and found no useful open redirect, although they did find some XSS on those sites. SSRF looked close but arbitrary requests were not possible.

While playing with the endpoint, the researcher put the XSS-vulnerable third-party endpoint into the URL parameter, and the XSS popup appeared in the context of the redacted.com domain:

From the original on sudhanshur705.medium.com

Since an ESI injection had already been reported on this host, an ESI payload was tried and it worked. So an XSS on a different third-party domain gave ESI injection on the target domain. SSRF was not achieved after a couple of days of looking for an open redirect, but the issue was escalated through ESI injection and reported.

Step 6: an open redirect built from add_header

Using the add_header function, the pair tried to create their own open redirect with a payload like this:

From the original on sudhanshur705.medium.com

On any of the previously vulnerable ESI endpoints this gives a simple open redirect. It worked normally, but when the resulting open redirect URL was used on the proxy endpoint it did not work, possibly because of the Akamai WAF.

The bug was then marked as a duplicate by the HackerOne triager:

From the original on sudhanshur705.medium.com

After back and forth with the triager, they learned that the original reporter had escalated the issue to SSRF, without the ESI trick. The report was dropped, the promotion ended, and the pair stopped, expecting a low chance of another promotion.

Step 7: the second promotion and the moved JSON endpoint

Four to five months later the same 2x multiplier promotion launched again. Some callback parameters were tested because they usually reflect input, and some allowed <> characters, but the caching server configuration on those hosts was different so the ESI tags did not work.

Some old reports had already been fixed. nytr0gen found that the same JSON API endpoint was now reachable over a different path: to fix the original JSON API ESI bug the endpoint had been removed, but the same endpoint existed on another path, so the bug was still there. The same PoC reproduced it. It was submitted as a different endpoint even though it was the same API, triaged by the program, and rewarded as high again. This time the team asked a question about mitigation:

From the original on sudhanshur705.medium.com

Step 8: the best bug, a JSON endpoint that ignored ESI

The last endpoint found had Content-Type: application/json:

From the original on sudhanshur705.medium.com

The locale parameter value was reflected in the source, but the ESI tags were not rendered by the caching server, even though an ESI injection had been found on this host before. The URL was sent to nytr0gen, who agreed it should have worked. After some time he reported that he had got it working but that it was not useful:

From the original on sudhanshur705.medium.com

The change to spot in the request is the URL-encoded . in the URL, %2e:

From the original on sudhanshur705.medium.com

The backend server decoded the %2e in the URL and returned the same response. The caching server did not ignore the %2e, so it no longer treated the request as a static file and allowed the ESI tags to work. It worked, but was not exploitable: if the URL is sent to a victim, the browser auto-decodes the %2e, so the request goes to the original endpoint rather than the one needed, and the ESI tags are not rendered. More time was spent on this without finding a way to make it work in the browser.

Step 9: client-side path traversal and the iframe idea

A month later, while testing another program, the researcher had a potential client-side path traversal bug where the key variable in the JavaScript below was controllable:

From the original on sudhanshur705.medium.com

There was also a JSONP callback endpoint on the same host, so the aim was to load it instead of the /api.js file, which would pop an alert:

From the original on sudhanshur705.medium.com

The key variable value came from a query parameter, so the # symbol could not be used: putting # in the parameter value means the browser consumes it and it is not passed in the key value. URL-encoding it as %23 means the browser does not auto-decode it while fetching the JS file, so the researcher was stuck. The ? could not be used to ignore the /api.js part because of this code:

From the original on sudhanshur705.medium.com

Inside the getAllUrlParams method, the first line is url.split('?')[1], so a ? in the URL parameter value is dropped:

From the original on sudhanshur705.medium.com

The ? is completely ignored because of the split method. Loading the URL with the URL-encoded # inside an iframe was tried, but did not work.

The same idea was then applied to the redacted target, going back to the earlier endpoint:

From the original on sudhanshur705.medium.com

Loading this URL in an iframe was tried:

From the original on sudhanshur705.medium.com

It worked. Loading the same code in Chrome did not work, because %2e was automatically decoded by Chrome:

From the original on sudhanshur705.medium.com

So it worked in Firefox but not Chrome, and later the researcher confirmed it also worked in Safari the same way as Firefox. nytr0gen was contacted with the good news:

From the original on sudhanshur705.medium.com

Step 10: cookies in an iframe and a WAF bypass for text/html

When HTTP_COOKIE was used, not all cookies were present, notably the session cookie. nytr0gen explained this was because the page was loaded inside an iframe and the parent was of a different origin. Instead, another XSS (created using one of the earlier ESI injection bugs) was used to iframe the .json URL, and this time the cookie appeared.

Using the add_header method to change the application/json content type to text/html was blocked by the WAF. After shortening the payload, the researcher found the WAF was now blocking the text/html keyword, possibly a rule added when the previous report was fixed, so a bypass was needed.

Fuzzing showed that %09, the tab character (\t), was converted to t by the server. The payload below changed the Content-Type, and XSS was then used to steal the session cookie:

From the original on sudhanshur705.medium.com

This one was not rewarded with the 2x multiplier because the asset was not part of the promotion, which the pair agreed with, since it was still paid as a high severity even though it only worked in Firefox and not Chrome. Finally, the program manager asked them to stop testing for ESI injection bugs while the WAF was tuned:

From the original on sudhanshur705.medium.com

Root cause

User input reaches the caching server inside a context where ESI tags are parsed and rendered. The application reflects characters such as <>'" and the edge assembles the response, so an attacker who can get an ESI tag into the response controls what the edge inserts. The WAF blocked valid ESI tags such as include, but the comment form and the variable syntax inside it still worked. and neither were the encoding tricks (url_decode, double URL-encoding, %2e, %09). The httponly flag and .redacted.com scope did not prevent the ESI variables from exposing the cookies. and add_header can turn a JSON response into text/html so the injected script executes.

Impact

On the affected endpoints the attacker could execute JavaScript in the target origin and read the session cookies, which were httponly and scoped to .redacted.com, and account takeover PoCs were provided. The JSON endpoint variant required add_header to change the content type, and the final variant only worked when the URL was loaded in Firefox or Safari, not Chrome, because Chrome auto-decodes %2e. The proxy endpoint allowed an XSS on a whitelisted third-party domain to run in the redacted.com context and to reach ESI injection there. SSRF through the proxy was not achieved by this pair; the duplicate report showed another researcher had escalated it to SSRF without the ESI trick.

Fix

The report does not describe the fixes applied by the program. The original JSON API endpoint was removed and the same API reappeared on another path; the researchers suspected a WAF rule blocking text/html came from the earlier fix, and bypassed it with %09. The program manager asked them to stop testing ESI injection while the WAF was tuned.

Variants to test

  1. Send aaa<!--esi-->bbb<!--esx-->ccc to any reflected parameter. A positive result is the comment being stripped in the response, which confirms ESI processing.
  2. Send <esi:> alone. A 500 error suggests the caching server is trying to render ESI tags.
  3. Try $(QUERY_STRING{param}) and $(HTTP_COOKIE) inside an ESI comment. A positive result is the parameter value or the cookies appearing in the response body.
  4. On JSON endpoints, try $add_header('content-type','text/html') combined with url_decode. A positive result is the response content type changing and the injected script executing.
  5. Where a WAF blocks text/html, try %09 in place of the space or characters in the keyword, and try double URL-encoding. A positive result is the header change going through.
  6. Where a URL is treated as a static file, try %2e in the path. A positive result is the backend returning the same response while the caching server renders ESI tags; check whether the browser decodes it before sending.
  7. On proxy or fetch features with a host whitelist, look for XSS or open redirects on the whitelisted hosts and pass them in the URL parameter. A positive result is script executing in the target origin, or ESI tags rendering there.
  8. Try $add_header('Location','https://evil.com') on an ESI-vulnerable endpoint to build an open redirect, and check whether it survives when passed through a proxy feature.

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. 21 min read.

What happened, in plain words

Two researchers, Sudhanshu Rajbhar (@sudhanshur705) and nytr0gen (@nytr0gen_), spent several months finding a family of bugs on a private bug bounty program. A bug bounty program is a scheme where a company invites outside testers to look for security problems in its systems and pays them for reporting what they find. The company in this story is only ever called redacted.com, and the authors describe it as a very famous sports organisation. They found bugs on several of its subdomains, and once through a feature that fetches other web pages.

The bug class is called Edge Side Include (ESI) injection. To understand it you need to know what a caching server is. When a website is popular, it does not want to rebuild every page from scratch for every visitor, so it puts a copy of the page in a fast intermediate machine called a cache. The cache hands the stored copy to visitors and only asks the real server (the "backend") for the small pieces that change. ESI is a small markup language that tells the cache which pieces to fetch and where to put them. A tag like esi:include means "go and fetch this fragment and paste it here". Variables like $(HTTP_COOKIE) and $(QUERY_STRING{x}) mean "paste the visitor's cookies here" or "paste the value of parameter x here".

The danger is simple: if a visitor's own input ends up inside an ESI tag that the cache processes, the visitor controls what the cache pastes into the page. That is the whole bug. The authors used it to run JavaScript in the victim's browser (cross-site scripting, or XSS) and to read cookies that were supposed to be unreadable, and they also tried to build an open redirect.

A cookie is a small piece of data a website asks your browser to store and send back on every request. The most important one is the session cookie: it is the ticket that proves you are logged in. If an attacker can read it, they can often log in as you, which is called account takeover. The site had marked its session cookies httponly, a setting that tells the browser "JavaScript must never be allowed to read this cookie". That normally defeats cookie-stealing XSS. It did not help here, because the ESI variables exposed the cookies in the response.

A WAF (Web Application Firewall) is a filter that sits in front of a website and blocks requests that look malicious. The site used an Akamai WAF, and much of the story is about getting payloads past it. A payload is the piece of text an attacker sends to trigger the bug.

The starting point: a reflected parameter and a WAF

The hunt began as an XSS search. XSS means getting your own JavaScript to run inside someone else's website, in the context of that site, so it can act with that site's permissions. The researcher found an endpoint (a URL the site responds to) that reflected the characters <>'" back unchanged. Reflection means the site copies your input into its response. Those characters matter because HTML uses < and > to mark tags, so being able to inject them is often the first step to injecting a script tag.

Even so, a plain XSS was not achievable because of the Akamai WAF. While reading the page source (the HTML the browser received), the researcher noticed a block of code that looked suspicious:

From the original on sudhanshur705.medium.com

Because the researcher already knew about ESI, the plan changed: instead of trying to make an alert box appear, check whether the caching server would process ESI tags that came from user input.

From the original on sudhanshur705.medium.com

The first attempt was blocked by the WAF. More testing showed the WAF looked for patterns shaped like <esi:placeholderhere> and blocked them whenever they contained a valid ESI tag such as include. Sending just <esi:> returned a 500 Internal Server Error. A 500 is the server's way of saying "something went wrong on my side". That error was actually good news: it showed the caching server was genuinely trying to process the ESI tag and failing. The researcher then tried characters such as %00 and %0A to slip past the filter, and none worked. %00 and %0A are URL-encoded control characters (a null byte and a newline); testers often try them because different pieces of software may treat them inconsistently.

At that point the researcher was using a trial of Burp Suite Pro, a popular tool for intercepting and modifying web traffic, with an extension called Active Scan++. The scanner produced this output for the parameter:

Text
https://globe.redacted.com/?showFooter=um6k%3c!--esi--%3e8omf%3c!--esx--%3eekdiNote: This issue was generated by the Burp extension: Active Scan++.Issue detailThe application appears to support Edge Side Includes:  The following probe was sent: um6k<!--esi-->8omf<!--esx-->ekdi In the response, the ESI comment has been stripped: um6k8omf<!--esx-->ekdi  Refer to https://gosecure.net/2018/04/03/beyond-xss-edge-side-include-injection/ for further information

Line by line, in plain words:

  • The URL shows a parameter called showFooter on the host globe.redacted.com, carrying a value that is URL-encoded. %3c is < and %3e is >.
  • The scanner sent the probe um6k<!--esi-->8omf<!--esx-->ekdi. The <!--esi--> part is an HTML comment that ESI-aware caches treat as a marker, and <!--esx--> is the matching closing marker.
  • In the response, the ESI comment had been stripped: the site returned um6k8omf<!--esx-->ekdi. The cache removed the <!--esi--> marker, which proves it is processing ESI.
  • The note points to GoSecure's article for background.

So ESI injection was confirmed through the comment tag, but it was not yet useful for anything. With no further ideas, the researcher saved the endpoint in notes and moved on.

The promotion and the collaboration

A couple of months later the program announced a promotion: it would pay 2x (double) for all high and critical submissions. Severity ratings like high and critical are how programs rank how serious a bug is. The doubled reward made the saved endpoint worth another attempt.

The researcher judged the WAF bypass to be beyond their own skill set, so they used the program's collaborator feature, which lets you invite another researcher onto a report, and contacted nytr0gen, a member of the WreckTheLine capture-the-flag team. Capture the flag (CTF) is a competition where teams solve security puzzles; the authors note that CTF players tend to have strong, practical skills.

Step 1: a working ESI payload for XSS

Within roughly 30 minutes nytr0gen produced a working ESI payload that pops an XSS alert box:

From the original on sudhanshur705.medium.com

The payload uses variables inside the ESI comment tag, which the first researcher did not know was possible. The documentation that explains it is Oracle's page on ESI language tags:

https://docs.oracle.com/cd/A97335_02/caching.102/a90372/esi.htm#633138 From the original on sudhanshur705.medium.com

https://docs.oracle.com/cd/A97335_02/caching.102/a90372/esi.htm#633138

When the caching server processes the payload, only this is left in the page source:

From the original on sudhanshur705.medium.com

$(QUERY_STRING{countryCode}) returned the value of the countryCode parameter. In other words, the cache read the visitor's request, took the value of that parameter, and pasted it into the page. Because the session cookies were httponly, ordinary XSS could not read them, but the ESI variables could reach them. A full account takeover proof of concept (a PoC: a demonstration that proves the bug is real and shows its impact) was included in the report. The issue was triaged (accepted and rated by the program) and rewarded with a high severity rating, doubled by the 2x multiplier:

From the original on sudhanshur705.medium.com

Step 2: a second subdomain that mangles letter case

nytr0gen found another subdomain where XSS worked through ESI tags and the caching server rendered them. That was a strong signal: if it happens on one subdomain, it may happen on more. This application performed an odd uppercase/lowercase transformation of input, so variables such as HTTP_COOKIE could not be used directly, because the name was transformed into something like http_COOKIE. ESI variable names are case-sensitive, so a mangled name no longer matches. nytr0gen went back to the documentation and found another ESI function that decodes URL-encoded strings:

https://www.akamai.com/site/zh/documents/technical-publication/akamai-esi-developers-guide-technical-publication.pdf From the original on sudhanshur705.medium.com

https://www.akamai.com/site/zh/documents/technical-publication/akamai-esi-developers-guide-technical-publication.pdf

The payload was URL-encoded twice to make sure Akamai would not block it:

From the original on sudhanshur705.medium.com

URL encoding replaces characters with % codes so they can travel safely in a URL. Encoding twice means the WAF sees an encoded version of an already encoded string, which often slips past filters that only decode once.

Step 3: ESI on a subdomain with no ESI in the source

The researcher had already found an XSS on another subdomain where there were no signs of ESI tags in the page source, but decided to try anyway with this payload:

Text
aaa<!--esi-->bbb<!--esx-->ccc

This is a minimal test. aaa, bbb and ccc are just markers so you can see what survives. If the response comes back as aaabbbccc (the ESI comment removed), the cache is processing ESI. The server rendered it, confirming ESI injection, and the same payload was used for account takeover:

From the original on sudhanshur705.medium.com

The account takeover proof of concept placed the JavaScript after the hash, shown below the main payload for readability:

From the original on sudhanshur705.medium.com

A hash in a URL is the part after #. Browsers do not send it to the server; it is used by the page itself. Putting the script after the hash keeps the URL tidy while the PoC still shows the code clearly. Because HTTP_COOKIE and QUERY_STRING{x} have already been explained, the PoC is easy to follow. It turned out nytr0gen had submitted this XSS bug 10 months earlier; it was reported again because the ESI version had much more impact than a normal XSS:

From the original on sudhanshur705.medium.com

Another high severity bug.

Step 4: a JSON response and the add_header trick

A few days later nytr0gen found another vulnerable endpoint:

From the original on sudhanshur705.medium.com

The response Content-Type for this endpoint was application/json. Content-Type is the label a server puts on a response to tell the browser what kind of data it is. application/json means "this is structured data, not a web page". The ESI tags were still rendered by the caching server. The problem: browsers do not run scripts in a response labelled application/json, so stealing the cookie in the page body looked impossible.

The answer is the $add_header() method, which can overwrite any response header:

From the original on sudhanshur705.medium.com
https://www.akamai.com/site/zh/documents/technical-publication/akamai-esi-developers-guide-technical-publication.pdf

The payload below changes the response content-type to text/html:

From the original on sudhanshur705.medium.com

text/html is the label for a normal web page, and browsers do run scripts in those. The final payload executes JavaScript by first using HTTP_COOKIE, then add_header, then the url_decode function:

From the original on sudhanshur705.medium.com

In plain words: HTTP_COOKIE fetches the visitor's cookies and puts them into the response, add_header relabels the response as text/html so the browser will treat it as a page, and url_decode delivers the XSS payload, URL-encoded twice to avoid the WAF. The result is a page that runs the attacker's script and can read the cookies. The bug was rewarded:

From the original on sudhanshur705.medium.com

Step 5: a proxy endpoint and a third-party XSS

The next endpoint looked like a proxy that takes a URL parameter and fetches the response of that URL. A proxy here means a feature on the site that goes and retrieves another page on your behalf. Features like this are interesting because they can be abused to make the server fetch things it should not, which is called SSRF (Server-Side Request Forgery).

From the original on sudhanshur705.medium.com

It only whitelisted a few domains, some on redacted.com and some on third-party sites. A whitelist is a list of things that are explicitly allowed. Because only whitelisted hosts could be requested, the pair looked for open redirects on those hosts. An open redirect is a link on a site that will send the visitor to any address supplied in the URL, which is useful to an attacker because the first hop looks trustworthy.

They found one on redacted.com, but it only worked for logged-in users. Visiting this URL:

loaded another URL inside an iframe which then redirected to the supplied URL. An iframe is a page inside a page. XSS was attempted but did not work because the redirect happened via the Location header. The Location header is the server's instruction to the browser: "go to this other address". Because the browser simply follows it, there is no page content in which to run a script.

From the original on sudhanshur705.medium.com

They moved on to the third-party sites in the whitelist and found no useful open redirect, although they did find some XSS on those sites. SSRF looked close, but arbitrary requests were not possible.

While playing with the endpoint, the researcher put the XSS-vulnerable third-party endpoint into the URL parameter, and the XSS popup appeared in the context of the redacted.com domain:

From the original on sudhanshur705.medium.com

"In the context of redacted.com" means the script ran as if it belonged to redacted.com, so it could act with that site's permissions. Since an ESI injection had already been reported on this host, an ESI payload was tried and it worked. So an XSS on a different third-party domain gave ESI injection on the target domain. SSRF was not achieved after a couple of days of looking for an open redirect, but the issue was escalated through ESI injection and reported.

Step 6: an open redirect built from add_header

Using the add_header function, the pair tried to create their own open redirect with a payload like this:

From the original on sudhanshur705.medium.com

On any of the previously vulnerable ESI endpoints this gives a simple open redirect: the cache sets the Location header to an address of the attacker's choosing. It worked normally, but when the resulting open redirect URL was used on the proxy endpoint it did not work, possibly because of the Akamai WAF.

The bug was then marked as a duplicate by the HackerOne triager:

From the original on sudhanshur705.medium.com

A triager is the person at the bug bounty platform who reads reports, checks them, and decides whether they are valid, duplicates, or out of scope. A duplicate means someone else already reported the same issue. After back and forth with the triager, they learned that the original reporter had escalated the issue to SSRF, without the ESI trick. The report was dropped, the promotion ended, and the pair stopped, expecting a low chance of another promotion.

Step 7: the second promotion and the moved JSON endpoint

Four to five months later the same 2x multiplier promotion launched again. Some callback parameters were tested because they usually reflect input. A callback parameter is one a page uses to tell another script "call me back with the result", and it often echoes what you give it. Some allowed <> characters, but the caching server configuration on those hosts was different, so the ESI tags did not work.

Some old reports had already been fixed. nytr0gen found that the same JSON API endpoint was now reachable over a different path. An API is the set of addresses and rules a program exposes so other software can talk to it; an endpoint is one specific address in that set. To fix the original JSON API ESI bug the endpoint had been removed, but the same endpoint existed on another path, so the bug was still there. The same PoC reproduced it. It was submitted as a different endpoint even though it was the same API, triaged by the program, and rewarded as high again. This time the team asked a question about mitigation:

From the original on sudhanshur705.medium.com

Mitigation means the measures taken to reduce or remove a risk.

Step 8: the best bug, a JSON endpoint that ignored ESI

The last endpoint found had Content-Type: application/json:

From the original on sudhanshur705.medium.com

The locale parameter value was reflected in the source, but the ESI tags were not rendered by the caching server, even though an ESI injection had been found on this host before. A locale parameter normally tells a site which language or regional format to use. The URL was sent to nytr0gen, who agreed it should have worked. After some time he reported that he had got it working but that it was not useful:

From the original on sudhanshur705.medium.com

The change to spot in the request is the URL-encoded . in the URL, %2e:

From the original on sudhanshur705.medium.com

The backend server decoded the %2e in the URL and returned the same response. The caching server did not ignore the %2e, so it no longer treated the request as a static file and allowed the ESI tags to work. A static file is something like an image or a script that never changes; caches often skip ESI processing for those. It worked, but was not exploitable: if the URL is sent to a victim, the browser auto-decodes the %2e, so the request goes to the original endpoint rather than the one needed, and the ESI tags are not rendered. More time was spent on this without finding a way to make it work in the browser.

Step 9: client-side path traversal and the iframe idea

A month later, while testing another program, the researcher had a potential client-side path traversal bug. Path traversal means using ../ style tricks to make a program load a file it did not intend to load; "client-side" means it happens in the browser rather than on the server. The key variable in the JavaScript below was controllable:

From the original on sudhanshur705.medium.com

There was also a JSONP callback endpoint on the same host. JSONP is an older technique for loading data from another site as if it were a script. The aim was to load the JSONP endpoint instead of the /api.js file, which would pop an alert:

From the original on sudhanshur705.medium.com

The key variable value came from a query parameter, so the # symbol could not be used: putting # in the parameter value means the browser consumes it and it is not passed in the key value. URL-encoding it as %23 means the browser does not auto-decode it while fetching the JS file, so the researcher was stuck. The ? could not be used to ignore the /api.js part because of this code:

From the original on sudhanshur705.medium.com

Inside the getAllUrlParams method, the first line is url.split('?')[1], so a ? in the URL parameter value is dropped:

From the original on sudhanshur705.medium.com

split('?') cuts the URL into pieces at the ?, and [1] takes the second piece. If your value itself contains a ?, everything after it is treated as a new piece and lost. The ? is completely ignored because of the split method. Loading the URL with the URL-encoded # inside an iframe was tried, but did not work.

The same idea was then applied to the redacted target, going back to the earlier endpoint:

From the original on sudhanshur705.medium.com

Loading this URL in an iframe was tried:

From the original on sudhanshur705.medium.com

It worked. Loading the same code in Chrome did not work, because %2e was automatically decoded by Chrome:

From the original on sudhanshur705.medium.com

So it worked in Firefox but not Chrome, and later the researcher confirmed it also worked in Safari the same way as Firefox. nytr0gen was contacted with the good news:

From the original on sudhanshur705.medium.com

Step 10: cookies in an iframe and a WAF bypass for text/html

When HTTP_COOKIE was used, not all cookies were present, notably the session cookie. nytr0gen explained this was because the page was loaded inside an iframe and the parent was of a different origin. Origin here means the combination of scheme, host and port that a browser uses to decide what a page is allowed to touch. When a page is framed by a different origin, the browser restricts what it can see. Instead, another XSS (created using one of the earlier ESI injection bugs) was used to iframe the .json URL, and this time the cookie appeared.

Using the add_header method to change the application/json content type to text/html was blocked by the WAF. After shortening the payload, the researcher found the WAF was now blocking the text/html keyword, possibly a rule added when the previous report was fixed, so a bypass was needed.

Fuzzing means sending many small variations of an input and watching how the system reacts. Fuzzing showed that %09, the tab character (\t), was converted to t by the server. The payload below changed the Content-Type, and XSS was then used to steal the session cookie:

From the original on sudhanshur705.medium.com

This one was not rewarded with the 2x multiplier because the asset was not part of the promotion, which the pair agreed with, since it was still paid as a high severity even though it only worked in Firefox and not Chrome. An asset is one specific system or domain that a program lists as in scope. Finally, the program manager asked them to stop testing for ESI injection bugs while the WAF was tuned:

From the original on sudhanshur705.medium.com

Why it worked

User input reached the caching server in a place where ESI tags are parsed and rendered. The application reflected characters such as <>'" and the edge assembled the response, so an attacker who could get an ESI tag into the response controlled what the edge inserted. The WAF blocked valid ESI tags such as include, but the comment form and the variable syntax inside it still worked. and neither were the encoding tricks (url_decode, double URL-encoding, %2e, %09). The httponly flag and the .redacted.com cookie scope did not help, because the ESI variables read the request cookies at the edge and place them in the response body, and add_header can turn a JSON response into text/html so the injected script executes.

What the impact was

On the affected endpoints the attacker could execute JavaScript in the target origin and read the session cookies, which were httponly and scoped to .redacted.com, and account takeover PoCs were provided. The JSON endpoint variant required add_header to change the content type, and the final variant only worked when the URL was loaded in Firefox or Safari, not Chrome, because Chrome auto-decodes %2e. The proxy endpoint allowed an XSS on a whitelisted third-party domain to run in the redacted.com context and to reach ESI injection there. SSRF through the proxy was not achieved by this pair; the duplicate report showed another researcher had escalated it to SSRF without the ESI trick.

What was fixed

The report does not describe the fixes applied by the program. The original JSON API endpoint was removed and the same API reappeared on another path; the researchers suspected a WAF rule blocking text/html came from the earlier fix, and bypassed it with %09. The program manager asked them to stop testing ESI injection while the WAF was tuned.

Things to try yourself

  1. Send aaa<!--esi-->bbb<!--esx-->ccc to any reflected parameter. A positive result is the comment being stripped in the response, which confirms ESI processing.
  2. Send <esi:> alone. A 500 error suggests the caching server is trying to render ESI tags.
  3. Try $(QUERY_STRING{param}) and $(HTTP_COOKIE) inside an ESI comment. A positive result is the parameter value or the cookies appearing in the response body.
  4. On JSON endpoints, try $add_header('content-type','text/html') combined with url_decode. A positive result is the response content type changing and the injected script executing.
  5. Where a WAF blocks text/html, try %09 in place of the space or characters in the keyword, and try double URL-encoding. A positive result is the header change going through.
  6. Where a URL is treated as a static file, try %2e in the path. A positive result is the backend returning the same response while the caching server renders ESI tags; check whether the browser decodes it before sending.
  7. On proxy or fetch features with a host whitelist, look for XSS or open redirects on the whitelisted hosts and pass them in the URL parameter. A positive result is script executing in the target origin, or ESI tags rendering there.
  8. Try $add_header('Location','https://evil.com') on an ESI-vulnerable endpoint to build an open redirect, and check whether it survives when passed through a proxy feature.

Glossary

  • Account takeover: gaining control of another person's account, usually by stealing their session cookie.
  • API: the set of addresses and rules a program exposes so other software can talk to it.
  • Asset: one specific system or domain that a bug bounty program lists as in scope.
  • Backend: the real server behind a cache that does the actual work.
  • Bug bounty program: a scheme where a company invites outside testers to find security problems and pays for reports.
  • Cache / caching server: a fast intermediate machine that stores copies of pages and serves them to visitors.
  • Callback parameter: a parameter a page uses to tell another script where to send a result; it often echoes input.
  • Capture the flag (CTF): a competition where teams solve security puzzles.
  • Collaborator: a bug bounty feature that lets you invite another researcher onto a report.
  • Content-Type: the label a server puts on a response to say what kind of data it is.
  • Cookie: a small piece of data a website asks your browser to store and send back on every request.
  • Cross-site scripting (XSS): getting your own JavaScript to run inside someone else's website, with that site's permissions.
  • Duplicate: a report for an issue someone else already reported.
  • Edge Side Include (ESI): a markup language that tells a caching server which fragments to fetch and where to place them.
  • Endpoint: a specific URL that a site responds to.
  • Fuzzing: sending many small variations of an input and watching how the system reacts.
  • Hash: the part of a URL after #; browsers do not send it to the server.
  • Httponly: a cookie setting that forbids JavaScript from reading the cookie.
  • Iframe: a page embedded inside another page.
  • JSONP: an older technique for loading data from another site as if it were a script.
  • Location header: the server's instruction to the browser to go to another address.
  • Mitigation: measures taken to reduce or remove a risk.
  • Open redirect: a link on a site that sends the visitor to any address supplied in the URL.
  • Origin: the combination of scheme, host and port that a browser uses to decide what a page may touch.
  • Payload: the piece of text an attacker sends to trigger a bug.
  • Proof of concept (PoC): a demonstration that proves a bug is real and shows its impact.
  • Proxy: a feature that fetches another page on your behalf.
  • Reflection: a site copying your input into its response.
  • Session cookie: the cookie that proves you are logged in.
  • Severity: how serious a bug is rated to be, for example high or critical.
  • SSRF (Server-Side Request Forgery): making a server fetch a resource it should not, by supplying the address.
  • Static file: a file such as an image or script that never changes; caches often skip ESI processing for those.
  • Triager: the person at the bug bounty platform who checks reports and decides whether they are valid.
  • URL encoding: replacing characters with % codes so they can travel safely in a URL.
  • WAF (Web Application Firewall): a filter in front of a website that blocks requests that look malicious.
  • Whitelist: a list of things that are explicitly allowed.

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.