Hacking Facebook CSRF device login flow
The device login flow lacked CSRF protection when linking a user_code to an application code, allowing an attacker to trick a victim into authorising the attacker's device and obtain the victim's access token. Exploitation required the victim to have previously approved an app with 'Login for Devices' enabled, making it a 'perfect storm' vulnerability.
Published on josipfranjkovic.com
Facebook has published a way to use OAuth on Internet of Things devices, called Facebook Login for Devices. You can read the documentation here.
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.
Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.
How it worked
Root cause
The endpoint that links the user_code to the application code did not include any CSRF protection, allowing an attacker to forge the request.
Impact
An attacker could obtain the victim's access token, potentially leading to information disclosure on any Facebook account, but only if the victim had approved an app with 'Login for Devices' enabled.
What the attacker needed
Victim has approved an app with 'Login for Devices' enabled; attacker knows which app the victim approved
The fix
Facebook fixed the issue by adding a re-confirmation prompt and later implementing CSRF protection through the 'state' OAuth parameter.
How it was found
- Attacker requests a device code from Facebook's OAuth endpoint to get a user_code and hash code.
- Attacker presents a page to the victim that loads the OAuth dialog URL with the attacker's user_code as a parameter.
- The OAuth dialog redirects to the device.php endpoint with the user_code and an application code, which succeeds.
- Attacker requests a device token using the hash code to obtain the victim's access token.
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 write-up has not been written yet. The Original tab links to the source.
When you log in to an app using Facebook on a device like a smart TV, you enter a short code. The report found that an attacker could trick you into entering a code that belongs to them, so that your Facebook account gets linked to the attacker's device. This only worked if you had already approved a special app that supports device login.
What is CSRF?
Another site makes a signed-in user's browser perform an action they did not intend.