GitHub Device Code Phishing Explained: How It Works and How to Defend

Discover how GitHub Device Code phishing attacks work, how attackers trick users, and learn effective prevention strategies. Includes step-by-step diagram & security tips.

Jul 01, 2025 - 12:29
Updated: 29 days ago
102.9k
GitHub Device Code Phishing Explained: How It Works and How to Defend

Quick answer: Device code phishing abuses the OAuth device flow. An attacker starts a login on their own app, gets a short code, and persuades you to enter it at github.com/login/device. You log in and pass 2FA yourself, so GitHub issues the attacker's app a token with the permissions you approved.

Key takeaways

  • The device flow (RFC 8628) was built for devices without a browser, such as CLIs and TVs.
  • The attack tricks a person into authorising the attacker's app. No password is stolen and 2FA is completed by the victim.
  • The real GitHub page is used, which is why it feels trustworthy. The app name and requested scopes are the clue.
  • Never enter a code you did not start yourself. If you did, revoke the app and review your account activity.
  • Organisations can restrict which OAuth apps are allowed.

What is the device authorisation flow?

Some programs cannot show a proper login page: a command-line tool, a smart TV, a build agent. The OAuth device flow, defined in RFC 8628, solves this. The program asks the service for a short user code and a verification URL. You open that URL on another device, type the code, log in, and approve the app. The program, meanwhile, polls the service until it receives an access token. GitHub's own steps are in its OAuth device flow documentation.

How is the flow abused?

The design has one weak point: the code links a request to an approval, but the service cannot tell whether the person approving it is the person who started the request. An attacker uses that gap.

  1. The attacker registers or controls an OAuth app and starts a device flow, receiving a user code.
  2. They send the victim a message, such as an email, chat or fake support note, saying the code is needed to "verify your account", join a repository, or finish a login.
  3. The victim opens the genuine GitHub verification page, enters the code, signs in and completes two-factor authentication.
  4. GitHub shows an authorisation screen for the attacker's app. If the victim clicks approve, the attacker's polling request receives a token.

The attacker never sees a password and never touches the 2FA step. The token carries whatever scopes (permissions) were granted, such as reading private repositories or writing to them. This is why defenders describe it as consent phishing rather than credential theft.

Does this bypass two-factor authentication?

Not technically. 2FA works correctly, because the real user performs it. What fails is the user's judgement about what they are authorising. That is why hardware keys and passkeys, which are excellent against fake login pages, do not by themselves stop this attack: the login happens on the real site.

What are the red flags?

  • You are asked for a code you did not generate from your own terminal or device just now.
  • The message creates urgency or comes from someone you cannot verify.
  • The authorisation screen names an application you do not recognise, or asks for broad scopes such as full repository access or organisation access.
  • The request arrives on a different channel from the tool it claims to belong to.

How do you protect yourself and your team?

Individuals: only enter a device code that your own command, for example gh auth login, just displayed on your screen. Read the app name and permissions before clicking authorise. Periodically review your authorised apps in GitHub settings and remove anything you do not use.

Organisations: use OAuth app access restrictions so members cannot grant org data to unapproved apps, review the audit log for new authorisations, prefer fine-grained tokens and GitHub Apps with narrow permissions, and train staff to treat code requests like a password request.

What should you do if you entered a code by mistake?

  1. Go to your GitHub settings and open the list of authorised OAuth applications. Revoke the app you do not recognise.
  2. Review recent account activity, SSH keys, personal access tokens and deploy keys for anything you did not create, and remove it.
  3. If you work in an organisation, tell your security team so they can check the audit log for access to private repositories.
  4. Rotate any secrets stored in repositories the app could read.

Next steps

Consent phishing is a good topic to study next to OAuth misconfiguration. You can read a real-world example of bypassing 2FA through OAuth misconfiguration and how common authentication mechanisms work. For structured training, see our cyber security course.

Related reading

Frequently Asked Questions

It is an attack where someone starts an OAuth device login with their own app and persuades you to enter the displayed code on the real service. When you approve it, the attacker's app receives an access token for your account.

It does not break 2FA. You complete 2FA yourself on the genuine page. The attack works because you then approve the attacker's app, so the token is issued despite strong login protection.

Be suspicious of any code you did not generate yourself moments ago in your own tool. Also check the app name and permissions on the authorisation screen. Unknown apps or broad scopes are warning signs.

Revoke the unknown app in your GitHub authorised applications list, review your tokens and SSH keys, rotate secrets the app could read, and tell your security team if the account belongs to an organisation.

Organisations can use OAuth app access restrictions so that members need approval before an app can access organisation data. Combine it with audit log reviews and narrow-scope tokens or GitHub Apps.

No. It is a standard, useful flow for input-limited devices. The risk comes from social engineering around it. Users should only approve codes they started and should always read the app name and requested permissions.

What's Your Reaction?

Like Like 0
Dislike Dislike 0
Love Love 0
Funny Funny 0
Wow Wow 0
Sad Sad 0
Angry Angry 0
Vaishnavi

Vaishnavi is a skilled tech professional at the Ethical Hacking Training Institute in Pune, responsible for managing and optimizing the technical infrastructure that supports advanced cybersecurity education. With deep expertise in network security, backend operations, and system performance, she ensures that practical labs, online modules, and assessments run smoothly and securely. Her behind-the-scenes contributions play a vital role in delivering a seamless and secure learning experience for aspiring ethical hackers.