T05 · Unauthorized Access and Privilege Escalation
- Location
secretary_engine.py:12- Finding
Excessive Microsoft Graph Delegated Permissions
- Content
View full analysis
Vulnerability Details
File Location:
secretary_engine.py:12-18; supporting documentation atSKILL.md:22-23
Vulnerability Type: Excessive OAuth permissions and violation of least privilege
Risk Level: MediumComplete Vulnerable Code Snippet:
python REQUIRED_SCOPES = [ 'User.Read', 'Mail.ReadWrite', 'Calendars.ReadWrite', 'Files.ReadWrite', 'ChatMessage.Send' ]The corresponding setup instructions explicitly request the same broad write permissions:
markdown 2. **Permissions**: Grant Delegated `Mail.ReadWrite`, `Calendars.ReadWrite`, `Files.ReadWrite`, and `ChatMessage.Send`.Technical Analysis
The application requests delegated
Calendars.ReadWriteandFiles.ReadWritepermissions even though the implemented calendar and Drive operations are read-only:- Calendar functionality calls
me/calendar/getScheduleto retrieve availability. - Drive functionality lists root items and returns their names.
- No implemented operation creates, modifies, moves, or deletes calendar or Drive content.
Consequently, the OAuth token has broader authority than the legitimate application behavior requires. The
User.Readscope is also requested by the implementation but is not identified in the documented permission list.Because this is a public-client application, the resulting delegated token is stored locally in
token_cache.bin. Any party that compromises the host, token cache, or running process may be able to exercise all permissions represented by the token rather than being limited to the operations exposed by this script.Attack Path
- A user registers the application and grants the delegated scopes specified by the project.
- The application completes interactive authentication and obtains a token containing calendar and file write permissions.
- MSAL serializes the authentication state into the local token cache.
- An attacker comp ...[truncated 1073 chars]
- Calendar functionality calls
- Remediation
View remediation
Remediation Suggestions
- Replace
Calendars.ReadWritewith the narrowest delegated permission sufficient for thegetScheduleoperation. - Replace
Files.ReadWritewith the narrowest read-only permission sufficient to list the user's Drive item metadata. - Retain
Mail.ReadWriteonly if assigning theUrgentcategory remains a required feature. - Retain only the minimum Teams permission needed to post channel messages.
- Verify whether
User.Readis required by the authentication flow or implemented features; remove it if unnecessary. - Keep
SKILL.mdsynchronized with the exact runtime scope list so users can make informed consent decisions. - After reducing the scopes, revoke existing user consent and cached refresh tokens, then require reauthentication so previously issued broad tokens cannot continue to be used.
- Add automated tests or policy checks that compare each Graph endpoint against an approved minimum-scope allowlist.
- Replace
