Blog · Dmarc
How Attackers Use Device Code Authentication to Bypass Microsoft 365 Phishing Defenses
OAuth 2.0 device code authentication (RFC 8628) lets users sign in to devices that cannot run a full browser by using a second device as the authentication terminal. It is legitimate, standards-based, and used by Microsoft, Google, and GitHub. It is also increasingly used by attackers who trick users into authenticating on the real Microsoft endpoint while the attacker collects the resulting session tokens. The attack works because the user is genuinely on microsoft.com. There are no spoofed headers, no forged domains, and no red flags that SPF, DKIM, or DMARC are designed to catch.
How the Attack Works
The phishing variant of this attack targets the user, not the limited device. Here is the sequence:
Step 1: The attacker prepares a phishing page. It displays a fake product activation form, license renewal prompt, or tech support portal. It includes a fabricated device code and instructions to visit microsoft.com/devicelogin.
Step 2: The victim goes to the real Microsoft endpoint. The URL the victim sees is genuine. The TLS certificate is valid. The page belongs to Microsoft. This is what makes the attack effective: nothing looks wrong.
Step 3: The victim enters the device code and authenticates. The victim signs in with their M365 credentials and approves the consent prompt. From their perspective, they just logged into a Microsoft service.
Step 4: The attacker collects the token. While the victim is completing the Microsoft login, the attacker's server is polling the authorization endpoint using the same device code. Microsoft issues tokens to the first party that polls after the user approves. The attacker wins that race.
Step 5: The attacker has a persistent session. The tokens are real. If the attacker requested Mail.Read, Mail.Send, or Files.ReadWrite.All scopes, they now have access to the victim's email and files. Critically, this access survives password changes. Revoking it requires actively removing the OAuth application from the tenant.
Why Email Authentication Does Not Catch This
SPF, DKIM, and DMARC operate on the email layer. They verify that an email's From header was authorized by the domain owner. They do not see OAuth authentication events that never involve sending email.
- SPF validates the envelope sender, not OAuth tokens.
- DKIM confirms an email was signed by an authorized mail server, not that an OAuth session is legitimate.
- DMARC aligns the From header domain with the sending infrastructure, entirely separate from OAuth.
An attacker with a valid device code token can read your M365 inbox, send calendar invites, and access SharePoint files without ever triggering a single SPF, DKIM, or DMARC check. There is no forged From address. There is no unauthorized mail server. Your email authentication records had no visibility into this session because OAuth operates in an entirely different authentication layer.
This is the practical implication: a strong DMARC policy does not prevent device code phishing. Your email gateway is not failing to catch this because it is misconfigured. It is not catching it because it was never designed to.
Realistic Attack Scenario
A professional services firm runs Microsoft 365 with DMARC at p=reject, an email gateway, and regular phishing training. Their team feels confident about email-based risks.
A partner receives an email from what appears to be their software vendor. The message says their license has expired and they need to renew by visiting a link. The link reads https://portal microsoft.com/device-login. The partner clicks, sees a Microsoft login page, enters their credentials, and approves the sign-in.
What the partner does not realize is that the URL was a device code authorization page, not a vendor portal. The attacker used the resulting session to register a malicious OAuth application in the partner's M365 tenant. From that moment, the attacker has persistent access to the partner's email and files that does not depend on the partner's password. A password reset will not revoke this access.
This is the specific danger of device code phishing: it creates credential-independent persistence inside your tenant.
Detection Signals in Azure AD Sign-In Logs
Device code authentication leaves traces in Azure Active Directory sign-in logs. Security teams that know what to look for can identify suspicious patterns.
Look for:
- Sign-in events with grant type "device code" that occur outside your normal patterns. If a user typically uses device code for specific CI/CD pipelines or admin tools, an unfamiliar location or browser profile is worth investigating.
- Applications granted access via device code that were not requested through your standard approval workflow. Azure AD logs show which app was authorized, when, and from which IP.
- High volumes of device code grants from a single IP in a short time window. Legitimate device code usage is typically low-frequency. Bursts suggest automation.
To access this data: open the Azure AD sign-in logs, filter by authentication method "Device Code," and cross-reference with your Conditional Access policies to see which flows were permitted or blocked.
Monitoring Across Authentication Layers With DMARCFlow
This is where two separate monitoring strategies come together.
Device code phishing operates in your OAuth layer. DMARCFlow monitors your email authentication layer. The two are distinct, but they intersect when an attacker with a stolen OAuth session uses it to send mail from your domain.
If a compromised OAuth application starts sending outbound email through your M365 tenant, it will appear in your DMARC aggregate reports as sending from IPs you do not recognize, with DKIM signatures that do not match your published record, or with SPF alignment that fails your policy. DMARCFlow can alert on these anomalies, giving your security team an early warning that something in your tenant is sending unauthorized mail.
The email authentication layer does not prevent device code phishing. But for organizations that want visibility across both the OAuth session layer and the email sending layer, DMARC aggregate monitoring provides a signal that is otherwise easy to miss.
Conditional Access Policies That Help
Conditional Access can reduce device code phishing risk without blocking the flow entirely.
Require phishing-resistant authentication for sensitive apps. If your high-value applications support Windows Hello for Business, FIDO2 security keys, or certificate-based authentication, require those methods and exclude device code grants from the allowed methods for your most sensitive workloads.
Flag or block device code flows from unfamiliar locations. Treat device code as a higher-risk signal than standard interactive login, particularly when the sign-in originates from a country where your organization does not typically operate.
Restrict user consent for OAuth applications. In Azure AD, you can require admin review for new application consents. This does not stop device code phishing directly, but it prevents an attacker from silently installing a malicious app without anyone noticing.
App Consent and Persistent Access
After obtaining a token, an attacker's next step is typically registering a malicious OAuth application in the victim's tenant. This gives them persistent access that survives credential resets.
To find unauthorized OAuth apps in your tenant:
- In the Azure AD admin center, go to Enterprise applications > Consent and permissions.
- Look for app consent grants authorized recently that you do not recognize.
- Check sign-in activity for each app: who authorized it, from which IP, and what permissions were granted.
Permissions like Mail.Read, Mail.Send, Files.ReadWrite.All, and User.Read are common targets. An app that requests Outlook access and was consented by a single user following a device code phishing event is a high-priority finding.
Revoke suspicious app permissions immediately and reset the compromised user's session. Also check whether the app was granted application permissions (which do not require a user to be present) rather than delegated permissions.
What to Check in Your M365 Tenant Today
Two things you can do right now:
First: check your Azure AD sign-in logs for device code authentications you did not authorize. Filter by authentication method, check the application names, and revoke anything that looks wrong.
Second: review your user consent settings. In the Azure AD admin center, go to Enterprise applications > Consent and permissions, and change the user consent setting to require admin review for new applications. This limits the ability of an attacker to silently add an app to your tenant after a successful device code phishing event.
Device code phishing exploits a real standard, a real endpoint, and real authentication behavior. Your email authentication posture is not the vulnerability. The gap is in OAuth application oversight and sign-in log monitoring. Close those two things first.