Reporting - Amazon 1 click device XSS
The device names listed under Amazon's 1-Click Status were not sanitised, allowing stored XSS when a user named their device with a script payload. An attacker could execute arbitrary JavaScript in the context of anyone viewing the device list, such as support representatives.
Published on github.com
Update Amazon1clickdeviceXSS.md
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's account settings include a 1-Click purchasing section. Within that section, the account shows a list of devices that are associated with 1-Click ordering, along with a 1-Click Status for each. The device names in that list come from the names the user has given their own devices, such as a phone or tablet.
The bug described here is a stored cross-site scripting issue in that device listing. The researcher's broader point is that any data controlled by a user should be sanitised and output encoded if it will be returned to the client, even when the nature of the data makes developers assume certain input cannot exist there.
Setup
The precondition is simple: the user controls the name of a personal device. The researcher names personal devices such as an iPhone and an iPad with an XSS payload. The payload used in the proof of concept is the following:
<script>alert(1)</script>
No special tools, accounts or roles beyond a normal Amazon account and a device whose name can be set are described. The same technique had previously triggered XSS in other software, including notification software and routers, because those products also have a page that lists devices and is viewed by other users.
Finding it
The device name, which is user-controlled input, was rendered back into the 1-Click device listing without being sanitised. The reasoning is that developers often assume a device name cannot contain certain input, so the value is trusted when it is displayed. The test is to give a device a name containing a script payload and then load the page that lists devices.
Exploitation
Step 1: Name the device with a payload
The device is given a name containing the payload shown above. The researcher did this on personal devices, including an iPhone and an iPad.
Step 2: Open the 1-Click device listing
The affected page is reached through the account settings for 1-Click purchasing:
Your Account > Manage Default Address and 1-Click Settings
The device names listed under 1-Click Status are not sanitised. When the page loads, the payload in the device name executes.
Step 3: Confirm execution
The proof of concept states that the phone name is <script>alert(1)</script> and that once this is loaded into the 1-Click Status an alert window appears with the number 1.
Step 4: Report it
The bug was reported by email to Amazon Security at [redacted] The report contained the following details:
- Report date: July 19th 2017
- Issue fix confirmed: November 13th 2017
- Reported to: Amazon Security [[redacted]]
- Bug Type: XSS (Stored)
- Description: under the account settings for 1-Click purchasing, found at Your Account > Manage Default Address and 1-Click Settings, the device names listed under 1-Click Status are not sanitised
- POC: the phone name is
<script>alert(1)</script>and once this is loaded into the 1-Click Status an alert window appears with the number 1
Step 5: Report mobile compatibility
Later the researcher found that the issue could also be triggered from a mobile phone. This update was reported to Amazon on August 19th 2017.
Root cause
The device name is user-controlled data that is stored and later rendered into the 1-Click Status listing. The listing did not sanitise or output encode that value, so the markup in the name was interpreted by the browser as HTML and the script ran. The researcher's general point is that developers sometimes assume certain input cannot exist in data like a device name, yet it is still returned to the client.
Impact
The 1-Click device list is only something the user would view, and the attack vector is through the name of their own device. As the researcher specified to Amazon in a later email, the only valid attack vector in this case is to attack representatives who assist with the account and have to view the 1-Click devices for troubleshooting. The researcher notes that this is not always the case in other bugs they have discovered, where other users would be affected by the payload.
Fix
The issue was fixed by adding output encoding to the device listing. In addition, the 1-Click device listing was moved to its own page, reached through:
Your Account -> 1-Click settings -> Manager 1-Click for your devices
Variants to test
- Give a device, host or client a name containing a script payload and load any page that lists devices. A positive result is the payload executing in the listing, as it did here.
- Repeat the test from a mobile device, since the researcher found the issue could also be triggered from a phone.
- Look for listings that are viewed by support staff or other users rather than only by the account owner, since those are the cases where the stored payload reaches someone other than the person who set it.
- Check other user-controlled fields that developers may assume cannot contain markup, and confirm whether they are output encoded when rendered back to the client.
What happened, in plain words
A security researcher found a bug in Amazon's website. The bug let a piece of code hidden inside a phone's name run inside a web page on Amazon's site. This kind of bug is called cross-site scripting, or XSS for short.
To understand it, imagine a guest book at a party. Guests write their names in it, and later the host reads the book out loud. If a guest writes not just a name but an instruction like "shout this out loud", and the host reads the instruction as if it were a name, the instruction gets followed. That is roughly what happened here: the phone's name was treated as ordinary text, but the website displayed it in a way that made the browser treat part of it as a command.
The researcher's wider point is simple: any information a user can type in should be cleaned up and safely displayed when it comes back to a browser, even when the developers think that kind of information could never contain anything dangerous. A device name feels harmless, so it is easy to trust it. That trust is exactly what the bug relied on.
Background ideas you need first
A few everyday ideas make the rest of this easy to follow.
- A browser is the program you use to visit websites, such as Chrome, Safari or Firefox. It reads web pages and shows them to you.
- A web page is a document made of text and instructions. Some of those instructions tell the browser how to display things (bold text, images, buttons). Others, called scripts, tell the browser to do something, like show a pop-up window.
- HTML is the language those instructions are written in. Anything inside angle brackets, like
<b>, is a tag: an instruction to the browser rather than text for you to read. - A script is a small program that runs inside your browser. A very common example is a pop-up alert box. Scripts are normally written by the website's owners, but if a website accidentally lets a visitor's text be treated as a script, that visitor's script runs too. That accident is what XSS means.
- Sanitising means cleaning up input: removing or neutralising anything that could be interpreted as an instruction rather than plain text.
- Output encoding is the related step of converting special characters into a safe form when displaying data, so that a
<meant as text stays text and is never treated as the start of a tag. - Stored XSS is XSS where the dangerous text is saved on the server first (for example, in a device name) and then shown to whoever later views the page. The payload waits on the server until the page is loaded.
- A payload is the piece of text an attacker uses to test or exploit a bug. Here it is a tiny script.
- 1-Click purchasing is an Amazon feature that lets you buy something with a single click, without re-entering payment and address details each time. Because it is tied to your account and your devices, Amazon keeps a list of the devices associated with it, with a status for each.
The setup
The only thing needed to try this is a normal Amazon account and a personal device whose name you can change, such as a phone or a tablet. The researcher set the names of personal devices, including an iPhone and an iPad, to a small script. The payload used in the proof of concept is:
<script>alert(1)</script>
Line by line, in plain words:
<script>is the opening tag that tells the browser "a program starts here".alert(1)is the program itself: it asks the browser to show a pop-up box containing the number 1. It does nothing harmful; it is just an easy way to prove that code ran.</script>is the closing tag that says the program ends here.
If a website displays this text as plain text, you see the characters on screen and nothing happens. If a website displays it as HTML, the browser sees a script tag and runs the pop-up. The whole test is about which of those two things happens.
This is not a one-off trick. The researcher says the same approach had already triggered XSS in other software, including notification software and routers, because those products also have a page that lists devices and is viewed by other people.
Finding the bug
The device name, which the user controls, was being placed back into the 1-Click device listing without being cleaned up. The reasoning is that developers often assume a device name cannot contain certain characters, so the value is trusted when it is shown. The test is straightforward: give a device a name containing a script, then open the page that lists devices and see whether the script runs.
Exploitation, step by step
Step 1: Name the device with a payload
The device is given a name containing the payload shown above. The researcher did this on personal devices, including an iPhone and an iPad.
Step 2: Open the 1-Click device listing
The affected page is reached through the account settings for 1-Click purchasing:
Your Account > Manage Default Address and 1-Click Settings
This is a path through the site's menus, not a web address: from your account area, open the default address and 1-Click settings, and the device list appears there. The device names listed under 1-Click Status are not sanitised. When the page loads, the payload in the device name runs.
Step 3: Confirm execution
The proof of concept states that the phone name is <script>alert(1)</script> and that once this is loaded into the 1-Click Status an alert window appears with the number 1. Seeing that pop-up is the proof: the browser treated the name as a program, not as text.
Step 4: Report it
The bug was reported by email to Amazon Security at [redacted] The report contained the following details:
- Report date: July 19th 2017
- Issue fix confirmed: November 13th 2017
- Reported to: Amazon Security [[redacted]]
- Bug Type: XSS (Stored)
- Description: under the account settings for 1-Click purchasing, found at Your Account > Manage Default Address and 1-Click Settings, the device names listed under 1-Click Status are not sanitised
- POC: the phone name is
<script>alert(1)</script>and once this is loaded into the 1-Click Status an alert window appears with the number 1
Reporting it by email to the company's security team is the normal route when a company publishes a security contact. The report is short on purpose: what the feature is, where it lives, what the input is, and what happens when the page loads.
Step 5: Report mobile compatibility
Later the researcher found that the issue could also be triggered from a mobile phone. This update was reported to Amazon on August 19th 2017.
Why it happened
The device name is data the user controls. It is saved, and later placed into the 1-Click Status listing. The listing did not sanitise or output encode that value, so the markup in the name was read by the browser as HTML and the script ran. The researcher's general point is that developers sometimes assume certain input cannot exist in data like a device name, yet it is still returned to the client.
Who could be affected
The 1-Click device list is only something the user would view, and the attack path is through the name of their own device. As the researcher explained to Amazon in a later email, the only realistic target in this case is a support representative who helps with the account and has to view the 1-Click devices for troubleshooting. The researcher notes that this is not always the case in other bugs they have found, where other users would be affected by the payload.
The fix
The issue was fixed by adding output encoding to the device listing. In addition, the 1-Click device listing was moved to its own page, reached through:
Your Account -> 1-Click settings -> Manager 1-Click for your devices
Again this is a menu path rather than a web address. Output encoding is the key part: with it, the angle brackets in a device name are shown as text instead of being treated as the start of a script.
Things worth trying yourself
- Give a device, host or client a name containing a script payload and load any page that lists devices. A positive result is the payload running in the listing, as it did here.
- Repeat the test from a mobile device, since the researcher found the issue could also be triggered from a phone.
- Look for listings that are viewed by support staff or other users rather than only by the account owner, since those are the cases where the stored payload reaches someone other than the person who set it.
- Check other fields users control that developers may assume cannot contain markup, and confirm whether they are output encoded when shown back to the browser.
Glossary
- Browser: the program you use to visit websites, such as Chrome, Safari or Firefox.
- HTML: the language web pages are written in, where text inside angle brackets is an instruction to the browser rather than something you read.
- Tag: a piece of HTML inside angle brackets, such as
<script>, that tells the browser to do something. - Script: a small program that runs inside the browser.
- XSS (cross-site scripting): a bug where text supplied by a user is treated by the browser as a script and runs.
- Stored XSS: XSS where the dangerous text is saved on the server and runs when someone later loads the page that displays it.
- Payload: the piece of text used to test or exploit a bug, here a tiny script.
- Sanitising: cleaning up input so that anything that could be read as an instruction is removed or neutralised.
- Output encoding: converting special characters into a safe form when displaying data, so text stays text.
- 1-Click purchasing: an Amazon feature that lets you buy with a single click, tied to your account and a list of associated devices.
- 1-Click Status: the part of the 1-Click settings page that lists the associated devices and their status.
- Proof of concept (POC): a small demonstration that a bug is real, here the pop-up appearing.
- Support representative: a member of a company's support staff who may view a customer's account settings while helping them.