T09 · Insecure Skill Coding Practices
Warning
- Location
- scripts/geekbi_auth.py:60
- Finding
- Bearer tokens are replicated into unnecessary Skill and workspace directories<![CDATA[ ## Vulnerability Details **File Location**: `scripts/geekbi_auth.py:60-75`, `scripts/geekbi_auth.py:372-384`, and `scripts/geekbi_auth.py:637-650` **Vulnerability Type**: Excessive credential storage and insecure secret distribution **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 ...[truncated 2744 chars]
- Remediation
- <![CDATA[ ## Remediation Suggestions 1. Store authentication state only in a dedicated user configuration or credential location. 2. Remove `_skill_state_path()` and `_workspace_state_path()` from the credential-store candidates. 3. Replace the unrelated `temu-research-skill` namespace with an Ozon-specific application namespace. 4. Prefer an operating-system credential manager or keychain for the bearer token; keep only non-sensitive metadata in JSON. 5. If file storage is unavoidable: - Create the directory with user-only permissions. - Refuse storage when secure permissions cannot be guaranteed. - Avoid silently ignoring permission-hardening failures. - Ensure backups and synchronization tools exclude the credential file. 6. Add a migration routine that: - Reads any existing token from legacy locations. - Writes it to the secure canonical store. - Securely removes all legacy copies. 7. Document token revocation and provide a command that clears every historical storage location. 8. Add tests confirming that successful authentication creates no state file under the project, Skill installation, or current working directory. ]]>
