How to Block Device Code Flow in Entra ID to Stop Phishing

Device code phishing is an attack I see often. The victim signs in on the real Microsoft sign-in page, so the attacker needs no fake login page. The victim completes the sign-in on a real page, and the attacker receives the tokens. Few organizations need the feature that makes this possible, and a single Conditional Access policy blocks it.

You can check whether you use device code flow, block it with Conditional Access, and add the exceptions that Teams devices and some tools need.

What device code flow is

Device code flow lets people sign in to devices that have no browser or rich input, such as shared devices, digital signage, smart TVs, Microsoft Teams Room devices, IoT devices, and printers. The device shows a code. The user opens a sign-in page on another device, enters the code, and signs in. The token goes back to the original device.

Microsoft calls device code flow a high-risk authentication method that can be part of a phishing attack or used to reach corporate resources on unmanaged devices. The Microsoft-managed Conditional Access policy for it states that few customers use device code flow, while attackers use it often.

How the attack works

Microsoft Threat Intelligence described a campaign by the actor Storm-2372 in February 2025. The campaign had been active since August 2024. The attack runs in five steps:

  1. The attacker starts a legitimate device code request with Microsoft’s own sign-in flow and receives a code.
  2. The attacker sends the target a lure. Microsoft saw fake messaging experiences that resembled WhatsApp, Signal, and Microsoft Teams, and emailed invitations to online meetings.
  3. The lure asks the target to enter the code on a genuine Microsoft sign-in page.
  4. The target signs in. The attacker receives the access and refresh tokens, which give access without the target’s password.
  5. The attacker uses the session to search the mailbox with Microsoft Graph for sensitive keywords, exfiltrate matching mail, and send further phishing from the compromised account to other users in the organization.

Because the sign-in page is real, users have a hard time recognizing the attack. Microsoft later reported that the actor used the Microsoft Authentication Broker client ID to register an attacker-controlled device in Entra ID and acquire a Primary Refresh Token. Microsoft’s guidance for this attack starts with blocking device code flow wherever possible and allowing it only through Conditional Access policies.

Step 1: Check whether you use device code flow

Before you block it, find out what depends on it. Microsoft recommends auditing existing use first and allowing device code flow only in well documented and secured use cases.

  1. Open the Microsoft Entra admin center and go to Entra ID > Monitoring & health > Sign-in logs.
  2. Add the filter Authentication protocol and select Device code.
  3. For each result, note the user, the app, the location, and who owns the dependency.
  4. Also look at the Original transfer method property of sign-ins in the Activity details. A session that started with device code flow stays tracked on later token refreshes, even when the current sign-in does not show device code flow as the protocol.

Typical legitimate users are Microsoft Teams devices and command-line or developer tools such as Azure CLI. If the list is empty, you can block device code flow for everyone.

Step 2: Create the Conditional Access policy

You need Microsoft Entra ID P1 or higher for Conditional Access and at least the Conditional Access Administrator role.

  1. Go to Entra ID > Conditional Access > Policies and select New policy. Give it a clear name, for example “Block device code flow”.
  2. Under Assignments > Users or workload identities, include All users. Under Exclude, select your emergency access (break-glass) accounts and any approved exception groups. Audit this exclusion list on a schedule.
  3. Under Target resources, include All resources (formerly ‘All cloud apps’).
  4. Under Conditions > Authentication flows, set Configure to Yes, select Device code flow, and select Done.
  5. Under Access controls > Grant, select Block access.
  6. Set Enable policy to Report-only and select Create.

Review the results in report-only mode and in the sign-in logs. When nothing legitimate would break, change Enable policy from Report-only to On.

A Microsoft-managed policy may already exist

Microsoft deploys a Conditional Access policy named Block device code flow to eligible tenants, based on licensing. It appears in the policy list with Microsoft in the Created by column, in a Report-only state. Microsoft turns on these policies no less than 30 days after they appear in your tenant if you leave them in report-only mode, and it announces the change by email and in the Message center two weeks ahead. You can turn the policy on sooner, exclude users, or set it to Off to opt out. You cannot rename or delete it, but you can duplicate it when you need other changes.

Check your policy list. If the managed policy exists, review its report-only results and turn it on yourself, with your exceptions already in place, before Microsoft does it for you.

Step 3: Handle the exceptions

Microsoft Teams devices

Some Teams devices use device code flow for first-time sign-in, reprovisioning, and some reauthentication scenarios, such as password changes. Microsoft’s guidance for Teams devices uses a default-block policy with two layered exceptions:

  • A persistent security group that contains only the Teams device resource accounts that need device code flow. Exclude this group in the policy. Teams resource accounts that use passwordless authentication need device code flow only at initial provisioning, but keep them in the group so that reprovisioning and recovery are not blocked.
  • An exclusion for the Device Registration Service resource, under Target resources > Exclude. Without it, device registration through device code flow is blocked when the policy targets all resources.

An exception is account-scoped. An excluded account can use device code flow for any app in scope of the policy, so keep the group small, monitored, and owner-approved. Microsoft describes the full process in Restrict device code flow for Microsoft Teams devices with Conditional Access.

Other tools and scenarios

  • Move scenarios to safer authentication where possible. Use browser-based or brokered sign-in for users, and managed identities or workload identity federation for automation.
  • Create exception groups only for approved dependencies, with an owner and a review date. Do not add broad user groups. A broad exception allows device code flow beyond the intended tool.
  • Combine device code flow with other conditions when you must allow it. For example, for Android conference room devices, block device code flow everywhere except for Android devices in a specific network location.

After you turn the policy on

  • Blocked sign-ins show in the sign-in logs. Select the sign-in, open the Conditional Access tab, and select the policy to see which authentication flow matched.
  • A session that started with device code flow stays protocol tracked. When the policy targets all apps, the next token refresh can fail with error AADSTS530036. This block is expected behavior. Affected users sign in again with a different method.
  • Keep monitoring. Alert on unexpected device code flow by privileged users, emergency access accounts, unfamiliar apps, or unexpected locations, and review exception groups on a schedule.

Other controls against this attack

Blocking device code flow removes the attack path. Microsoft also recommends these controls against device code phishing:

  • Require multifactor authentication and use phishing-resistant methods where you can. See Go Passwordless with Microsoft Authenticator and the Entra ID migration checklist for SMS and voice MFA.
  • Block legacy authentication.
  • Use sign-in risk policies to block or require MFA for risky sign-ins.
  • Restrict which users can register or join devices in Microsoft Entra ID.
  • Train users to check which app a sign-in prompt names before they enter a code.
  • When you suspect a compromise, revoke the user’s refresh tokens and require the user to sign in again.

Questions or feedback? Leave a comment below.

Leave a Reply

Your email address will not be published. Required fields are marked *