T09 · Insecure Skill Coding Practices
Warning
- Location
- scripts/setup_and_auth.py:136
- Finding
- OAuth Access and Refresh Tokens Stored in Plaintext by Setup Workflow<![CDATA[ ## Vulnerability Details **File Location**: `scripts/setup_and_auth.py`, lines 136-138 **Vulnerability Type**: Plaintext storage of sensitive OAuth credentials **Risk Level**: Medium ### Vulnerable Code ```python def save_token(token_data: dict): with open(TOKEN_FILE, "w", encoding="utf-8") as f: json.dump(token_data, f, indent=2) ``` ### Technical Analysis The setup workflow serializes the complete Microsoft OAuth token response directly into `scripts/token_store.json`. The response can contain an access token, refresh token, ID token, granted scopes, and expiration metadata. The file is not protected with Windows DPAPI, Windows Credential Manager, an encrypted credential store, or explicitly restrictive filesystem permissions. Because the Skill requests `offline_access`, the stored refresh token may remain useful after the short-lived access token expires. Storing the token inside the Skill directory also increases its exposure to other local tools, agents, backup processes, archive operations, or users that can read that directory. The tokens are legitimately transmitted over HTTPS to official Microsoft endpoints. The vulnerability is their unprotected persistence after authentication, not the OAuth network exchange itself. ### Attack Path 1. The user runs `setup_and_auth.py` and completes Microsoft device-code authentication. 2. Microsoft returns an OAuth response containing an access token and potentially a refresh token. 3. `save_token()` writes the complete response to `scripts/token_store.json` in plaintext. 4. A malicious local process, another agent, an exposed backup, or a user with read access to the Skill directory copies the file. 5. The attacker uses the access token directly or submits the refresh token with the associated client ID to Microsoft’s token endpoint. 6. The attacker accesses Microsoft Graph using the delegated calendar permissions granted to the application. This attack requires local file access or ...[truncated 804 chars]
- Remediation
- <![CDATA[ ## Remediation Suggestions 1. Store OAuth credentials using Windows Credential Manager or protect them with Windows DPAPI. 2. Prefer a supported MSAL token cache configured with platform-specific encryption. 3. Store credential material outside the Skill installation directory. 4. If file storage is unavoidable, create the file with user-only access and explicitly configure a restrictive Windows ACL. 5. Persist only fields required for token renewal instead of the complete token response. 6. Ensure backups, diagnostics, and package archives exclude the token file. 7. Provide documented token-revocation and credential-cleanup procedures. 8. Avoid printing token contents or including the token file in error reports. ]]>
