AegisAI Perspectives · 016

How do I protect Microsoft 365 from device code phishing?

Block device code flow with a Conditional Access policy, test it in report-only mode, then turn it on and exclude only Teams devices that need the flow.

How do I protect Microsoft 365 from device code phishing?

Block the device code flow with a Conditional Access policy, test it in report-only mode, then turn it on. The FBI advised a block after a device code phishing kit for Microsoft 365 appeared in April 20264.

AegisAI reads each message for what it is trying to do. A device code lure is trying to get the reader to type a code on a legitimate Microsoft sign-in page13. The attacker started that sign-in, so the user finishes it on the attacker's behalf.

What you can do by the end

  • State why MFA does not stop device code phishing and which Conditional Access control does.
  • Roll out the block in Microsoft's order: inventory, report-only, account exceptions, then On.
  • Run the first hour after a user enters an attacker's code, with token lifetimes known.

Roll out protection from device code phishing in this order

Close the flow for everyone, then reopen it only for named accounts that need it. Microsoft Learn calls device code flow a high-risk authentication method that can be part of a phishing attack10. RFC 8628, the standard behind the flow, warns that it can be started on a device in an attacker's possession26.

The user has 15 minutes from the request to sign in17. Once the code is entered, the attacker reaches Outlook, Teams and OneDrive with no password and no further MFA challenge5. For a campaign that automated the lures with AI, read how a Midnight Blizzard-linked actor automated device code phishing.

  1. Inventory current use.

    In the Entra ID sign-in logs, filter on Authentication protocol = Device code flow and export every account that still signs in this way1612.

  2. Name the real dependencies.

    Audit each result before you write the policy7. Keep exceptions to required business processes, such as Teams devices that sign in with a code6.

  3. Check the licence.

    Users in scope need a Microsoft Entra ID P1 or higher licence14.

  4. Create the block policy.

    In Conditional Access, target all users, set the Authentication flows condition to Device code flow and set the grant to Block access8. Exclude one exception group of named accounts and nothing else.

  5. Start in report-only mode.

    Set Enable policy to Report-only and compare the policy impact with the accounts from step 19.

  6. Turn it On.

    When the report-only results match the inventory, move the Enable policy toggle from Report-only to On.

  7. Bind tokens to the device.

    Enforce Token Protection in Conditional Access so only refresh tokens cryptographically bound to the device are used25.

  8. Keep the log filter running.

    Protocol tracking state carries through later refreshes, so sessions that began with device code flow stay subject to the policy11. Re-run the Authentication protocol filter each week.

How AegisAI handles this

AegisAI agents read sign-ins and mailbox activity for each account, as the account takeover protection page describes1. When behavior stops matching the owner, they raise one explained finding. They weigh impossible travel, new devices, inbox rule changes and suspicious internal sends together per account2. Every finding comes with recommended steps, and your team acts in Entra ID3.

Which settings and signals matter against device code phishing?

Five Conditional Access and Entra ID settings do the work, and two time limits decide how fast you act. The table lists where each one lives and what it changes.

Setting or signalWhere it livesWhat it changesFact
Authentication flows condition: Device code flow, Block accessConditional Access policyBlocks new device code sign-ins for users in scope
Report-only modeEnable policy toggleShows the impact before enforcement
Authentication protocol = Device code flowSign-in logs filterLists the accounts that still use the flow
Exception groupPolicy exclusionsExempts named accounts only, because an exception is account-scoped15
Token ProtectionConditional Access session controlAccepts only refresh tokens bound to the device
Device code lifetimeDevice authorization requestThe user has 15 minutes to sign in
Access token lifetimeEntra ID defaultAccess tokens last 1 hour by default20

What does one device code phishing attempt look like?

A single code typed from a fake meeting invite gives the attacker a session, and the sign-in logs show it as a device code sign-in.

Illustrative example, figures are fictional. A fictional tenant with 400 mailboxes has its block policy in report-only mode during week 1. A finance user receives a Teams meeting invite from an outside address that says to enter a code at the Microsoft device login page to join. The user types the code 6 minutes after the attacker's device requested it, inside the 15 minute window. The sign-in logs show a successful sign-in for the user with Authentication protocol set to Device code flow, from an IP address the user has never used. The Conditional Access tab shows the block policy in report-only with a result of failure, which means it would have blocked the sign-in if it were On. The admin revokes the user's sessions, finds a new inbox rule that moves replies to RSS Subscriptions, deletes it and switches the policy On. A second invite to the same user 2 days later produces a failed sign-in with the block policy listed as the reason.

Does device code phishing bypass MFA?

Yes, in practice, because the user completes MFA on the real Microsoft page for a sign-in the attacker started. The FBI describes Kali365 as a service that obtains Microsoft 365 access tokens and bypasses MFA without intercepting the user's credentials. After that, the attacker needs no password and passes no additional MFA challenge.

