Skip to content
OAuth / SSO Write-up Intermediate

Exploiting Oauth Device Authorization Risks In Microsoft 365

The OAuth Device Authorization Flow in Microsoft 365 can be abused by an attacker to obtain long-lived refresh tokens by tricking a user into authenticating a device code. This allows persistent access to Microsoft Graph APIs, potentially bypassing Conditional Access policies.

Serj Novoselov Follow

Published on infosecwriteups.com

The OAuth Device Authorization Flow (RFC 8628) is not inherently malicious. It is designed to enable authentication on devices with limited input capabilities, such as smart TVs, Command Line Interface (CLI) tools, or IoT devices.

Serj Novoselov, on infosecwriteups.com

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

Likely the device authorization flow is not restricted to trusted applications or limited by Conditional Access policies, allowing first-party apps to be abused for token theft.

Impact

An attacker could gain long-term, low-noise access to Microsoft 365 resources, potentially bypassing Conditional Access policies such as device compliance or location-based restrictions.

What the attacker needed

Victim has Microsoft 365 account; victim enters device code; attacker has tenant ID

The fix

Organizations should restrict device code flow to trusted applications and ensure Conditional Access policies explicitly cover device code authentication.

How it was found

  1. Identify the target tenant ID via the OpenID configuration endpoint.
  2. Select a first-party Microsoft client ID that supports device login.
  3. Use MSAL to generate a device code and present the login URL to the victim.
  4. Victim enters the code and completes authentication, including MFA.
  5. Attacker's application receives tokens, including a refresh token valid for up to 90 days.

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.

OAuth device login lets you sign in on a device with no keyboard by entering a short code on a website. An attacker can start this login on their own computer, send the code to a victim, and if the victim signs in, the attacker gets a token that keeps them logged in for a long time. This is dangerous because the victim never sees anything suspicious.

What is OAuth / SSO?

Mistakes in OAuth, OpenID Connect, SAML or token handling that leak codes and tokens or link an attacker's identity to a victim's account.

More by Serj Novoselov

View all

1 more disclosed report, best first.

Similar reports

View all

Same bug class and techniques, clearest first.

OAuth and single sign-on flaws

The lesson behind this report.

Mistakes in OAuth, OpenID Connect, SAML or token handling that leak codes and tokens or link an attacker's identity to a victim's account.