Amazon leaking CSRF token using service worker
A stored XSS on a subdomain allowed uploading an SVG and JavaScript files that registered a service worker, which then proxied requests to the main domain and stole CSRF tokens. The attacker could use those tokens to change the user's phone number, potentially leading to account takeover.
Published on ahussam.me
Hello all, I have some free time today, so I will tell you about my finding at Amazon that could lead to a complete account takeover.
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
Amazon runs a public crossdomain.xml that is very permissive. The researcher had previously found a stored XSS through file upload in a third-party service called Answerhub, on a private bug bounty programme, and was paid $1250 for a PoC that affected an in-scope domain. He then noticed that Amazon uses the same third-party service, AnswerHub, and reasoned that if he could upload an SWF file to an Amazon sub-domain, the permissive crossdomain.xml would let that Flash content read data from the main domain. The obstacle was that the service does not allow Flash content to be uploaded.
The target chosen was gamedev.amazon.com. On that host the researcher could upload an XML file (SVG) and get stored XSS, but every trick he knew for uploading an SWF file failed.
Setup
- Target:
gamedev.amazon.com, an AnswerHub-based forum. - Precondition: the ability to upload files to the forum's attachment storage.
- Tooling: Flex SDK to compile ActionScript into an SWF, plus a PHP script the researcher wrote to generate an SWF file from AS code (he said he would publish it on GitHub).
- A website of his own,
ahussam.me, to host the SWF file. - Service Worker API, as implemented in Google Chrome.
Finding it
The researcher searched for large companies using AnswerHub with a Google dork:
inurl:/questions/ask.html inurl:https://
Amazon came up, and the permissive crossdomain.xml came to mind. Here is Amazon's crossdomain.xml as he showed it:

He could get stored XSS on gamedev.amazon.com by uploading an SVG, but that was not the goal. The SWF upload was blocked. The idea that followed was to combine what he had: upload an SVG and a JS file that together register a Service Worker on the domain.
His description of the Service Worker API, quoted from Google Chrome's documentation:
A service worker is a script that your browser runs in the background, separate from a web page, opening the door to features that don't need a web page or user interaction. Today, they already include features like push notifications and background sync. In the future, service workers will support periodic sync or geofencing. The core feature discussed in this tutorial is the ability to intercept and handle network requests, including programmatically managing a cache of responses.
The reason this is such an exciting API is that it allows you to support offline experiences, giving developers complete control over the experience.
The attack theory, in three files:
- ActionScript code that sends an HTTP request to
amazon.com, receives the page content and finds the CSRF token on the page. The file was hosted onahussam.measmyexp.as, and Flex SDK was used to generate the SWF version. - A JS file registered as the Service Worker for the site, which proxies the traffic and serves an SWF file response on a chosen path. This installs the SWF (
myexp.swf) on that path, and the SWF grabs the CSRF tokens from the main website, which works because ofcrossdomain.xml. - An HTML page, delivered as an SVG image containing XML and JS, that registers the Service Worker.
Exploitation
Step 1: upload the Service Worker script
The JS file was uploaded first so that the new name could be learned, since the filename changes after upload. It was renamed to sw.txt because there is a client-side check on the extension, and the old trick of changing the content-type to something different was used. After upload the name became 4837-sw.txt. The HTTP request:

Step 2: upload the registration page
The SVG image with XML and JS registers the Service Worker. As before, the file extension and the content-type were changed. The HTTP request:

The resulting PoC page was:
https://gamedev.amazon.com/forums/storage/attachments/4937-svg.txt
Step 3: debug the exploit
The exploit did not work the first time because he was using HTTP, and Service Worker only works over HTTPS. His note for anyone without an HTTPS website for the SWF file is to use a data URI and base64 in the fetch function. After some debugging it worked:

