Skip to main content
Back to Blog
Security

Device Code Phishing in Microsoft 365: How to Block It

Device code phishing signs attackers into Microsoft 365 on the real login page, MFA and all. Find who uses the flow, then block it with Conditional Access.

PlatOps Team
Author
Published: November 19, 2026
9 min read

An email that looks like a Teams invite or a shared invoice asks the reader to go to microsoft.com/devicelogin and type a short code. The page is real Microsoft, and so is the sign-in, MFA prompt included. When it finishes, the attacker holds valid tokens for that user's mailbox, OneDrive and Teams, and the user never typed a password into anything fake.

This is device code phishing, and in 2026 it stopped being a niche technique. In April, Microsoft Defender researchers described a widespread campaign driven by the EvilTokens phishing-as-a-service kit that used the stolen sessions to register devices, map the organization through Microsoft Graph and set inbox rules to watch for invoices and wire transfers. Microsoft now blocks the flow by default in security defaults for new tenants and pushes a managed Conditional Access policy that blocks it.

If your company runs on Microsoft 365 and nobody has looked at authentication flows in Entra ID, start by finding who legitimately uses device code sign-in. Then you can block it without breaking the meeting-room displays.

TL;DR

  1. Device code phishing gets the victim to complete a real Microsoft sign-in on the attacker's behalf, so password managers, URL checks and standard MFA prompts do not stop it.
  2. Microsoft recommends blocking device code flow wherever possible; a Conditional Access policy with the Authentication flows condition does it, and it needs at least Microsoft Entra ID P1.
  3. Before you block, filter the Entra sign-in logs by Authentication protocol = Device code for 30 days. Typical legitimate users are Teams Rooms and other shared devices, and some admins running CLI tools.
  4. Exclude break-glass accounts, a named group of approved device accounts, and the Device Registration Service resource. Run the policy in report-only mode first.
  5. Check for the Microsoft-managed Block device code flow policy. Left in report-only, it is switched on automatically no less than 30 days after it appears, so set exclusions first.
  6. If someone already entered a code, revoke their sessions, look for newly registered devices and new inbox rules, and remember that issued access tokens can stay valid for up to an hour.

How the attack works

Device code flow, defined in RFC 8628, exists for devices that cannot show a full sign-in page: smart TVs, printers, conference room consoles. The device gets a code from Microsoft, shows it, and asks you to enter it on another device. It polls until you finish, then receives the tokens.

On the Microsoft identity platform, the request goes to /oauth2/v2.0/devicecode, and the user has 15 minutes to sign in from the moment it is sent:

POST https://login.microsoftonline.com/organizations/oauth2/v2.0/devicecode
Content-Type: application/x-www-form-urlencoded

client_id=<public-client-app-id>&scope=openid%20profile%20offline_access

The response contains a device_code the client keeps, a short user_code for the human, and the verification_uri. Nothing in the protocol ties the person entering the code to the device that requested it. The attack follows from that gap. The attacker requests a code from their own machine and gets you to enter it, and their polling client receives your tokens.

Two details make it effective. Every page the victim sees is genuine Microsoft, so "check the URL" training works against you. And the attacker picks the client ID. In the Storm-2372 campaign Microsoft documented in 2025, the actor switched to the client ID of the Microsoft Authentication Broker, used the refresh token to register an attacker-controlled device in Entra ID, and obtained a Primary Refresh Token from it.

The 15-minute expiry used to limit the attack, because a code embedded in an email went stale quickly. The 2026 kits generate the code only when the victim clicks the link, so the code is always fresh when the victim reaches the prompt.

Step 1: find out who uses device code flow today

Blocking a flow nobody uses is free. Blocking one your boardroom display depends on gets you a phone call on Monday morning. Check the logs first.

In the Microsoft Entra admin center, go to Entra ID > Monitoring & health > Sign-in logs, add the Authentication protocol filter and set it to Device code. Microsoft's authentication flows documentation points to the same filter, or a report-only policy, as the way to see current usage.