A stronger MFA method on the user's side protects the user's own sign-in. It does not change which device receives the tokens, since the device that started the flow can be the attacker's. That is why the FBI and Microsoft both point to blocking the flow.

Token Protection adds a second layer by refusing refresh tokens that are not bound to the device. For the full kit breakdown, read how the Kali365 kit defeated MFA without breaking it.

How do I block device code flow with a Conditional Access policy?

Use one policy that covers all users and blocks the Device code flow authentication flow, with a single exception group. Microsoft recommends getting as close as possible to a unilateral block, and the FBI asks for limited exceptions for required business processes.

Keep three settings fixed. The scope is all users, the condition is Authentication flows with Device code flow selected, and the grant is Block access. Report-only comes first, then On once the impact is confirmed.

Put exclusions in one group so they are visible and countable. Each exception is account-scoped, so add the account that needs the flow, never a whole department. Before you add anyone, check the sign-in logs filtered by authentication protocol for that account.

What should I do if a user already entered a device code an attacker sent?

Revoke the user's sessions first, then look for what the attacker changed. Revoking active sessions immediately invalidates active access from the stolen credentials and stops further actions on the account23.

1 hour is the default life of an access token issued by Entra ID. Apps that use access tokens lose access when that token expires22. In CAE sessions, token lifetime increases to long-lived, up to 28 hours19. Do not wait out a timer in either case.

Work through this order in the first hour. Revoke the user's Entra ID refresh tokens with Revoke sessions in the admin center or Revoke-MgUserSignInSession in PowerShell21. Then check the mailbox for rules that move messages to the Notes, Junk Email or RSS Subscriptions folders24. For where each takeover stage leaves evidence, read how email account takeover works step by step.

Can I block device code flow if I use Teams Rooms or Teams phones?

Yes, with an exception group that holds only the Teams device accounts that sign in with a code. Microsoft Learn has a dedicated page for this setup, and the setup needs Entra ID P1 or higher for the users in scope.

Find those accounts with the sign-in log filter Authentication protocol = Device code flow before rollout. Because an exception is account-scoped, it allows every device code sign-in by that account, from any device. Keep the group to the resource accounts the inventory found, and review it each month.

How to measure it in 30 days

Track three numbers each week, and expect the first one to reach zero once the policy is On.

  • Device code sign-ins outside the exception group per week. Read them in the sign-in logs with Authentication protocol = Device code flow. Any sign-in by a user outside the group means the policy has a gap.
  • Accounts in the exception group. Read the group's member count in Entra ID. Because exceptions are account-scoped, every new member widens what an attacker can use.
  • Time from a user's report to revoked sessions. Read it from the audit log entry for the revocation. Revoking sessions ends active access from stolen credentials, so this time is the length of the attacker's window.

Questions people ask

How long is a device code valid?

From the moment the request is sent, the user has 15 minutes to sign in. An attacker sends the code and asks the user to enter it straight away, so the lure fits inside that window. A short lifetime does not replace the block.

How are admins restricting Microsoft 365 device code authentication with Conditional Access?

Start with an inventory, then a report-only policy that blocks Device code flow for all users. Microsoft recommends getting as close as possible to a unilateral block. Exceptions go into one group of named accounts, because an exception is account-scoped.

What is the fastest way to protect Microsoft 365 from device code phishing?

Filter the sign-in logs for device code flow, create a Conditional Access policy that blocks it for all users, run it in report-only mode, then turn it On. Add an exception group only for accounts the logs show need it.

Does blocking device code flow end sessions that already exist?

Not by itself. Protocol tracking state carries through later refreshes, so those refreshes can meet the policy. Access tokens already issued stay valid until they expire. Revoke the refresh tokens of any account you suspect.

What licence do I need to block device code flow?

Microsoft Learn lists a Microsoft Entra ID P1 or higher licence for the users in scope. Check it before you build the block, since the block is a Conditional Access policy.

Is device code flow ever needed in Microsoft 365?

Yes, for required business processes such as Teams devices that sign in with a code. Microsoft Learn notes the flow can also be used to reach corporate resources on unmanaged devices. Audit existing use before you block it, so real dependencies get an exception.

Sources

  1. FBI IC3 public service announcement PSA260521 on Kali365 device code phishing
  2. Block authentication flows with Conditional Access policy, Microsoft Learn
  3. Authentication flows in Conditional Access policy, Microsoft Learn
  4. Block device code flow while allowing Teams devices, Microsoft Learn
  5. OAuth 2.0 device authorization grant flow, Microsoft identity platform, Microsoft Learn
  6. Continuous access evaluation in Microsoft Entra, Microsoft Learn
  7. Revoke user access in Microsoft Entra ID, Microsoft Learn
  8. Responding to a compromised email account, Microsoft Learn
  9. Protecting tokens in Microsoft Entra ID, Microsoft Learn
  10. RFC 8628, OAuth 2.0 Device Authorization Grant, IETF
  11. Account takeover protection, AegisAI

Recent posts

Every email, investigated.