Cross-Domain Leakage of X Username / UserID due to Dynamically Generated JS File
The service worker script at twitter.com/sw.js includes a dynamically generated user ID when requested with an authentication cookie. Because JavaScript imports are not subject to the Same-Origin Policy, a malicious site could import the script and read the victim's X user ID, which can then be used to look up their username.
Originally disclosed on HackerOne
- Triaged in 35 days
- Fixed in 41 days
- Paid in 36 days
- Disclosed after 6 months
Summary by the program
Because the Same-Origin Policy does not apply to JavaScript imports, a malicious website could deanonymize users by retrieving their user ID from https://twitter.com/sw.js.
The report
Summary:
It was found that twitter.com hosts a specific javascript file whose content is partly dynamically generated, depending on the requestor's user authentication cookie. This dynamic part actually reveals the X's User ID of the requestor. Since the Same-Origin-Policy doesn't apply to javascript file imports, an attacker can force a victim X user to import it from a malicious cross-domain application, then extract the User-ID, leading to the retrieval of the associated X username (via X API).
Description:
The leaky JS file is the following: https://twitter.com/sw.js
When requested with the cookie 'auth_token', the attribute 'INITIAL_STATE ' is populated in the following way:
self.__INITIAL_STATE__ = {"userId":"█████"};
Steps To Reproduce:
- Log in to your X account
- Visit the following malicious website:
███████ - Your X User ID has been retrieved
Impact
X users become precisely identifiable from any remote website.
This implies the following:
- Privacy / Confidentiality issue
- Facilitation of X users tracking
- Facilitation of phishing attacks at scale via better targeting
- Facilitation of potential CSRF attacks at scale, for request depending on userId / username or any other public attribute that would initially be unknown to an attacker willing to target a maximum number of users.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Root cause
Likely the service worker script was generated per-user and embedded the authenticated user's ID in a global variable, without considering that cross-origin script imports can read such values.
Impact
X users could be precisely identified from any remote website, which may facilitate tracking, targeted phishing, and some CSRF attacks.
What the attacker needed
Victim is logged in to X; victim visits attacker-controlled site
How it was found
- Log in to your X account.
- Visit the malicious website.
- The site imports the script and extracts your X user ID.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
Websites normally cannot read data from another site you are logged into, because of a rule called the Same-Origin Policy. But that rule does not stop a page from loading another site's JavaScript file, and this particular file contained your account ID when you were logged in. So a malicious page could load the file, read your ID, and use it to find your public username.
What is Info disclosure?
Data the application should keep private (personal data, internal details, other users' records) reaches someone it should not.