Why This Matters Now
Recent high-profile data breaches have highlighted the critical importance of properly configuring OAuth permissions in Microsoft Entra ID. Attackers are increasingly exploiting misconfigured OAuth clients to gain unauthorized access to corporate email and other sensitive resources. The recent Petri IT Knowledgebase article underscores the urgency of addressing this issue, as improperly scoped permissions can provide attackers with stealthy access to corporate data.
Understanding OAuth Permissions in Microsoft Entra ID
OAuth permissions in Microsoft Entra ID allow applications to request specific levels of access to resources within an organization’s Azure Active Directory. These permissions are categorized into two types:
- Delegated Permissions: Allow an app to act on behalf of a signed-in user.
- Application Permissions: Allow an app to act as itself, without a signed-in user.
Delegated Permissions
Delegated permissions are used when an application needs to perform actions on behalf of a user. For example, an email client might request delegated permissions to read the user’s emails.
Example: Delegated Permission Request
{
"resource": "https://graph.microsoft.com",
"scope": "Mail.Read",
"response_type": "code",
"client_id": "YOUR_CLIENT_ID",
"redirect_uri": "https://yourapp.com/callback",
"state": "12345"
}
Application Permissions
Application permissions are used when an application needs to perform actions as itself, independent of any user. For example, a backup service might request application permissions to read all users’ emails.
Example: Application Permission Request
{
"resource": "https://graph.microsoft.com",
"scope": "Mail.Read.All",
"response_type": "code",
"client_id": "YOUR_CLIENT_ID",
"redirect_uri": "https://yourapp.com/callback",
"state": "12345"
}
Common Pitfalls in Configuring OAuth Permissions
Misconfigurations in OAuth permissions can lead to significant security vulnerabilities. Here are some common pitfalls to avoid:
Over-Scoping Permissions
Granting more permissions than necessary increases the attack surface. Always follow the principle of least privilege.
Wrong Way: Over-Scoping
{
"scope": "User.Read.All Mail.ReadWrite.All Contacts.ReadWrite.All"
}
Right Way: Least Privilege
{
"scope": "Mail.Read"
}
Hardcoding Credentials
Storing OAuth credentials in source code or unsecured locations can lead to exposure.
Wrong Way: Hardcoding Credentials
string clientId = "YOUR_CLIENT_ID";
string clientSecret = "YOUR_CLIENT_SECRET";
Right Way: Secure Storage
string clientId = Environment.GetEnvironmentVariable("CLIENT_ID");
string clientSecret = Environment.GetEnvironmentVariable("CLIENT_SECRET");
Inadequate Monitoring
Failing to monitor OAuth activity can allow attackers to maintain persistent access.
Example: Monitoring OAuth Activity
Get-AzureADServicePrincipalSignInActivity -ObjectId YOUR_SERVICE_PRINCIPAL_ID
🎯 Key Takeaways
- Avoid over-scoping permissions to reduce the attack surface.
- Store OAuth credentials securely to prevent exposure.
- Monitor OAuth activity regularly to detect suspicious behavior.
Securing OAuth Permissions in Microsoft Entra ID
Properly securing OAuth permissions involves several best practices. Here’s how to do it right:
Register Applications Correctly
When registering applications in Microsoft Entra ID, ensure that you configure permissions carefully.
Example: Registering an Application
- Go to the Azure portal.
- Navigate to Azure Active Directory > App registrations.
- Click “New registration”.
- Configure the application with the necessary permissions.
📋 Quick Reference
- `Register an application` - Navigate to Azure portal > Azure Active Directory > App registrations. - `Add permissions` - Configure the required permissions for the application.Use Conditional Access Policies
Conditional access policies can enforce additional controls on OAuth permissions.
Example: Creating a Conditional Access Policy
- Go to the Azure portal.
- Navigate to Azure Active Directory > Conditional Access.
- Click “New policy”.
- Define the conditions and grant/deny access based on those conditions.
Implement Least Privilege
Always grant the minimum necessary permissions to applications.
Example: Least Privilege Configuration
# Grant only necessary permissions
New-AzureADAppPermission -ObjectId YOUR_APP_OBJECT_ID -PermissionId READ_MAIL_PERMISSION_ID
Rotate Credentials Regularly
Regularly rotating OAuth credentials reduces the risk of long-term exposure.
Example: Rotating Client Secrets
# Create a new client secret
New-AzureADApplicationPasswordCredential -ObjectId YOUR_APP_OBJECT_ID -CustomKeyIdentifier "NewSecret" -EndDate (Get-Date).AddYears(1)
🎯 Key Takeaways
- Register applications correctly and configure permissions carefully.
- Use conditional access policies to enforce additional security controls.
- Implement least privilege to minimize the attack surface.
- Rotate credentials regularly to reduce exposure risk.
Real-World Scenarios and Case Studies
Understanding how OAuth permissions can be exploited is crucial for implementing effective security measures. Here are some real-world scenarios:
Scenario: Unauthorized Access via Over-Scoped Permissions
An attacker gains access to an application with over-scoped permissions and uses it to read all users’ emails.
Mitigation: Least Privilege
Ensure that the application has only the necessary permissions to read specific user emails.
Scenario: Credential Exposure via Hardcoding
An attacker discovers hardcoded OAuth credentials in the application’s source code and uses them to access corporate email.
Mitigation: Secure Storage
Store OAuth credentials in secure vaults or environment variables to prevent exposure.
Scenario: Persistent Access via Unmonitored Activity
An attacker maintains persistent access to corporate email by continuously using stolen OAuth credentials.
Mitigation: Regular Monitoring
Regularly monitor OAuth activity to detect and respond to suspicious behavior.
Attacker discovers over-scoped permissions in application.
Attacker gains access to corporate email.
Organization implements least privilege and monitoring.
Conclusion
Properly configuring OAuth permissions in Microsoft Entra ID is crucial for maintaining the security of corporate email and other sensitive resources. By following best practices such as least privilege, secure credential storage, and regular monitoring, you can significantly reduce the risk of unauthorized access. Stay vigilant and proactive in securing your applications.
- Review and scope OAuth permissions to the minimum necessary.
- Store OAuth credentials securely.
- Implement conditional access policies.
- Rotate credentials regularly.
- Monitor OAuth activity for suspicious behavior.

