T09 · Insecure Skill Coding Practices
- Location
scripts/auth.py:27- Finding
OAuth Token Cache Is Stored Without Explicit Owner-Only Permissions
- Content
View full analysis
Vulnerability Details
File Location:
scripts/auth.py, lines 27-29 and 41-44
Vulnerability Type: Insecure storage of reusable OAuth credentials
Risk Level: MediumVulnerable Code
python def save_config(cfg): os.makedirs(TOKEN_DIR, exist_ok=True) with open(CONFIG_FILE, "w") as f: json.dump(cfg, f, indent=2)python def save_cache(cache): os.makedirs(TOKEN_DIR, exist_ok=True) if cache.has_state_changed: open(TOKEN_CACHE, "w").write(cache.serialize())Technical Analysis
The serialized MSAL token cache can contain access tokens, refresh tokens, account identifiers, and related authentication state. The application creates
~/.teams-delegateand writestoken_cache.binwithout explicitly setting owner-only permissions.Consequently, the resulting permissions depend on the user's current
umaskand any pre-existing directory or file permissions. In a permissively configured multi-user environment, another local account may be able to read the token cache. The implementation also writes the cache directly rather than using an atomic replacement, increasing the possibility of partial writes or interactions with an unexpectedly pre-created file.The network transmission of bearer tokens to Microsoft authentication and Graph endpoints is necessary for the declared Teams functionality. The vulnerability is instead the insufficient protection of the reusable credentials at rest.
Attack Path
- The victim authenticates through the device-code flow.
- MSAL obtains OAuth tokens with Teams chat and other Microsoft Graph permissions.
save_cache()serializes the authentication state to~/.teams-delegate/token_cache.bin.- The file inherits permissions determined by the environment rather than enforced mode
0600. - A local attacker reads the cache when filesystem permissions permit it.
- The attacker imports or otherwise reuses the cached OA ...[truncated 770 chars]
- Remediation
View remediation
Remediation Suggestions
- Create
~/.teams-delegatewith mode0700and verify that it is owned by the current user. - Create the token cache with mode
0600, independent of the ambientumask. - Reject symbolic links and files owned by another user before reading or writing authentication state.
- Write updates to an owner-only temporary file in the same directory, flush and synchronize it, and atomically replace the cache.
- Prefer an operating-system credential store or encrypted secret-storage facility instead of a plaintext serialized cache where supported.
- Correct the documentation mismatch: the reference says
token.json, while the implementation storestoken_cache.bin. - Revoke existing sessions and require reauthentication if insecure cache permissions are detected.
Example hardening should use low-level file creation with
os.open(..., os.O_CREAT | os.O_WRONLY | os.O_TRUNC, 0o600)or an equivalent secure credential-storage API.- Create
