T09 · Insecure Skill Coding Practices
- Location
src/auth.py:202- Finding
Full-session cookies may be transmitted to insufficiently constrained destinations
- Content
View full analysis
Vulnerability Details
File Location:
src/auth.py:202-207
Related Sinks:src/subtitle.py:158-163,src/publisher.py:585-613
Vulnerability Type: Cross-domain credential exposure and excessive credential propagation
Risk Level: HighVulnerable Code
src/auth.py:202-207creates a reusable client with broadly configured authentication cookies and automatic redirect following:python return httpx.AsyncClient( headers=self.get_headers(), cookies=self.cookies, timeout=30.0, follow_redirects=True, )src/subtitle.py:158-163uses that authenticated client to request a URL obtained from an API response without validating its hostname:python sub_url = target_sub["url"] if sub_url.startswith("//"): sub_url = "https:" + sub_url async with self._get_client() as client: resp = await client.get(sub_url) sub_data = resp.json()src/publisher.py:585-613also uses the authenticated client for a separate upload CDN:python upload_base = f"https://upos-sz-upcdnbda2.bilivideo.com/{upos_key}" async with self._get_client() as client: # Fetch upload ID resp = await client.post( upload_base, params={ "uploads": "", "output": "json", }, headers={"X-Upos-Auth": auth} if auth else {}, ) try: init_data = resp.json() upload_id = init_data.get("upload_id", "") except Exception: return {"success": False, "message": "Failed to initialize upload"} # Upload chunks with open(file_path, "rb") as f: for chunk_idx in range(chunk_count): chunk_data = f.read(chunk_size) start = chunk_idx * chunk_size end = min(start + len(chunk_data), file_size) async with self._get_client() as client: resp = await client.put( upload_base,Technical Analysis
...[truncated 3705 chars]
- Remediation
View remediation
Remediation Suggestions
-
Use separate clients by trust boundary.
- Use an authenticated API client only for exact Bilibili API endpoints that require session cookies.
- Use an unauthenticated client for subtitle documents, media streams, covers, and public APIs.
- Use a dedicated upload client containing only
X-Upos-Authfor the upload CDN.
-
Domain-scope every cookie explicitly.
- Scope account cookies to the minimum required Bilibili hostname and path.
- Do not create session cookies with an empty or unrestricted domain.
- Avoid sending
bili_jctas a cookie where only a request parameter or body field is required.
-
Validate remote destinations before each request.
- Require
https. - Compare normalized hostnames against a strict allowlist of exact expected domains.
- Reject embedded credentials, nonstandard schemes, unexpected ports, IP literals, and malformed URLs.
- Do not rely on substring or suffix-only hostname checks.
- Require
-
Constrain redirects.
- Disable
follow_redirectsfor authenticated clients. - If redirects are operationally required, validate every redirect target and strip cookies and authorization data whenever the origin changes.
- Disable
-
Harden subtitle retrieval.
- Resolve protocol-relative subtitle URLs only after hostname validation.
- Fetch subtitle JSON with a cookie-free client.
- Apply response-size limits, timeouts, and content-type validation.
-
Harden upload requests.
- Send upload chunks through a dedicated client without
SESSDATA,bili_jct, orbuvid3. - Authenticate the CDN request solely with the short-lived upload authorization returned by the pre-upload endpoint.
- Validate the returned upload URI and key before constructing the CDN destination.
- Send upload chunks through a dedicated client without
-
Add regression tests.
- Assert that public, subtitle, and CDN requests contain no account cookies.
- Test malicious absolute sub ...[truncated 148 chars]
-
