T09 · Insecure Skill Coding Practices
Warning
- Location
- scripts/geekbi_auth.py:53
- Finding
- Bearer Tokens Are Mirrored Across Multiple Plaintext State Files<![CDATA[ ## Vulnerability Details **File Location**: `scripts/geekbi_auth.py:53-71`, `scripts/geekbi_auth.py:371-383`, and `scripts/geekbi_auth.py:637-652` **Vulnerability Type**: Excessive plaintext credential storage **Risk Level**: Medium ### Vulnerable Code ```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)}") if written == 0: reason = ";".join(errors) or "登录状态目录不可用" raise OSError(reason) ``` ```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) re ...[truncated 2295 chars]
- Remediation
- <![CDATA[ ## Remediation Suggestions 1. Keep only one authentication-state location, preferably the dedicated per-user configuration directory. 2. Do not write bearer tokens into the Skill installation directory or current workspace. 3. Prefer an operating-system credential facility such as Windows Credential Manager, macOS Keychain, or Secret Service on Linux. 4. If file storage remains necessary: - Encrypt token material at rest using a key protected by the operating system. - Apply explicit Windows ACLs in addition to POSIX permission modes. - Reject state files owned by another user or having unsafe permissions. - Avoid following symbolic links when opening or replacing credential files. 5. Rename the configuration namespace from `temu-research-skill` to a unique Shopee-specific identifier. 6. Add a migration routine that removes legacy token copies from the Skill and workspace directories after securely importing or invalidating them. 7. Ensure logout reports deletion failures instead of silently ignoring them, and revoke the server-side token where supported. ]]>
