DEV Community

IAMDevBox
IAMDevBox

Posted on Originally published at iamdevbox.com

OAuth Consent Phishing: How Malicious Apps Pass MFA and How to Shut Them Down in Entra ID

OAuth consent phishing never asks for a password. The attacker registers a multi-tenant application, sends the victim a link to the real login.microsoftonline.com authorize URL, and waits for the user to click Accept. Every step the victim sees is genuine, including MFA, which is why this attack class keeps working against organisations that think they are covered by phishing-resistant authentication. What matters is not who the user is, but what they just authorised an unknown app to do.

This guide covers how the attack works at the protocol level, the Entra ID consent settings that close it, a KQL detection you can deploy today, and the exact commands to clean up after a successful grant. For the related token-theft pattern that abuses RFC 8628 instead of the authorization code flow, see OAuth Device Code Flow Security.

How an illicit consent grant works

The attacker's app is just an ordinary registration with a redirect URI they control. The lure is a standard authorization request:

https://login.microsoftonline.com/common/oauth2/v2.0/authorize
  ?client_id=<attacker-app-id>
  &response_type=code
  &redirect_uri=https://attacker.example.com/callback
  &response_mode=query
  &scope=offline_access%20Mail.Read%20Files.Read.All
  &state=12345
Enter fullscreen mode Exit fullscreen mode
  1. The user opens the link and signs in on the real Microsoft page. MFA, Conditional Access and sign-in risk all evaluate normally and pass.
  2. Microsoft shows a consent prompt listing the requested delegated permissions.
  3. If the tenant allows user consent for those scopes, clicking Accept creates an oauth2PermissionGrant and an enterprise application (service principal) in the victim's tenant.
  4. The attacker's redirect URI receives an authorization code, exchanges it, and holds an access token plus a refresh token (offline_access).

From then on the attacker calls Microsoft Graph as the app. The grant is independent of the user's password and sessions, so a password reset does not remove it. This is the same refresh-token persistence problem seen in MFA bypass attacks, except here Microsoft itself issued the token to the attacker's client at the user's request.

Variants you will see in incident reports:

  • Delegated mail and file access. Mail.Read, Mail.Send, Files.Read.All, offline_access. Used for inbox mining and business email compromise.
  • Lookalike names. App display names such as "Microsoft 365 Security Scan" or "Adobe Sign Review", often with a unverified-publisher banner that users ignore.
  • Compromised verified publisher. A real tenant with a Microsoft Cloud Partner Program verification that has been taken over, which defeats the "only allow verified publishers" shortcut on its own.
  • App-only permissions. Requested through an admin, so the phish targets a privileged user to obtain tenant-wide application permissions.

Close the door: user consent settings

Microsoft documents three user consent settings in Entra ID: do not allow user consent, allow consent only for apps from verified publishers requesting low-impact permissions, or let Microsoft manage your consent settings (the default for new tenants, backed by the microsoft-user-default-recommended policy). Check which one your tenant is on before assuming you are protected.

Read the current assignment with Microsoft Graph PowerShell:

Connect-MgGraph -Scopes "Policy.ReadWrite.Authorization"

(Get-MgPolicyAuthorizationPolicy).DefaultUserRolePermissions.PermissionGrantPoliciesAssigned
Enter fullscreen mode Exit fullscreen mode

If this returns ManagePermissionGrantsForSelf.microsoft-user-default-legacy, users can consent to almost anything that does not require admin consent. Move to a stricter setting.

Option 1: disable user consent entirely

Update-MgPolicyAuthorizationPolicy -DefaultUserRolePermissions @{
  PermissionGrantPoliciesAssigned = @()
}
Enter fullscreen mode Exit fullscreen mode

This is the strongest control and fits regulated tenants. Pair it with the admin consent workflow below, otherwise users hit a dead end and look for workarounds.

Option 2: low-impact permissions from verified publishers only

Update-MgPolicyAuthorizationPolicy -DefaultUserRolePermissions @{
  PermissionGrantPoliciesAssigned = @("ManagePermissionGrantsForSelf.microsoft-user-default-low")
}
Enter fullscreen mode Exit fullscreen mode

Note the weakness: it depends on the verified-publisher signal, and the permission classification (which scopes count as low impact) is something you must review rather than assume. Mail.Read should never be classified low-impact in a tenant that cares about mailbox confidentiality.

Turn on the admin consent workflow

In the Entra admin center go to Enterprise applications > Consent and permissions > Admin consent settings and set Users can request admin consent to apps they are unable to consent to to Yes, then pick reviewers. Users get a request button on the consent prompt instead of a block, and reviewers see the app, publisher and exact scopes before approving. Make sure reviewers know to decline anything requesting offline_access plus mail or file scopes from an unverified publisher.

Risk-based step-up consent

Microsoft's risk-based step-up consent turns a user consent request that Microsoft flags as risky into a requirement for admin consent. It only changes behaviour when user consent is enabled, and the BlockUserConsentForRiskyApps setting is controlled through the Graph PowerShell beta module with the Privileged Role Administrator role. Treat it as a useful extra layer, not a substitute for restricting consent: the flag is advisory and attackers iterate until their app is not flagged.

