Device Code Phishing Explained — And the Conditional Access Policy That Blocks It
Multi-factor authentication has dramatically improved Microsoft 365 account security.
But attackers have adapted.
One technique worth understanding is device code phishing.
Unlike traditional phishing, the attacker does not necessarily need to create a fake Microsoft login page or steal the victim's password directly.
Instead, they abuse a legitimate Microsoft authentication workflow.
The user may:
visit Microsoft's genuine sign-in page
enter their real credentials
complete legitimate MFA
see a perfectly valid Microsoft interface
and still authorise an attacker-controlled session.
That is what makes device code phishing dangerous.
Fortunately, Microsoft Entra ID now gives organisations a very direct defence:
block device code flow with Conditional Access unless there is a genuine business requirement for it.
Microsoft explicitly describes device code flow as high risk and recommends blocking it wherever possible.
What Is Device Code Flow?
Device code flow is an authentication method designed for devices or applications that cannot easily display or complete a normal interactive browser sign-in.
Examples can include:
meeting-room devices
digital signage
shared devices
command-line tools
specialist applications
devices without a full keyboard or browser
A legitimate flow typically works like this:
Device requests authentication
↓
Microsoft generates a short code
↓
User opens Microsoft's verification page on another device
↓
User enters the code
↓
User signs in and completes MFA
↓
The original device receives an authentication token
The important detail is this:
The user entering the code does not necessarily have physical control of the device that originally requested it.
That is what attackers exploit.
How Device Code Phishing Works
The attacker starts a device code authentication request on a device or application they control.
Microsoft generates a short code for that session.
The attacker then persuades the victim to enter that code.
The lure could arrive through:
Teams
another messaging platform
a compromised account
telephone/social engineering
The victim may be told:
“Enter this code to open the document.”
or:
“Your account needs to be reconnected.”
The victim follows the instructions and visits Microsoft's genuine verification page.
They then:
1. Enter the attacker's code.
2. Sign into Microsoft.
3. Complete MFA.
4. Approve the authentication.
Microsoft can then issue tokens to the application or device that initiated the flow.
That device belongs to:
the attacker.
The user has effectively completed the attacker's authentication for them.
Why Ordinary MFA May Not Stop It
This is the critical concept.
The attacker may not be bypassing MFA.
MFA can work exactly as designed.
The real user:
knows the password
receives the MFA challenge
approves it
The problem is that they are authorising the wrong authentication transaction.
That means device code phishing can potentially work against accounts protected by conventional methods such as:
Authenticator approvals
number matching
one-time codes
SMS
telephone verification
MFA remains extremely important.
But this attack demonstrates why security cannot rely solely on:
password + MFA prompt.
Authentication context matters too.
Device Code Phishing vs Traditional Phishing
Traditional phishing commonly looks like:
Fake Microsoft page
↓
Victim enters password
↓
Attacker steals credentials
↓
Attacker attempts authentication
Device code phishing looks more like:
Attacker initiates legitimate Microsoft authentication
↓
Microsoft generates device code
↓
Victim is persuaded to enter code
↓
Victim authenticates on real Microsoft service
↓
Attacker-controlled application receives authorised tokens
The fact that the Microsoft page itself is genuine can make the attack much harder for employees to recognise.
The Best Defence: Block Device Code Flow
Microsoft Entra Conditional Access has an Authentication flows condition that allows administrators to specifically target device code flow. Microsoft recommends blocking the flow wherever possible and permitting it only for documented scenarios where it is genuinely required.
For most ordinary Microsoft 365 users, device code authentication simply is not something they need.
That gives organisations a powerful principle:
If a risky authentication route has no business purpose, disable it.
The Conditional Access Policy
For organisations that do not need device code flow, the policy structure is straightforward.
In the Microsoft Entra admin centre:
Entra ID > Conditional Access > Policies > New policy
Use something descriptive such as:
CA – Block Device Code Flow
Users
Include:
All users
Exclude only accounts that have a documented reason to remain outside the policy, including properly managed emergency-access accounts where appropriate.
Microsoft recommends keeping exclusions limited and reviewing them regularly.
Target resources
Include:
All resources
Microsoft's current guidance recommends all resources where practical so that the flow is not merely blocked for one application while remaining available elsewhere.
Conditions
Open:
Authentication flows
Set:
Configure = Yes
Select:
Device code flow
Access controls
Under:
Grant
select:
Block access
Policy state
Start with:
Report-only
Do not move directly into enforcement across a live organisation without first understanding whether anything genuinely depends on the flow.
Why Report-Only Matters
Report-only mode lets Microsoft Entra evaluate the policy without actually blocking authentication.
That gives administrators time to identify:
users relying on device code flow
applications using it
meeting-room devices
command-line tooling
unexpected dependencies
After reviewing normal activity, the policy can move from:
Report-only
to:
On
Microsoft's current guidance specifically recommends this staged approach.
Teams Rooms and Shared Devices Need Special Care
This is one area I would strengthen considerably in the existing article.
Some Microsoft Teams devices may legitimately use device code flow during:
initial registration
reprovisioning
reauthentication
Microsoft now provides dedicated guidance for these deployments. Rather than excluding large groups of ordinary employees, it recommends tightly scoped exceptions for the resource accounts assigned to Teams room or shared devices.
For relevant Teams-device scenarios, Microsoft also documents cases where the Device Registration Service resource needs to be excluded from the blocking policy so device registration continues to work correctly.
This is much safer than:
“Exclude everybody who might use Teams devices.”
The exception should follow the technical dependency.
Not the broadest possible group of people.
Avoid Broad Device-Code Exceptions
Suppose an Azure CLI workflow legitimately needs device code authentication.
The easy solution is:
exclude the entire IT department.
That creates unnecessary exposure.
A better approach is to determine:
exact accounts
exact application
exact technical requirement
whether a modern authentication alternative exists
Microsoft's recommendation is to allow device code flow only for well-documented, secured use cases and move dependencies away from it when practical.
Exceptions should be:
small + documented + monitored + temporary where possible.
Check Sign-In Logs Before Enforcement
Use:
Entra ID > Monitoring & health > Sign-in logs
Device code activity can be identified through Microsoft Entra sign-in information.
For modern protocol-tracked sessions, Microsoft also recommends checking:
Original transfer method
because later sign-ins can retain the original authentication-flow context even when the immediate event does not obviously look like another device code transaction.
That is particularly useful when investigating:
unexpected blocks
approved exceptions
suspicious successful device code authentication
What Should You Monitor After Blocking It?
Do not create the policy and forget about it.
Review:
blocked device-code attempts
successful device-code activity through exceptions
privileged accounts
unusual applications
unexpected locations
emergency-access account activity
Microsoft specifically recommends alerting on unexpected device code use by privileged users, emergency accounts, unfamiliar applications or unexpected locations.
A successful device-code attempt from an ordinary finance user who has no legitimate reason to use the flow deserves investigation.
Security Defaults Now Help Too
Not every organisation has Conditional Access.
Microsoft Entra Security Defaults now includes protection against device code flow.
As of 1 July 2026, new Microsoft Entra tenants using Security Defaults block device code flow automatically. Microsoft also states that organisations needing granular exceptions should use Conditional Access instead.
That makes the distinction simple:
Smaller/simple environments
Security Defaults can provide Microsoft's standard baseline protection.
Organisations requiring exceptions or more control
Use Conditional Access.
Conditional Access requires appropriate Microsoft Entra licensing, such as Entra ID P1 or qualifying Microsoft 365 subscriptions.
Does Phishing-Resistant MFA Still Matter?
Absolutely.
Passkeys, FIDO2 security keys and other phishing-resistant authentication methods provide significantly stronger protection against conventional credential phishing and adversary-in-the-middle attacks.
But the important lesson here is:
do not rely on stronger MFA as an excuse to leave unnecessary risky authentication flows enabled.
A strong Microsoft 365 identity design combines:
phishing-resistant authentication
Conditional Access
managed/compliant devices
risky-flow restrictions
session protection
monitoring
Device code flow is a particularly good example of why layered identity security matters.
User Training Can Be Very Simple
Employees do not need to understand OAuth.
Give them one rule:
Never enter a device code that somebody else sends you unless you deliberately initiated the sign-in on a business device you recognise.
A legitimate process should begin with:
you trying to sign a known device in.
An unsolicited email saying:
“Enter this Microsoft device code”
should immediately be treated as suspicious.
What If Someone Already Fell for It?
Treat it as an account-compromise incident.
Do not merely:
change the password and carry on.
Because the attack can result in issued authentication tokens, investigate and revoke access appropriately.
Microsoft Entra provides mechanisms for revoking refresh tokens and user sessions, while access-token invalidation may depend on the application and Continuous Access Evaluation support.
A practical response should include:
1. Revoke the user's sessions/tokens.
2. Review Entra sign-in activity.
3. Identify the application used in the device-code flow.
4. Review mailbox and Microsoft 365 activity.
5. Check MFA/authentication-method changes.
6. Review suspicious OAuth/app access.
7. Reset credentials where justified.
8. Investigate any data access or messages sent.
9. Block device code flow if it was unnecessarily available.
For a privileged account, escalate the incident accordingly.
Don't Confuse Device Code Flow With Authentication Transfer
Microsoft's Authentication flows Conditional Access condition also covers another mechanism called authentication transfer.
That allows authenticated state to be transferred between devices—for example, from a desktop application to a mobile app using a QR-based flow.
This is separate from device code flow.
An organisation may decide to restrict:
device code flow
authentication transfer
or both
depending on its requirements.
Do not simply select every authentication-flow option without understanding the impact.
A Practical 2026 Policy
For many Microsoft 365 SMEs, I would aim for:
Device code flow
→ Blocked by default
Ordinary employees
→ No exception
Emergency-access accounts
→ carefully controlled exclusion where required by your Conditional Access design
Teams device accounts genuinely requiring the flow
→ tightly scoped exception following Microsoft's Teams guidance
Legacy tools
→ document dependency and migrate away where practical
Policy deployment
→ Report-only first, then enforce
Monitoring
→ review device-code sign-ins and exception use continuously
That is significantly better than leaving the flow available tenant-wide simply because:
“Nothing has gone wrong yet.”
The Key Lesson
Device code phishing works because the attacker abuses a legitimate Microsoft authentication process.
The victim can:
visit the correct Microsoft site
use their correct password
complete genuine MFA
and still authorise an attacker.
The best defence is therefore not trying to make users recognise an increasingly convincing login page.
It is:
remove the authentication path if the business does not need it.
Microsoft's current recommendation is unambiguous:
block device code flow wherever possible.
How Hamilton Group Can Help
Hamilton Group can help businesses review Microsoft Entra and Microsoft 365 authentication controls, including:
device code flow
Conditional Access
report-only policies
Microsoft Entra sign-in logs
Teams device exceptions
emergency-access accounts
phishing-resistant MFA
administrator protection
suspicious authentication investigation
account-compromise response
A strong identity-security strategy should not simply ask:
“Do our users have MFA?”
It should also ask:
“Which authentication routes are still available, and do we genuinely need them?”
Visit hgmssp.com or call 01423 438 953 to discuss Microsoft 365 and identity security.
0 comments
- Be the first to comment.