# Stored XSS on PyPi simple API endpoint

Stored XSS via unsanitized requires_python field rendered into HTML on GitLab's PyPi simple API endpoint, executing JS when a victim visits the package URL.

- Payout: $3,000
- Severity: medium
- Program: GitLab
- Found by: vakzz
- Disclosed: 2020-09-09
- Write-up quality: 6/10
- Original: https://hackerone.com/reports/856836
- Library page: https://bugbountylibrary.com/r/h1%3A856836
- Tags: area:web domain:web impact:integrity kind:bounty platform:hackerone sev:medium tech:ruby technique:source-review vuln:xss

**Target:** GitLab PyPi package registry simple API endpoint (/api/:version/projects/:id/packages/pypi/simple/*package_name)
**Root cause:** package_presenter.rb interpolates the user-controlled requires_python value directly into an HTML attribute without escaping; only a 50-char DB length constraint applies.
**Steps:**
1. Create a project and obtain an API token.
2. Upload a PyPi package with `requires_python='"><script>alert(1)</script>'` via `curl -F requires_python='"><script>alert(1)</script>' .../packages/pypi`.
3. Visit `/api/v4/projects/:id/packages/pypi/simple/<package_name>` and observe the injected `<script>` in the rendered HTML.
**How found:** Code review of the new PyPi package feature's presenter revealed string interpolation of user-controlled fields into HTML without escaping.
**Exploitation:** Attacker uploads a package with a crafted requires_python value, then sends the victim a link to the simple API endpoint; the payload breaks out of the data-requires-python attribute and executes JS in the victim's session. CSP on gitlab.com currently blocks execution.
**Insight:** New package-registry endpoints that render HTML (PyPi simple index) are prime XSS surfaces; audit presenter/view code for raw interpolation of package metadata fields, not just the obvious name/version.

## Proof of concept (copied exactly from the original report)

**curl upload with XSS payload in requires_python**

```
curl -v "https://__token__:$TOKEN@gitlab.com/api/v4/projects/18315917/packages/pypi" -F content=@/tmp/lala.txt -F requires_python=2.7 -F version=1 -F name='package_test_1' -F requires_python='"><script>alert(1)</script>'
```

**Rendered HTML showing injected script tag**

```
<a href="https://gitlab.com/api/v4/projects/18315917/packages/pypi/files/lala.txt#sha256=" data-requires-python=""><script>alert(1)</script>">lala.txt</a><br>
```