Root cause
Two weaknesses combine. The upload feature on the AnswerHub-based forum enforces the file extension only on the client side, so renaming the file and changing the content-type gets arbitrary content stored under an attacker-chosen name on the gamedev.amazon.com origin. The uploaded SVG and JS files are served from the Amazon sub-domain, and the JS registers a Service Worker there. The Service Worker then intercepts requests on that origin and serves the SWF file, and Amazon's permissive crossdomain.xml lets the SWF read responses from amazon.com, including pages containing CSRF tokens. The report does not show the server-side validation code, so the exact server-side check that was bypassed is not stated.
Impact
With the CSRF tokens stolen, changing the user's phone number was possible, which the researcher says could lead to a complete account takeover. He also lists CSRF, information leakage, OAuth approval and address disclosure as other things that could be done. The Service Worker part requires HTTPS.
Fix
The report does not describe the fix. It only says that after months of waiting without a reply, the researcher found that the bug had been fixed. The gamedev team had deleted his PoC and blocked him, and the Amazon team could not reproduce the issue from the long report until he supplied a PoC video, which he had to re-upload before they could reproduce it.
Variants to test
- Run the same dork against other AnswerHub installations and look for permissive
crossdomain.xmlfiles on the parent domain. A positive result is an upload that is stored and served from the target origin with attacker-controlled content. - Try the extension and
content-typemismatch on any upload feature that validates only in the browser. A positive result is a stored file whose name and MIME type differ from what the client check would allow. - Where SVG upload is possible, test whether the served SVG executes script on the target origin. A positive result is script running with the target's origin.
- On any origin where you can run script, attempt to register a Service Worker that proxies requests. A positive result is the worker installing and intercepting fetches on that origin.
- Check whether a Flash file served through the worker can read cross-origin responses because of
crossdomain.xml. A positive result is the SWF reading page content from the main domain. - If you have no HTTPS host for the SWF, try a data URI with base64 in the fetch function, as the researcher suggests.
What happened, in plain words
A security researcher found a way to steal a special code that Amazon uses to protect forms, which could lead to account takeover. He did this by uploading two files to a forum that Amazon runs for game developers, and then getting a victim to visit a page. The files made the victim's browser run a background program (a Service Worker) that could fetch pages from Amazon and read the secret code from them. With that code, changing the user's phone number was possible, which could lead to a complete account takeover.
The story starts with a previous finding on a private bug bounty programme. A bug bounty programme is a scheme where companies pay people for reporting security problems. The researcher had found a stored XSS (a way to run your own JavaScript in other users' browsers) in a third-party service called Answerhub. That service is used by many companies to run question-and-answer forums. He was paid $1250 for a proof of concept (PoC) that affected a domain that was in scope (allowed to be tested).
He then noticed that Amazon also uses Answerhub. Amazon has a file called crossdomain.xml that is very permissive. That file tells Flash (a browser plugin) which other domains it is allowed to talk to. If it is permissive, Flash content from one domain can read data from another. So the researcher thought: if I can upload a Flash file (SWF) to an Amazon sub-domain, I can use it to read data from the main Amazon domain. The problem was that the forum did not allow uploading SWF files.
He chose gamedev.amazon.com as his target. On that site he could upload an SVG file (an image format that can contain JavaScript) and get stored XSS. Stored XSS means the malicious script is saved on the server and runs whenever someone views the page. But that was not his goal. He tried every trick he knew to upload an SWF file, but none worked.
Then he had an idea: instead of uploading an SWF directly, what if he uploaded an SVG and a JavaScript file that together register a Service Worker on the domain? A Service Worker is a script that the browser runs in the background, separate from any web page. It can intercept network requests and serve responses from a cache. In effect, it can act as a proxy inside the browser. If he could register a Service Worker on gamedev.amazon.com, he could make it serve an SWF file from a path he controlled. Then the SWF, running on that Amazon sub-domain, could use the permissive crossdomain.xml to read pages from amazon.com and extract the CSRF token.
A CSRF token is a secret value that a website includes in forms to prevent Cross-Site Request Forgery (CSRF). CSRF is an attack where a malicious site makes a victim's browser send a request to a site where the victim is logged in, without the victim's knowledge. The token proves that the request came from the legitimate site. If an attacker can steal the token, they can forge requests that the site will accept.
So the plan was:
- Write an ActionScript (Flash) file that, when run, sends a request to
amazon.com, reads the page, and extracts the CSRF token. Compile it to SWF. - Write a JavaScript file that will be registered as a Service Worker. It will intercept requests and serve the SWF file on a chosen path.
- Write an HTML page (disguised as an SVG) that registers the Service Worker.
He uploaded the JavaScript file and the SVG file to the forum's attachment storage. He had to bypass a client-side check on the file extension by renaming the files and changing the content-type header. The files were stored with new names. The uploaded SVG page, when loaded, runs JavaScript that registers the Service Worker. The Service Worker then served the SWF file, which grabbed the CSRF tokens from the main website. With that token, the attacker could change the victim's phone number, and potentially take over the account.
The exploit did not work at first because he was using HTTP, and Service Workers only work over HTTPS. He fixed that and got it working. He reported it to Amazon, but they could not reproduce it from his long report. The gamedev team deleted his PoC and blocked him. He made a video, re-uploaded it, and then they could reproduce it. After months, the bug was fixed.
Now let's go through the technical details step by step, explaining everything from scratch.
Technical details
Finding targets with a Google dork
The researcher wanted to find large companies that use AnswerHub. He used a Google dork, which is a search query that uses advanced operators to find specific pages. The dork was:
inurl:/questions/ask.html inurl:https://
This searches for URLs that contain both /questions/ask.html (a typical AnswerHub page) and https://. The results included Amazon. That made him think of crossdomain.xml.
Here is Amazon's crossdomain.xml as he showed it:

A crossdomain.xml file is a policy file that Adobe Flash Player requests from a domain to decide whether Flash content from another domain can access its data. If it allows all domains (e.g. <allow-access-from domain="*"/>), then any Flash file can read data from that domain. That is very permissive and dangerous.
The obstacle: no SWF uploads
His target was gamedev.amazon.com. He could upload an XML file (SVG) and get stored XSS, but he could not upload an SWF file. The forum blocked it. So he needed another way to get an SWF file served from that domain.
The idea: Service Worker as a proxy
He thought: what if I upload an SVG and a JavaScript file that together register a Service Worker on this domain? A Service Worker is a script that the browser runs in the background, separate from a web page. It can intercept network requests and respond with cached or generated content. It is like a man-in-the-middle inside the browser, but under the control of the website's JavaScript. Service Workers only work over HTTPS for security reasons.
He quoted Google Chrome's documentation:
A service worker is a script that your browser runs in the background, separate from a web page, opening the door to features that don't need a web page or user interaction. Today, they already include features like push notifications and background sync. In the future, service workers will support periodic sync or geofencing. The core feature discussed in this tutorial is the ability to intercept and handle network requests, including programmatically managing a cache of responses.
The reason this is such an exciting API is that it allows you to support offline experiences, giving developers complete control over the experience.
An API (Application Programming Interface) is a set of rules that lets one piece of software talk to another. Here, the Service Worker API lets a web page register a background script and control network requests.
His attack theory involved three files:
- An ActionScript file that sends an HTTP request to
amazon.com, receives the page content, and finds the CSRF token. ActionScript is the programming language used by Flash. He wrote the file asmyexp.asand hosted it on his websiteahussam.me. He used Flex SDK (a tool for compiling ActionScript) to generate the SWF version. He also wrote a PHP script to generate an SWF file from ActionScript code, which he said he would publish on GitHub. - A JavaScript file that will be registered as the Service Worker. It will proxy traffic and serve an SWF file response on a chosen path. This installs the SWF (
myexp.swf) on that path, and the SWF grabs the CSRF tokens from the main website. This works because of the permissivecrossdomain.xml. - An HTML page, delivered as an SVG image containing XML and JavaScript, that registers the Service Worker.
Step 1: Upload the Service Worker script
He first uploaded the JavaScript file to see what new name it would get, because the filename changes after upload. He renamed it to sw.txt because there is a client-side check on the extension. A client-side check is validation done in the browser (JavaScript), which can be bypassed by intercepting the request and changing it. He used the old trick of changing the content-type header to something different. The content-type header tells the server what type of file is being sent. By changing it, he could bypass the check. After uploading, the file was renamed to 4837-sw.txt. Here is the HTTP request:

This image shows the HTTP request used to upload the file.
Step 2: Upload the registration page
The third file is an SVG image that contains XML and JavaScript. When the browser loads it, the JavaScript runs. That JavaScript registers the Service Worker. As before, he changed the file extension and the content-type to bypass the check. Here is the HTTP request:

This image shows the upload request for the SVG file.
The resulting PoC page was:
https://gamedev.amazon.com/forums/storage/attachments/4937-svg.txt
This is the URL where the SVG file was stored. When a victim visits this URL, the SVG runs its JavaScript, which registers the Service Worker.
Step 3: Debug the exploit
The exploit did not work the first time because he was using HTTP, and Service Workers only work over HTTPS. HTTPS is the secure version of HTTP, encrypted with TLS. Service Workers require a secure context, so they only run on HTTPS pages (or localhost). He notes that if you don't have an HTTPS website for your SWF file, you can use a data URI and base64 in the fetch function. A data URI is a way to embed data directly in a URL, like data:application/x-shockwave-flash;base64,.... Base64 is an encoding that turns binary data into text. So you can embed the SWF file directly in the JavaScript without needing an external HTTPS host. After some debugging, it worked:

This image relates to the working exploit after debugging.
Reporting and response
He reported it to Amazon. They could not reproduce the PoC because the report was long. So he made a PoC video. They could not watch it at first, but he re-uploaded it, and then they could reproduce the vulnerability. After months of waiting, they did not reply, but he found that the bug had been fixed.
Impact
With the CSRF tokens stolen, changing the user's phone number was possible, which could lead to a complete account takeover. Other things could be done, including CSRF, information leakage, OAuth approval, address disclosure, etc. OAuth is an open standard for access delegation, commonly used for login with Google, Facebook, etc.
The Service Worker part requires HTTPS.
Root cause
Two weaknesses combine. The upload feature on the AnswerHub-based forum enforces the file extension only on the client side, so renaming the file and changing the content-type gets arbitrary content stored under an attacker-chosen name on the gamedev.amazon.com origin. The uploaded SVG and JS files are served from the Amazon sub-domain, and the JS registers a Service Worker there. The Service Worker then intercepts requests on that origin and serves the SWF file, and Amazon's permissive crossdomain.xml lets the SWF read responses from amazon.com, including pages containing CSRF tokens. The report does not show the server-side validation code, so the exact server-side check that was bypassed is not stated.
Fix
The report does not describe the fix. It only says that after months of waiting without a reply, the researcher found that the bug had been fixed. The gamedev team had deleted his PoC and blocked him, and the Amazon team could not reproduce the issue from the long report until he supplied a PoC video, which he had to re-upload before they could reproduce it.
Variants to test
- Run the same dork against other AnswerHub installations and look for permissive
crossdomain.xmlfiles on the parent domain. A positive result is an upload that is stored and served from the target origin with attacker-controlled content. - Try the extension and
content-typemismatch on any upload feature that validates only in the browser. A positive result is a stored file whose name and MIME type differ from what the client check would allow. - Where SVG upload is possible, test whether the served SVG executes script on the target origin. A positive result is script running with the target's origin.
- On any origin where you can run script, attempt to register a Service Worker that proxies requests. A positive result is the worker installing and intercepting fetches on that origin.
- Check whether a Flash file served through the worker can read cross-origin responses because of
crossdomain.xml. A positive result is the SWF reading page content from the main domain. - If you have no HTTPS host for the SWF, try a data URI with base64 in the fetch function, as the researcher suggests.
Glossary
- API: Application Programming Interface; a set of rules that lets software components communicate.
- ActionScript: The programming language used by Adobe Flash.
- AnswerHub: A third-party service for building question-and-answer forums.
- Base64: An encoding that represents binary data as text.
- Bug bounty programme: A scheme where companies reward people for finding and reporting security vulnerabilities.
- Client-side check: Validation performed in the browser (e.g. with JavaScript), which can be bypassed by an attacker.
- Content-type: An HTTP header that indicates the media type of a resource.
- Crossdomain.xml: A policy file used by Flash to allow or deny cross-domain data access.
- CSRF (Cross-Site Request Forgery): An attack that tricks a victim's browser into sending an unwanted request to a site where they are authenticated.
- CSRF token: A secret, unpredictable value included in forms to prevent CSRF.
- Data URI: A URI scheme that embeds data directly in the URL.
- Flex SDK: A software development kit for building Flash applications.
- Google dork: A search query using advanced operators to find specific information.
- HTTPS: HTTP over TLS, providing encrypted communication.
- OAuth: An open standard for access delegation, commonly used for login.
- PoC (Proof of Concept): A demonstration that a vulnerability exists.
- Service Worker: A script that runs in the background, separate from a web page, and can intercept network requests.
- Stored XSS: A type of XSS where the malicious script is stored on the server and served to other users.
- SVG: Scalable Vector Graphics, an XML-based image format that can contain JavaScript.
- SWF: The file format for Flash content.
- XSS (Cross-Site Scripting): A vulnerability that allows an attacker to inject client-side scripts into web pages viewed by other users.