T09 · Insecure Skill Coding Practices
Warning
- Location
- update_viewer.py:331
- Finding
- Excessive Collection and Propagation of the Complete Browser Cookie Set<![CDATA[ ## Vulnerability Details **File Location**: `update_viewer.py:331-344`; related cookie scoping occurs at `bilibili_api.py:49-53`, and full-cookie collection is instructed at `SKILL.md:22-27` **Vulnerability Type**: Excessive credential handling and insufficient least-privilege controls **Risk Level**: Medium ### Complete Code Snippet `update_viewer.py:331-344`: ```python # 获取 cookies cookies_str = os.environ.get('BILIBILI_COOKIES', '') if not cookies_str: print("错误:必须提供 --cookies 参数或设置 BILIBILII_COOKIES 环境变量") print("\n获取方法:") print(" 1. 登录 B站") print(" 2. F12 打开开发者工具 → Network 选项卡") print(" 3. 刷新页面,找到任意请求") print(" 4. 复制 Request Headers 中的 Cookie 值") sys.exit(1) # 解析 cookies all_cookies = parse_cookies(cookies_str) # 创建 API 客户端 api = BilibiliAPI(all_cookies=all_cookies) ``` The corresponding cookie propagation logic appears at `bilibili_api.py:49-53`: ```python # 如果提供了全部 cookies,直接设置 if all_cookies: for key, value in all_cookies.items(): self.session.cookies.set(key, value, domain=".bilibili.com") ``` The documented collection instruction appears at `SKILL.md:22-27`: ```bash export BILIBILI_COOKIES="你的B站cookies" ``` ### Technical Analysis The Skill directs the user to copy the complete Cookie header from an authenticated Bilibili browser session. The application parses every supplied cookie without maintaining an allowlist of required cookie names, then adds all parsed values to a shared `requests.Session`. Each cookie is explicitly scoped to `.bilibili.com`, making it eligible for transmission to applicable Bilibili subdomains. Consequently, sensitive authentication or account-state cookies unrelated to the requested read-only operation may be propagated with API requests. This violates the principle of least privilege. The Skill only needs enough state to query creator information, videos, dynamics, or sear ...[truncated 2038 chars]
- Remediation
- <![CDATA[ ## Remediation Suggestions 1. Define an explicit allowlist containing only cookie names proven necessary for the supported API operations. 2. Discard or reject all unrecognized cookie names rather than loading the complete browser Cookie header. 3. Permit anonymous requests for endpoints that do not require authentication. 4. Request individual cookie values instead of instructing users to copy an entire browser Cookie header. 5. Scope cookies to the narrowest required host rather than `.bilibili.com` whenever the API permits it. 6. Use separate sessions for authenticated and anonymous operations to prevent accidental credential propagation. 7. Never print, log, cache, or include cookie values in exception diagnostics. 8. Document the precise permissions and account effects of every requested credential. 9. Add tests that inspect prepared requests and verify that only approved cookie names are attached to each destination. ]]>
