7. Device code phishing and security

10 cards

Review this deck
All cards in this deck

Device code phishing

The attacker starts a device flow themselves and tricks the victim into entering the user_code on the real sign-in page; the token goes to the attacker.

Why MFA does not stop device code phishing

The victim completes MFA on the real page themselves, for a session the attacker started.

Mitigation with a short expires_in

A code that lives only a few minutes narrows the phishing window.

Mitigation with the consent page

Clearly show the application, the IP/location of the initiating device, and a warning to continue only if you just ran the command yourself.

Mitigation with policy

Block device flow for users/apps that do not need it, e.g. the Conditional Access "authentication flows" condition in Microsoft Entra ID.

Restricting clients

Allow only registered clients to use the device grant; do not enable it for every application.

Loopback risk

A malicious app on the machine grabs the port or intercepts the code; PKCE means an intercepted code cannot be exchanged for a token.

DNS rebinding

An attacker's domain resolves to 127.0.0.1 so a web page can read the loopback server; block it by checking that the `Host` header equals `127.0.0.1:{port}`, requiring `state`, and using an IP literal.

Token theft on the developer machine

Mitigate with the keychain, short-lived access tokens, least-privilege scopes, refresh token rotation.

Audit log

Record the time, IP, and client of each device code approval to investigate incidents.

7. Device code phishing and security – Flashcards – CLI Auth | Học Dev