Blog · Dmarc

Device-Code Phishing: Why Mailbox Persistence Changes the Risk Profile

What is device-code phishing?

Device-code phishing abuses the OAuth 2.0 device authorization grant flow. This standard mechanism lets devices with limited input - smart TVs, CLI tools, IoT hardware - authenticate users without a full browser. Attackers have learned to abuse it for account takeovers that bypass most MFA.

Here is how the attack works. The attacker initiates a device code flow against the OAuth authorization server - Microsoft Entra ID or Google Workspace. The server responds with a short-lived user code and a URL. The attacker sends the victim a phishing message containing this code and URL, framed as a "verification required" prompt. The victim visits the URL, enters the code, and logs in. The attacker, who controls the token endpoint, captures the resulting access token and refresh token.

No credential is stolen. No session cookie is intercepted. The victim performed a genuine login with their second factor. The attacker simply receives a valid token pair because the victim handed it to them, under false pretenses.

How mailbox persistence extends the attack

The access token is short-lived - typically an hour or less. The refresh token is where the real danger lies.

OAuth refresh tokens are designed to persist beyond the access token's lifetime. When an attacker holds a refresh token obtained through device-code phishing, they can obtain new access tokens indefinitely - until the token is explicitly revoked. In a Microsoft 365 environment, refresh tokens can remain valid for 90 days by default, with automatic refresh meaning the attacker needs no further interaction from the victim. The user can log out, change their password, or enroll a new MFA device. The attacker still has access as long as the refresh token has not been revoked.

This is fundamentally different from session hijacking. A stolen session cookie typically expires when the user logs out or the session times out. With refresh token chaining, the attacker holds an autonomous credential that requires no further victim participation.

Once inside the mailbox, a motivated attacker often takes additional steps to ensure long-term access:

  • Registering a new OAuth application with delegated permissions, creating a backdoor that survives token rotation and password changes
  • Setting up mailbox forwarding rules to silently copy incoming mail
  • Adding attacker-controlled accounts as mailbox delegates
  • Using the compromised account to launch further phishing attacks within the organization

Why conditional access policies often miss this attack

Organizations relying on Conditional Access to enforce MFA and device compliance may assume they are protected. Device-code phishing frequently evades these controls because the evaluation occurs at token issuance, not token use.

When a refresh token is used to silently obtain a new access token, the authorization server may not re-evaluate Conditional Access policies. The access token is issued based on the original grant's stored properties - including whether the device was compliant at the moment of the initial device-code login. If that device was BYOD or non-compliant, the resulting tokens carry that compromise forward.

Microsoft's Continuous Access Evaluation (CAE) can enforce Conditional Access changes at the token-use stage, but not all applications and scenarios support CAE. Legacy applications, certain API calls, and cross-tenant scenarios fall back to the older model where access decisions are cached and not re-evaluated until token expiry. In practice, this means a device-code phishing session can remain active under a non-compliant device classification long after the Conditional Access policy has been updated to block that classification.

Detection signals security teams should monitor

Unusual client application IDs: OAuth token requests from client IDs not associated with sanctioned applications. Microsoft and Google publish lists of known first-party and third-party application IDs. Token requests from unknown clients - particularly recently registered OAuth apps with mailbox permissions - warrant investigation.

New device ID with existing refresh token: A new device appearing in the environment combined with an active refresh token from an unfamiliar OAuth client. The initial device-code grant creates a fresh device record. The attacker reuses the refresh token to maintain access. This pattern - new device, established refresh token - is a strong detection signal because it decouples the device identity from the token lifecycle.

Impossible login characteristics: A session from a geographic location or IP range inconsistent with the user's normal patterns, particularly when paired with a previously unseen device.

Mailbox rule changes after unusual authentication: Any inbox rule created shortly after a suspicious login event, especially rules that forward, redirect, or delete mail.

API or PowerShell activity from mailbox context: A user account that normally uses only Outlook or OWA suddenly making Graph API calls or PowerShell connections.

Token issuance events where the grant type is device_code: This is the foundational detection event. Monitor for device-code grant flows that result in token issuance, and flag cases where the requesting client ID has not been pre-approved.

DMARC aggregate reports showing new sending sources on your domain: When a compromised mailbox is used to send authenticated mail, DMARC reports will show a previously unseen sending source. DMARCFlow monitors these aggregate reports and alerts on new return-paths, providing a domain-level detection signal that is independent of the identity and endpoint controls above. This is one of the few places where mailbox compromise shows up as a domain-level signal rather than a user-level one - and it often surfaces before the account owner notices anything wrong.

Detection checklist for SOC teams:


  • Monitor for token issuance events where the grant type is device_code

  • Flag new OAuth applications registered within the past 30 days that request mailbox permissions

  • Alert on refresh token usage from new IP ranges or ASNs not previously associated with the user

  • Watch for mailbox delegation changes or forwarding rule creation

  • Correlate device-code login events with downstream mailbox activity within a short time window

  • Monitor DMARC aggregate reports for new sending sources appearing on your domain

Hardening Microsoft 365 and Google Workspace against device-code phishing

Restrict the device code flow through Conditional Access: Microsoft Entra ID allows policies to block the device code grant type. Creating a policy that targets "Device code" as the client app, excluding only sanctioned applications, reduces the attack surface significantly. Evaluate this carefully for organizations that use device-code authentication for legitimate kiosk or CLI purposes.

Require phishing-resistant MFA for sensitive accounts: Enforce FIDO2 hardware keys or Windows Hello for Business for accounts with high-privilege access or access to executive mailboxes. These authentication methods resist device-code phishing because they require physical presence and cannot be relayed through a simple code exchange.

Disable legacy authentication protocols: Device-code phishing works partly because legacy authentication does not enforce modern Conditional Access. Disabling POP3, IMAP, and SMTP at the tenant level removes an entire class of token theft vectors.

Implement token lifetime policies: Microsoft Entra ID allows administrators to configure maximum refresh token lifetimes. Shorter lifetimes reduce the window during which a stolen refresh token remains useful. Note the user experience implications for legitimate scenarios before applying restrictive policies.

Audit OAuth app permissions regularly: Run quarterly reviews of all registered OAuth applications. Remove permissions for applications not used in the past 90 days. Enforce a policy requiring business justification for mailbox-access scopes.

Monitor DMARC reports actively: DMARCFlow watches aggregate reports for new sending sources, which can indicate that a compromised mailbox is being used to send as your domain. This domain-level signal catches sending anomalies that user-level identity controls may miss, and provides an independent detection path that does not rely on Conditional Access evaluation.

---

Device-code phishing is not a vulnerability in Microsoft 365 or Google Workspace. It is an abuse of a legitimate authentication mechanism that most security tooling was not designed to catch at the token-issuance step. The addition of mailbox persistence turns a short-term account takeover into a durable presence inside the organization.

Detection and prevention require a combination of Conditional Access tightening, token lifetime management, behavioral monitoring, and domain-level signals like DMARC aggregate reports. No single layer is sufficient. The attack works precisely because it chains together multiple legitimate features in ways that individual controls do not catch in isolation.