Skip to main content

πŸš¦πŸ”΄πŸ“œCA - Block Device Code Flow

Device code flow was built for the TV in the corner. Attackers noticed it also works on the human in the corner. This one shuts it off.

🚦Type Conditional AccessπŸ”΄Action Block accessπŸ“œTarget Device code auth flow
reference-build Β· ca-block-device-code-flowGolden Master reference
License tier
Business Premium (Entra ID P1)
Control plane
Entra Conditional Access
Scope
All users, all cloud apps
Reversibility
report-only first, clean-revert

What this policy is about πŸ“œβ€‹

Device code flow exists for the sign-ins that cannot show a browser: a smart TV, a CLI on a headless box, an IoT gadget. It shows a short code and tells you to punch it into microsoft.com/devicelogin on a device that does have a browser, where you authenticate normally. Handy, and completely legitimate. The trouble is that "authenticate this code on your own device" is exactly the sentence a phisher wants you to hear.

This policy blocks the device code authentication flow for everyone, targeting all cloud apps, with a tight exception group for the rare CLI or kiosk that genuinely needs it. If you are not using it on purpose, you should not be reachable through it at all.

πŸ€” Why it bites

The attack needs no fake login page. The phisher starts a device code request against your tenant, sends you the real Microsoft prompt and a real code, and you helpfully authenticate it, MFA included, handing them a live session. There is nothing to spot in the URL because the URL is genuinely Microsoft's.

Why this matters πŸ•΅οΈβ€‹

These are the droids you are looking for, and device code flow is the mind trick that walks them straight past the guard. The victim does everything right, real Microsoft domain, real MFA prompt, real code, and the token still lands in the attacker's hands, because the flow was designed to authorise a session for a device that is not the one you are typing on. Consent phishing campaigns lean on it precisely because every credential and MFA control you own waves it through: the person authenticating is the legitimate user, on their legitimate device, approving a request they did not start.

Blocking the flow removes the trick entirely. The genuine headless scenarios in a typical MKB tenant are close to none, and the ones that exist are known, named, and can sit in the exception group. Everyone else loses an attack path they were never using, which is the cheapest kind of hardening there is.

πŸ› οΈ Configuration​

Where: Entra admin center β†’ Protection β†’ Conditional Access β†’ Policies.

CA policy diagram: all users, device code flow authentication, block access to all cloud apps

SettingValue
Users, includeAll users
Users, excludeπŸ›‘οΈπŸ§‘β€πŸ’Όβ›“οΈπŸ”“πŸš¦Group - Break the Glass solution
πŸ›‘οΈπŸ§‘β€πŸ’ΌπŸ‘ˆπŸ”“πŸš¦Group - Device Code Flow Allowed Users
ConditionsNone configured (the authentication-flow condition scopes this to device code flow)
Target resourcesAll cloud apps
GrantBlock access
SessionNone

The block is scoped to the device code authentication flow itself, so ordinary browser and app sign-ins are untouched: only that one flow is refused. The allowed-users group is the escape hatch for a real headless dependency, and the screenshot shows it holding zero members, which is exactly where you want it.

Roll it out in Report-only first and read the sign-in logs for device-code hits before you enforce. In most tenants there are none, which makes this one of the safest blocks to flip on. If something does show up, identify the CLI or kiosk behind it, decide whether it belongs, and move it to the exception group before you go live.

Caveats βš οΈβ€‹

Legitimate uses exist, so scope the exception carefully. Some admin CLIs and provisioning tools default to device code flow. That is what the allowed-users group is for: named, reviewed, and small. If the list grows, the block is quietly undoing itself.

It closes one door, not the corridor. This stops the device code trick, not consent phishing in general. Pair it with MFA for all users and app-consent governance so the other approval-based paths are covered too.

Report-only tells you the blast radius before you feel it. Because genuine use is rare, most tenants can enforce almost immediately, but confirm that with the logs rather than assuming it. A single overlooked provisioning script breaking at go-live is an avoidable ticket.

License and reversibility. Conditional Access is Entra ID P1, included in Business Premium, and no add-on is needed. Clean-revert: set it to Off and device code flow opens again, which is exactly why a disabled version of this belongs in drift detection rather than left as a silent gap.


If a flow only exists for devices you do not run, the only sign-ins it can serve are the ones you did not start. Turn it off. πŸ“œ