T05 · Unauthorized Access and Privilege Escalation
Warning
- Location
- secretary_engine.py:12
- Finding
- Excessive Microsoft Graph Delegated Permissions## Vulnerability Details **File Location**: `secretary_engine.py:12-18`; supporting documentation at `SKILL.md:22-23` **Vulnerability Type**: Excessive OAuth permissions and violation of least privilege **Risk Level**: Medium **Complete 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.ReadWrite` and `Files.ReadWrite` permissions even though the implemented calendar and Drive operations are read-only: - Calendar functionality calls `me/calendar/getSchedule` to 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.Read` scope 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 1. A user registers the application and grants the delegated scopes specified by the project. 2. The application completes interactive authentication and obtains a token containing calendar and file write permissions. 3. MSAL serializes the authentication state into the local token cache. 4. An attacker comp ...[truncated 1073 chars]
- Remediation
- ## Remediation Suggestions 1. Replace `Calendars.ReadWrite` with the narrowest delegated permission sufficient for the `getSchedule` operation. 2. Replace `Files.ReadWrite` with the narrowest read-only permission sufficient to list the user's Drive item metadata. 3. Retain `Mail.ReadWrite` only if assigning the `Urgent` category remains a required feature. 4. Retain only the minimum Teams permission needed to post channel messages. 5. Verify whether `User.Read` is required by the authentication flow or implemented features; remove it if unnecessary. 6. Keep `SKILL.md` synchronized with the exact runtime scope list so users can make informed consent decisions. 7. 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. 8. Add automated tests or policy checks that compare each Graph endpoint against an approved minimum-scope allowlist.