If you stream sign-in logs to a Log Analytics workspace or Microsoft Sentinel, the SigninLogs table has an AuthenticationProtocol column whose values include deviceCode:

SigninLogs
| where TimeGenerated > ago(30d)
| where AuthenticationProtocol == "deviceCode"
| summarize SignIns = count(),
            Apps = make_set(AppDisplayName),
            Countries = make_set(Location),
            LastSeen = max(TimeGenerated)
          by UserPrincipalName, ResultType
| order by SignIns desc

Sort what you find into three buckets:

What you seeLikely causeAction
Room or shared-device resource accountsTeams Rooms, Teams Android devices, signagePut them in a named exception group
An admin or engineer, a few times a monthaz login --use-device-code, older PowerShell modules, CLI toolsMove them to browser or broker sign-in; exception only with an owner
An ordinary user, once, from an unfamiliar countryPossible phishingTreat as an incident (see below)

Step 2: build the blocking policy

The Microsoft procedure is short. Under Entra ID > Conditional Access > Policies > New policy:

  • Users: include All users. Exclude your emergency access (break-glass) accounts and the exception group from Step 1.
  • Target resources: include All resources. Exclude Device Registration Service. Since September 2024 Microsoft enforces authentication flows policies on that resource when a policy targets all resources, and Teams devices that register through device code flow break without the exclusion.
  • Conditions > Authentication flows: set Configure to Yes and select Device code flow.
  • Grant: Block access.
  • Enable policy: Report-only.

The same policy in Microsoft Graph PowerShell, for version control:

Connect-MgGraph -Scopes "Policy.Read.All","Policy.ReadWrite.ConditionalAccess"

$params = @{
  displayName = "BLOCK - Device code flow - All users"
  state       = "enabledForReportingButNotEnforced"   # report-only
  conditions  = @{
    clientAppTypes = @("all")
    users = @{
      includeUsers  = @("All")
      excludeGroups = @("<break-glass-group-id>", "<device-code-exceptions-group-id>")
    }
    applications = @{
      includeApplications = @("All")
      excludeApplications = @("01cb2876-7ebd-4aa4-9cc9-d28bd4d359a9")  # Device Registration Service
    }
    authenticationFlows = @{ transferMethods = "deviceCodeFlow" }
  }
  grantControls = @{ operator = "OR"; builtInControls = @("block") }
}

New-MgIdentityConditionalAccessPolicy -BodyParameter $params

01cb2876-… is Microsoft's client ID for Device Registration Service, and deviceCodeFlow is a documented value of transferMethods.

Leave it in report-only for a week, check the Policy impact tab, then switch it to On.

Exceptions are per account, not per app

Microsoft is explicit that an exception is account-scoped: an excluded account can use device code flow for any app in scope. Keep the group to genuine room and shared-device resource accounts, with an owner and a ticket for each, and never add a whole department because one person uses a CLI. For automation, Microsoft points to managed identities or workload identity federation; we covered the same pattern for CI pipelines in GitHub Actions OIDC for AWS.

What breaks after you turn it on

Conditional Access tracks sessions that started with device code flow through later token refreshes, so a device that signed in with a code before the policy existed can be signed out with error AADSTS530036. Microsoft calls this expected behavior for protocol-tracked sessions. When a meeting room goes dark the morning after enforcement, open the blocked sign-in and check Original transfer method. If it says Device code flow, the fix is to add the room account to the exception group and sign the device in again.

Step 3: check what Microsoft already did in your tenant

Two Microsoft changes may have done part of this already.

Security defaults. The security defaults page now lists blocking device code flow among its basic controls, and states that all new tenants created from July 1, 2026 block it. Security defaults are on or off with no exceptions, so a company relying on them with a Teams Room has to choose between the room and the protection.

