# Cross-Domain Leakage of X Username / UserID due to  Dynamically Generated JS File

twitter.com/sw.js embeds the requester's userId in __INITIAL_STATE__; cross-origin JS import lets any site deanonymize a logged-in X user.

- Payout: $1,500
- Severity: medium
- Program: X / xAI
- Found by: th0h0
- Disclosed: 2024-05-10
- Write-up quality: 6/10
- Original: https://hackerone.com/reports/2244229
- Library page: https://bugbountylibrary.com/r/h1%3A2244229
- Tags: area:web domain:web impact:pii-leak kind:bounty platform:hackerone sev:medium tech:rest technique:js-analysis vuln:info-disclosure vuln:xs-leak

**Target:** Service worker JS endpoint (twitter.com/sw.js) with cookie-dependent dynamic content
**Root cause:** The service worker script is dynamically generated per-request and injects the authenticated user's userId into __INITIAL_STATE__, and JS imports are not subject to Same-Origin Policy so any origin can read it.
**Steps:**
1. Log in to X account in browser
2. Visit attacker page that imports `https://twitter.com/sw.js` (e.g. via `<script src>` or dynamic import) with credentials
3. Read `self.__INITIAL_STATE__.userId` from the loaded script
4. Resolve userId to username via X API
**How found:** Noticed sw.js content is partly dynamically generated based on the auth_token cookie and contains __INITIAL_STATE__ with userId; realized SOP does not block cross-origin script imports.
**Exploitation:** Attacker hosts a page that loads twitter.com/sw.js cross-origin; the victim's auth_token cookie is sent, the script populates __INITIAL_STATE__ with the victim's userId, and attacker JS reads it to identify the user.
**Escalation:** userId maps to username via public X API, enabling tracking, targeted phishing, and CSRF against userId-dependent endpoints at scale.
**Insight:** Service worker scripts and other JS endpoints that are dynamically templated per-user can leak identity because script imports bypass SOP — check sw.js/manifest/config JS for per-request state injection.

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

**Leaky service worker JS with userId**

```
self.__INITIAL_STATE__ = {"userId":"█████"};
```

