T09 · Insecure Skill Coding Practices
Error
- Location
- scripts/request/web/xhs_session.py:199
- Finding
- Authentication Cookie Exposed in Application Logs<![CDATA[ ## Vulnerability Details **File Location**: `scripts/request/web/xhs_session.py`, lines 199-200 and 242-270 **Vulnerability Type**: Sensitive authentication data exposure through logging **Risk Level**: High ### Vulnerable Code ```python cookies_dict = {cookie.key: cookie.value for cookie in self._session.cookie_jar} web_session = cookies_dict.get('web_session') ``` The credential is subsequently included verbatim in multiple log messages: ```python if "禁言" in msg_lower or "被禁言" in msg_lower: logger.warning(f"禁言 | {web_session} | {res_msg} | {logger_info}") raise session_exceptions.MutedError(res_msg) elif "登录已过期" in res_text_lower or "登录超时" in msg_lower: logger.warning(f"掉线 | {web_session} | web_session 登录超时 | {logger_info}") raise session_exceptions.LoginTimeOut(res_msg) elif "删除" in res_text_lower: logger.warning(f"笔记/评论被删除 | {logger_info}") raise session_exceptions.TaskDeleteError(res_msg) elif "无权限访问" in msg_lower: logger.warning(f"过期 | {web_session} | web_session 没有权限访问 | {logger_info}") raise session_exceptions.PermissionError(res_msg) elif "违规情形" in msg_lower or "被封号" in msg_lower or "封号" in msg_lower: logger.warning(f"封号 | {web_session} | {res_msg} | {logger_info}") raise session_exceptions.BannedError(res_msg) elif "用户已关闭评论艾特" in msg_lower: logger.warning(f"用户已关闭评论艾特 | {logger_info}") raise session_exceptions.UserCloseCommentAtError(res_msg) elif "对方设置" in msg_lower or "无法发布评论" in msg_lower: logger.warning(f"对方设置你无法评论 | {logger_info}") raise session_exceptions.CantCommentError(res_msg) elif "blockedps" in res_text_lower: logger.warning(f"封号 | {web_session} | blockedPs | {logger_info}") raise session_exceptions.BannedError(res_msg) ``` ### Technical Analysis The `web_session` value is an authentication credential supplied by the user and stored in the HTTP cookie jar. Several routine error-handling branches interpolate the complete credential into Loguru messages. Lo ...[truncated 1694 chars]
- Remediation
- <![CDATA[ ## Remediation Suggestions 1. Remove `web_session` from every log message. Log only the error class, response status, endpoint, and a non-sensitive request identifier. 2. If correlation is essential, derive a short one-way fingerprint using a dedicated keyed hash. Never log a raw or reversibly encoded credential. 3. Add a centralized logging filter that redacts cookie names such as `web_session`, `a1`, `webId`, and authorization-related headers. 4. Avoid placing complete request headers, cookies, or response objects in exception logs. 5. Define and enforce short retention periods and restrictive access controls for existing logs. 6. Rotate or invalidate credentials that may already have appeared in logs. 7. Add automated tests that inject sentinel credentials and verify that they never appear in captured logging output. ]]>
