T09 · Insecure Skill Coding Practices
Warning
- Location
- scripts/geekbi_auth.py:69
- Finding
- Bearer Tokens Are Replicated Across Multiple Filesystem Locations<![CDATA[ ## Vulnerability Details **File Location**: `scripts/geekbi_auth.py:69-90`, `scripts/geekbi_auth.py:371-380`, `scripts/geekbi_auth.py:631-648` **Vulnerability Type**: Excessive replication of plaintext authentication tokens **Risk Level**: Medium ### Complete Code Snippet ```python def _user_config_state_path(): return _absolute_path( user_config_path("GeekBI", appauthor=False, ensure_exists=True) / "temu-research-skill" / AUTH_FILE_NAME ) def _skill_state_path(): return _absolute_path(Path(__file__).parent.parent / AUTH_STATE_DIR / AUTH_FILE_NAME) def _workspace_state_path(): return _absolute_path(Path(os.getcwd()) / AUTH_STATE_DIR / AUTH_FILE_NAME) def _resolve_stores(): candidates = ( ResolvedStore(_user_config_state_path(), "user-config-directory"), ResolvedStore(_skill_state_path(), "skill-directory"), ResolvedStore(_workspace_state_path(), "working-directory"), ) ``` ```python def _write_state_files(stores, payload): normalized = _normalize_state(payload) errors = [] written = 0 for store in stores: try: _write_state_file(store, normalized) written += 1 except OSError as error: errors.append(f"{store.kind}: {_storage_probe_reason(error)}") ``` ```python def save_token(latest): latest_server = latest["servers"].get(server_key) if not isinstance(latest_server, dict): return False, False latest_pending = latest_server.get("pending") if not isinstance(latest_pending, dict): return False, False if latest_pending.get("deviceCode") != pending.get("deviceCode"): return False, False _remove_access_token(latest_server) latest_server["accessToken"] = access_token latest_server["accessTokenExpiresAt"] = now + max(0, expires_in - 30) latest_server.pop("pending", None) return True, True return _update_state(save_token) ``` ### Technical Analysis ...[truncated 2558 chars]
- Remediation
- <![CDATA[ ## Remediation Suggestions 1. Store authentication state only in the platform-specific user configuration directory. 2. Prefer an operating-system credential manager, such as Keychain, Credential Manager, or Secret Service, for the bearer token. 3. Remove `_skill_state_path()` and `_workspace_state_path()` from credential-store candidates. 4. Do not fall back to a less protected workspace when the secure store is unavailable. Fail closed and provide a clear setup error instead. 5. Retain atomic writes and restrictive permissions for non-secret metadata. 6. On POSIX systems, verify the final file owner and mode after replacement rather than silently ignoring permission-setting failures. 7. Provide migration logic that deletes legacy mirrored token files after moving authentication state into the protected store. 8. Document token lifetime, revocation behavior, and a reliable command for clearing all legacy copies. ]]>
