T09 · Insecure Skill Coding Practices
- Location
scripts/collectors/bilibili.py:265- Finding
Bilibili session cookies exposed in subprocess command-line arguments
- Content
View full analysis
Vulnerability Details
File Location:
scripts/collectors/bilibili.py:265-284
Vulnerability Type: Plaintext credential exposure through process arguments
Risk Level: High
Classification: T09: Insecure Skill Coding PracticesVulnerable Code
python def _curl(self, url: str, referer: str) -> str: """Use curl to obtain the response body.""" self._throttle() cookie = "; ".join(f"{k}={v}" for k, v in self.cookies.items()) cmd = [ "curl", "-sS", "--compressed", "--max-time", str(self.timeout), "-A", UA, "-H", f"Referer: {referer}", "-H", "Accept: application/json, text/plain, */*", "-H", "Accept-Language: zh-CN,zh;q=0.9", "-H", "Origin: https://space.bilibili.com", "-H", "Sec-Fetch-Dest: empty", "-H", "Sec-Fetch-Mode: cors", "-H", "Sec-Fetch-Site: cross-site", ] if cookie: cmd += ["-b", cookie] cmd.append(url) try: proc = subprocess.run( cmd, capture_output=True, text=True, timeout=self.timeout + 10 )Technical Analysis
The collector converts all user-authorized Bilibili cookies into a plaintext HTTP cookie string and supplies that string to
curlusing the-bcommand-line option. Although the subprocess is launched without a shell, which mitigates shell injection, sensitive arguments can still be exposed through operating-system process inspection, audit infrastructure, endpoint monitoring, debugging tools, or crash diagnostics.This behavior also conflicts with the security declaration in
SKILL.md, which states that cookies do not enter command-line arguments. The network request itself is necessary for authenticated collection, but placing the credential inargvis not necessary and exceeds the minimum safe exposure required for that operation.Attack Path
- A user explicitly supplies an authorized ...[truncated 1242 chars]
- Remediation
View remediation
Remediation Suggestions
- Replace the
curlsubprocess with an in-process HTTP client so cookies can remain in process memory and be attached directly to request headers. - If
curlmust be retained, provide sensitive configuration through a protected file descriptor or a temporary configuration file rather than throughargv. - Create any temporary credential file with mode
0600, reject symlinks and ownership mismatches, and remove it immediately after the request. - Avoid placing credentials in environment variables because those may also be inspectable or captured by diagnostics.
- Add an automated test that launches the Bilibili transport with a sentinel cookie and verifies that the sentinel does not appear in the subprocess argument vector, logs, exceptions, or artifacts.
- Update the implementation so it conforms to the stated
SKILL.mdguarantee that cookies never enter command-line arguments. - Recommend session revocation and cookie rotation if the affected collector has already been used on a shared or monitored host.
- Replace the