Microsoft-managed policies. On tenants with eligible licensing, Microsoft creates a managed policy called Block device code flow in report-only state. If nobody acts, Microsoft enables it no less than 30 days later, with an email and a Message center post two weeks before. You can exclude users or turn it off, but you cannot rename or delete it. Look in Conditional Access > Policies for entries showing Microsoft in the Created by column. If the managed policy fits, add your exclusions to it; if you built your own, keep one of the two and turn the other off so nobody has to debug two overlapping blocks.

If someone already entered a code

Blocking new sign-ins does nothing about tokens an attacker already holds. For each affected user:

  1. Revoke sessions with Revoke-MgUserSignInSession -UserId user@example.com. This invalidates refresh tokens. Microsoft notes that access tokens can remain valid for up to an hour after revocation, so consider disabling the account for that window.
  2. Check Devices in Entra ID for anything the user "registered" recently and delete it. Both campaigns described above registered devices to keep long-term access.
  3. Review the mailbox for new inbox rules, especially rules that move or delete messages mentioning invoices, payments or the user's finance contacts.
  4. Look at what the account sent after the sign-in. Storm-2372 used compromised mailboxes to phish colleagues internally.

If you would like help with containment and the forensic side, that is what our incident response retainer is for.

Where this fits with the rest of your identity controls

Blocking device code flow closes one route. Phishing kits that proxy the real sign-in page and steal session cookies remain, and the controls Microsoft recommends against both are phishing-resistant MFA (passkeys or FIDO2 keys), Conditional Access and sign-in risk policies. Someone still has to watch the alerts. Our zero trust guide for small businesses covers how those pieces fit together, and IT and security for businesses without an IT team covers who should own them when there is no IT department.

For a tenant that has grown without a security baseline, Conditional Access design is part of our Microsoft 365 security hardening work.

Frequently asked questions

Does MFA stop device code phishing? Standard MFA does not. The victim completes the MFA prompt themselves on the genuine Microsoft page, and the tokens that result go to the attacker's polling client. Phishing-resistant methods such as passkeys raise the bar for the related adversary-in-the-middle attacks, but the dependable control for device code phishing is a Conditional Access policy that blocks the flow.

Will blocking device code flow break Teams Rooms or Azure CLI? It can, which is why you check the sign-in logs first. Teams Rooms and other shared Teams devices use device code flow for first sign-in and some reauthentication, so put their resource accounts in an exception group and exclude Device Registration Service. Azure CLI signs in through the Windows broker or a browser by default and falls back to device code only when it cannot open a browser or someone runs az login --use-device-code.

We only have Microsoft 365 Business Standard. Can we still block it? Conditional Access needs Microsoft Entra ID P1, and Business Standard is not among the plans Microsoft lists as including it. Without it, security defaults are the available control, and they block device code flow for the whole tenant with no exceptions. If you need exceptions for meeting-room devices, you need P1 licensing, for example through Microsoft 365 Business Premium.

Put this into practice

Book a free 30-minute call with a senior engineer about your infrastructure, or check your email security in 30 seconds.

Tags:microsoft-365entra-idphishingidentitym365-securitysecurity

Get articles like this in your inbox

Practical security, infrastructure, and DevOps insights for teams in regulated industries. Sent every two weeks.

Every two weeksUnsubscribe anytimeNo spam, ever

Security and cloud notes from PlatOps Security, LLC, every two weeks. We use your address only to send them. We will email you a link to confirm, and every issue has a one-click unsubscribe. Privacy Policy.

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

Free 30-minute call

Want to Talk This Through?

Book a free 30-minute call, and we'll go through how this applies to your business and what to do first.

No commitment. Video call or phone, whichever you prefer. Run by senior engineers, serving clients since 2014.

What you leave the call with

  • How this applies to your setup
  • What to do first
  • A senior engineer, not a salesperson
Book a free 30-minute call

Prefer it in writing? Request a written review