Stored XSS in archive.uber.com Due to Injection of Javascript:alert(0)
- Triaged in 5 hours
- Fixed in 28 days
- Paid in 33 days
- Disclosed after 40 days
Summary by the researcher
Injection of Javascript:alert(0) into the download_url or the home_page parameters of python packages caused injection of <a href=Javascript:alert(0)> into archive.uber.com which is a mirror of pypi.
The report
archive.uber.com is vulnerable to an XSS due to injection of Javascript:alert(0) as the download_url or the home_page in the setup.py when generating the .tar.gz. As of PEP 0470, the download_url and home_page parameters are depreciated.
An example of a setup.py that can exploit this is:
from distutils.core import setup
setup(
name='IgnoreMe_mime',
version='1.0.2',
author='David Dworken',
author_email='[email protected]',
packages=['IgnoreMe_mime'],
home_page='Javascript: alert(0)',
download_url='Javascript: alert(0)',
url='http://pypi.python.org/pypi/IgnoreMe_mime/',
license='LICENSE.txt',
description='XSS!',
long_description=open('README.rst').read(),
scripts=['uberPip/nothing.py'],
)
As with #126197, my PoC will be active once you run the mirror process to update archive.uber.com from pypi. Conveniently enough,, it looks like this was historically exploited on pypi, so a PoC (not mine) is already hosted on archive.uber.com here:
http://archive.uber.com/pypi/simple/ignore-me-1.0/
In order to see the alert(0) box you have to click on the link titled 1 home_page. This will work in all browsers as it is a persistent XSS rather than a reflected one.
This XSS was inadvertently fixed by PEP 0470 which removed the download_url and home_page parameters. In order to fix this, all you have to do is upgrade the software you use to host the mirror since this was fixed upstream.
Thanks, David Dworken
Context
archive.uber.com is a mirror of PyPI, the Python Package Index. A mirror of this kind serves the same package metadata that PyPI publishes, including the per-package pages that list a project's links. One of those links is the project's home page, and the mirror renders it as an anchor element for visitors to click.
The report concerns stored cross-site scripting through two package metadata fields, download_url and home_page, which are set in a package's setup.py. When a package is built into a .tar.gz and the mirror regenerates its pages from PyPI, those field values end up in the HTML served by archive.uber.com.
Setup
No accounts, roles or special tooling are described. The precondition is simply that a package carrying a malicious home_page or download_url value exists on PyPI and that the mirror process runs to pull it into archive.uber.com. The researcher notes that, as with a previous report (#126197), the proof of concept would only become active once the mirror process was run to update archive.uber.com from PyPI.
Finding it
The researcher identified that injecting Javascript:alert(0) into the download_url or home_page parameters of Python packages caused <a href=Javascript:alert(0)> to appear in archive.uber.com's output. Supplying Javascript:alert(0) in either field caused the string <a href=Javascript:alert(0)> to appear in the output of archive.uber.com. The researcher also observed that this had historically been exploited on PyPI itself, so a proof of concept that was not theirs was already hosted on archive.uber.com.
Exploitation
Step 1: Craft a package with a malicious metadata field
The researcher gives an example setup.py that sets both home_page and download_url to a JavaScript URI:
from distutils.core import setup
setup(
name='IgnoreMe_mime',
version='1.0.2',
author='David Dworken',
author_email='[redacted]',
packages=['IgnoreMe_mime'],
home_page='Javascript: alert(0)',
download_url='Javascript: alert(0)',
url='http://pypi.python.org/pypi/IgnoreMe_mime/',
license='LICENSE.txt',
description='XSS!',
long_description=open('README.rst').read(),
scripts=['uberPip/nothing.py'],
)
The relevant lines are home_page and download_url, both set to Javascript: alert(0). When the package is built into a .tar.gz, these values are carried in the package metadata.
Step 2: Wait for the mirror to sync
As with the earlier report #126197, the payload only becomes active once the mirror process runs to update archive.uber.com from PyPI. Until that sync happens, the malicious metadata is not present on the mirror.
Step 3: Use the already-hosted proof of concept
The researcher points out that the same class of injection had been exploited on PyPI historically, so a proof of concept (not the researcher's own) was already present on archive.uber.com at:
http://archive.uber.com/pypi/simple/ignore-me-1.0/
Step 4: Trigger the script
On that page, clicking the link titled 1 home_page executes the injected JavaScript and shows the alert(0) box. Because the payload is stored in the package metadata and served on every visit, the researcher notes it works in all browsers: it is a persistent XSS rather than a reflected one.
Root cause
The mirror takes the download_url and home_page values from package metadata and places them into an anchor's href without preventing a javascript: URI from being used. The resulting markup, <a href=Javascript:alert(0)>, is a link that runs script when clicked. The report does not describe any output encoding or URL scheme validation on the mirror side.
Impact
A package with a crafted home_page or download_url produces a link that runs the injected script when a visitor clicks it. The report frames this as a persistent XSS that works in all browsers. The payload shown is alert(0), and the report does not describe any further actions an attacker could take with the injected script.
Fix
The researcher states that the issue was inadvertently fixed by PEP 0470, which removed the download_url and home_page parameters. The recommended fix is therefore to upgrade the software used to host the mirror, since the problem was fixed upstream. No code change on the mirror itself is described.
Variants to test
Hunting notes
This kind of bug tends to hide wherever a service mirrors or re-renders third-party metadata, especially package indexes and repository browsers that display author-supplied URLs.
What happened, in plain words
A security researcher found that archive.uber.com, a mirror of PyPI, displayed a link built from package metadata, and clicking it ran JavaScript in the visitor's browser. The trick was to put that code into two pieces of information attached to a Python software package: the package's home page address and its download address. When the site copied those values into its own pages, the result was a link whose address was a JavaScript command. The result was a link that, when clicked, ran the code. Because the dangerous value was stored in the package's details, the researcher notes it is a persistent XSS rather than a reflected one.
Background: what the pieces are
Before the steps make sense, here are the main parts of the story.
PyPI is the Python Package Index. Think of it as a huge public library of free Python software. Anyone can publish a package there, and anyone can download one. Each package has a page listing its name, version, author and links, including a link to the project's home page and a link to download it.
A mirror is a copy of a website kept on a different server. Libraries sometimes keep a local copy of a big catalogue so that their own users can get files faster or without going to the original site. archive.uber.com was a mirror of PyPI: it served the same package information that PyPI publishes, including the per-package pages that list a project's links.
A package's setup.py is a small Python file that describes a package: its name, version, author, and so on. When the package is built, this description is packed into the package file, which in this case is a .tar.gz archive (a compressed bundle of files, like a zip file). Two of the fields in that description are home_page and download_url. They are meant to hold web addresses.
Cross-site scripting (XSS) is a class of bug where a website ends up putting someone else's code into a page that other people view, so the code runs in their browser. A simple everyday comparison: imagine a noticeboard where visitors can pin notes, and the person who runs the board copies whatever is written on a note straight onto the official board without reading it. If someone writes "tear down all the other notes" as an instruction rather than as text, and the board treats it as an instruction, the damage is done. In a browser, the "instruction" is JavaScript, the programming language that web pages use to do things.
Stored versus reflected XSS. A reflected XSS happens when the dangerous value is echoed back once, usually from something you typed into a form, and disappears afterwards. A stored XSS happens when the dangerous value is saved somewhere, such as in a database or in package metadata, and served to every visitor afterwards. Stored XSS is generally more serious because it does not depend on tricking a particular person into sending a specially crafted request.
A javascript: link. Browsers understand several kinds of address. http:// and https:// load a web page. javascript: is different: instead of loading a page, the browser runs the code that follows. So a link whose address starts with javascript: is really a small program disguised as a link.
alert(0) is the simplest possible JavaScript command: it opens a pop-up box in the browser showing the number 0. Researchers use it as a harmless demonstration that code ran. If you see the box, the code executed.
Finding it
The researcher noticed that the download_url and home_page values of Python packages were being placed into the mirror's pages without adequate handling. When either field was set to Javascript:alert(0), the string <a href=Javascript:alert(0)> appeared in the output of archive.uber.com. In HTML, the language web pages are written in, <a href=...> is the tag for a link, and the href part is the address the link points to. So the mirror was producing a link whose address was a JavaScript command.
The researcher also noticed that this same trick had been used on PyPI itself in the past. That meant a ready-made example, not created by this researcher, was already sitting on archive.uber.com, waiting to be clicked.
Exploitation
Step 1: Craft a package with a malicious metadata field
The researcher gives an example setup.py that sets both home_page and download_url to a JavaScript address:
from distutils.core import setup
setup(
name='IgnoreMe_mime',
version='1.0.2',
author='David Dworken',
author_email='[redacted]',
packages=['IgnoreMe_mime'],
home_page='Javascript: alert(0)',
download_url='Javascript: alert(0)',
url='http://pypi.python.org/pypi/IgnoreMe_mime/',
license='LICENSE.txt',
description='XSS!',
long_description=open('README.rst').read(),
scripts=['uberPip/nothing.py'],
)
Line by line:
from distutils.core import setupbrings insetup, the standard Python function used to describe a package.setup(starts the description block.name='IgnoreMe_mime'gives the package a name. The name is a hint to anyone reading it that the package is only a demonstration.version='1.0.2'gives it a version number, as every package needs one.author='David Dworken'andauthor_email='[redacted]'record who made the package.packages=['IgnoreMe_mime']lists the folders of Python code that belong to the package.home_page='Javascript: alert(0)'is the important line: the project's home page address is set to a JavaScript command instead of a normal web address.download_url='Javascript: alert(0)'does the same for the download address.url='http://pypi.python.org/pypi/IgnoreMe_mime/'is an ordinary web address for the project page on PyPI.license='LICENSE.txt'points at the licence file.description='XSS!'is a short description, here naming the bug being demonstrated.long_description=open('README.rst').read()reads a longer description from a file.scripts=['uberPip/nothing.py']lists a script file that ships with the package.- The closing
)ends the description.
Why this step: the two dangerous values have to get into the package's metadata, because that metadata is what the mirror later copies into its pages. When the package is built into a .tar.gz, these values travel inside it.
Step 2: Wait for the mirror to sync
As with the earlier report #126197, the payload only becomes active once the mirror process runs to update archive.uber.com from PyPI. Until that sync happens, the malicious metadata is not present on the mirror. A sync is simply the mirror fetching the latest information from the original site and copying it over, like a librarian updating the catalogue cards from the central library's list.
Step 3: Use the already-hosted proof of concept
The researcher points out that the same kind of injection had been used on PyPI historically, so a proof of concept (not the researcher's own) was already present on archive.uber.com at:
http://archive.uber.com/pypi/simple/ignore-me-1.0/
This is the mirror's page for a package called ignore-me, version 1.0. The address follows the mirror's pattern for package pages. Because the page already existed with the dangerous value inside it, there was no need to wait for a fresh sync to show the problem.
Step 4: Trigger the script
On that page, clicking the link titled 1 home_page runs the injected JavaScript and shows the alert(0) box. The link is labelled with the field name, so a visitor sees a normal-looking link and has no reason to suspect that its address is a command rather than a web page.
Because the payload is stored in the package metadata and served on every visit, the researcher notes it works in all browsers: it is a persistent XSS rather than a reflected one. In other words, the dangerous value is not a one-off echo of something a visitor typed; it lives on the page and affects anyone who clicks.
Root cause
The mirror takes the download_url and home_page values from package metadata and places them into a link's href without preventing a javascript: address from being used. The resulting markup, <a href=Javascript:alert(0)>, is a link that runs script when clicked. The report does not describe any output encoding or address-scheme checking on the mirror side.
A useful comparison: a receptionist who copies a caller's name onto a visitor badge without checking it is fine if the name is "Jane Smith", but not if the caller writes "give this person the master key". The badge system has to treat the input as text, not as an instruction.
Impact
A package with a crafted home_page or download_url produces a link that runs the injected script when a visitor clicks it. The report frames this as a persistent XSS that works in all browsers. The payload shown is alert(0), and the report does not describe any further actions an attacker could take with the injected script.
Fix
The researcher states that the issue was inadvertently fixed by PEP 0470, which removed the download_url and home_page parameters. A PEP is a Python Enhancement Proposal: a document that describes a change to how Python or its packaging works. Removing the two fields removed the place where the dangerous value could be stored. The recommended fix is therefore to upgrade the software used to host the mirror, since the problem was fixed upstream. No code change on the mirror itself is described.
Variants to test
These are other places where the same idea might work:
Hunting notes
This kind of bug tends to hide wherever a service mirrors or re-renders third-party metadata, especially package indexes and repository browsers that display author-supplied addresses.
Glossary
- PyPI: the Python Package Index, a public catalogue where Python packages are published and downloaded.
- Mirror: a copy of a website or catalogue kept on another server and kept up to date from the original.
- Package: a bundle of software, here a Python project, distributed as a single file.
setup.py: the Python file that describes a package's name, version, author and links..tar.gz: a compressed archive file, similar to a zip file, used to distribute software.- Metadata: descriptive information about something, such as a package's name, author and links.
home_page: a metadata field meant to hold the address of a project's home page.download_url: a metadata field meant to hold the address where a project can be downloaded.- Cross-site scripting (XSS): a bug where a website puts someone else's code into a page, so it runs in visitors' browsers.
- Stored XSS: XSS where the dangerous value is saved and served to every visitor, rather than echoed back once.
- Reflected XSS: XSS where the dangerous value is echoed back once, usually from something a visitor typed.
- JavaScript: the programming language that web pages use to run code in the browser.
javascript:link: a link whose address is a JavaScript command, so clicking it runs code instead of loading a page.alert(0): a JavaScript command that opens a pop-up showing 0, used to prove that code ran.- HTML: the language web pages are written in.
<a href=...>: the HTML tag for a link; thehrefpart is the address the link points to.href: the attribute of a link that holds its address.- Output encoding: converting data so that a browser treats it as text rather than as code or an instruction.
- Address scheme: the first part of a web address, such as
http://orjavascript:, which tells the browser what kind of address it is. - PEP: a Python Enhancement Proposal, a document describing a change to Python or its packaging.
- PEP 0470: the proposal that removed the
download_urlandhome_pagefields. - Sync: the process by which a mirror fetches the latest information from the original site.
- Proof of concept (PoC): a small demonstration that a bug is real and can be triggered.
- Recon: the early stage of exploring a target to understand what it is made of.
- Payload: the piece of code or value used to trigger a bug.