Detect illicit grants with KQL

Entra ID writes a Consent to application audit event each time a user or admin grants consent. Forward the AuditLogs table to Microsoft Sentinel (or Log Analytics) and run:

AuditLogs
| where TimeGenerated > ago(7d)
| where OperationName == "Consent to application"
| where Result == "success"
| extend Actor = tostring(InitiatedBy.user.userPrincipalName),
         ActorIp = tostring(InitiatedBy.user.ipAddress),
         App = tostring(TargetResources[0].displayName),
         AppId = tostring(TargetResources[0].id)
| extend Scopes = tostring(parse_json(tostring(TargetResources[0].modifiedProperties))[0].newValue)
| where Scopes has_any ("Mail.Read", "Mail.ReadWrite", "Mail.Send", "Files.Read.All", "offline_access")
| project TimeGenerated, Actor, ActorIp, App, AppId, Scopes, CorrelationId
| order by TimeGenerated desc
Enter fullscreen mode Exit fullscreen mode

Property positions in modifiedProperties vary by event shape, so run this once against a known consent in your tenant and adjust the index before turning it into an alert. Elastic's prebuilt rule uses the same event with a new-terms approach (first time a user and application pair is seen in the recent window), which keeps a campaign hitting many users visible because each pair alerts separately.

Good triage pivots:

  • Actor and IP. Did the same IP consent for several users within minutes? That is a campaign.
  • Publisher verification. Unverified publisher plus mail or file scopes is the highest-priority combination.
  • Correlation ID. Join to SigninLogs to see the sign-in that preceded the consent, and to MicrosoftGraphActivityLogs (if enabled) to see what the app did afterwards.

Microsoft's own guidance for investigating suspected grants is to search the audit log in Microsoft Purview for questionable "Consent to application" activities, and to review consent grants in large tenants on a weekly cadence. A scheduled review is cheap insurance.

Inventory what is already granted

Do not wait for an alert. List every delegated grant in the tenant and review it:

Connect-MgGraph -Scopes "DelegatedPermissionGrant.Read.All","Application.Read.All"

Get-MgOauth2PermissionGrant -All |
  Where-Object { $_.Scope -match "Mail|Files|offline_access" } |
  Select-Object Id, ClientId, ConsentType, PrincipalId, Scope
Enter fullscreen mode Exit fullscreen mode

ConsentType of AllPrincipals means an admin granted it for the whole tenant, which deserves the most scrutiny. Principal means a single user consented. Resolve ClientId to the service principal with Get-MgServicePrincipal -ServicePrincipalId <ClientId> and check the publisher, creation date and sign-in activity. Apps nobody on your team can explain are candidates for removal.

Respond: revoke the grant, the app and the sessions

A password reset alone leaves the attacker's refresh token valid. Run all four steps:

Connect-MgGraph -Scopes "DelegatedPermissionGrant.ReadWrite.All","Application.ReadWrite.All","User.RevokeSessions.All"

# 1. Delete the delegated grant(s) for the malicious app
Remove-MgOauth2PermissionGrant -OAuth2PermissionGrantId <grant-id>

# 2. Disable (or delete) the enterprise application
Update-MgServicePrincipal -ServicePrincipalId <sp-id> -AccountEnabled:$false

# 3. Revoke the affected user's refresh tokens and sessions
Revoke-MgUserSignInSession -UserId user@example.com

# 4. Remove any app role assignments the app holds
Get-MgServicePrincipalAppRoleAssignment -ServicePrincipalId <sp-id>
Enter fullscreen mode Exit fullscreen mode

The equivalent REST call for step 1 is DELETE https://graph.microsoft.com/v1.0/oauth2PermissionGrants/{id}. After cleanup, search the mailbox for inbox rules and forwarding the attacker may have created while they had Mail.ReadWrite, and review what the app read through the unified audit log so you can decide on disclosure.

Hardening checklist

Control Setting
User consent Disabled, or low-impact permissions from verified publishers only
Admin consent workflow Enabled with at least two named reviewers
Risk-based step-up consent Left on as an additional layer
Detection Sentinel alert on Consent to application with mail/file scopes
Inventory Weekly review of oauth2PermissionGrants and new enterprise apps
Response runbook Delete grant, disable service principal, revoke sessions, check mailbox rules
App registration Restrict who can register applications and review your own multi-tenant apps

Why this keeps working

Consent phishing succeeds because identity teams spend their effort on authentication strength and treat authorisation as a user decision. Passkeys and number matching do nothing here: the user authenticated correctly and then authorised the wrong party. The durable fix is making consent an administrative decision for anything beyond trivial scopes, and watching the audit log for the exceptions. If your org also exposes OAuth-based integrations to AI agents, the same principle applies to what those agents may be granted; see MCP OAuth 2.1 authentication and the OAuth 2.1 security best practices guide. To inspect the tokens an app receives during a test, use the JWT Decoder.

Top comments (0)