T09 · Insecure Skill Coding Practices
Error
- Location
- scripts/xuexitong_submit.py:69
- Finding
- Authentication Cookie Disclosure Through Unvalidated Request URLs<![CDATA[ ## Vulnerability Details **File Location**: - `scripts/xuexitong_submit.py:69-94` - `scripts/xuexitong_submit.py:129-181` - `scripts/xuexitong_submit.py:220-245` - `scripts/xuexitong_hw_pipeline.py:93-127` - `scripts/xuexitong_hw_pipeline.py:326-332` - `scripts/xuexitong_hw_pipeline.py:406-420` **Vulnerability Type**: Sensitive credential disclosure through unvalidated outbound requests **Risk Level**: High ### Vulnerable Code The session places the complete authentication cookie in a global request header: ```python def session(cookie_header: str, ua: str = DEFAULT_UA) -> requests.Session: """Create a session that sends cookies as a CookieJar (more reliable than raw Cookie header).""" s = requests.Session() s.headers.update( { "User-Agent": ua, "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8", "Accept-Language": "zh-CN,zh;q=0.9", "Referer": "https://mooc1-api.chaoxing.com/work/stu-work", # Many Chaoxing endpoints behave differently depending on whether cookies are sent # as a raw header vs cookie jar. We set BOTH for maximum compatibility. "Cookie": cookie_header, } ) # Populate cookie jar for kv in cookie_header.split(";"): kv = kv.strip() if not kv or "=" not in kv: continue k, v = kv.split("=", 1) k = k.strip() v = v.strip() if not k: continue s.cookies.set(k, v, domain=".chaoxing.com") return s ``` The same authenticated session is then used with caller-controlled URLs without validating their scheme, hostname, or port: ```python def resolve_mtask_to_dohomework(s: requests.Session, task_url: str, sleep_ms: int = 0) -> str: if sleep_ms: time.sleep(sleep_ms / 1000) r = s.get(task_url, timeout=30) r.raise_for_status() html = r.text # Find doHomeWork URL inside the page # pattern i ...[truncated 4273 chars]
- Remediation
- <![CDATA[ ## Remediation Suggestions 1. Remove the global raw cookie header: ```python s.headers.pop("Cookie", None) ``` Use only a domain-scoped `RequestsCookieJar`. 2. Validate every URL before making a request: - Require the `https` scheme. - Require an explicit hostname allowlist, such as `mooc1-api.chaoxing.com`. - Reject embedded credentials, unexpected ports, malformed hostnames, and scheme-relative URLs. - Compare normalized hostnames rather than using substring or suffix-only checks. 3. Disable automatic redirects or validate each redirect destination: ```python response = s.get(url, timeout=30, allow_redirects=False) ``` Follow redirects only after applying the same scheme and hostname checks. 4. Centralize outbound URL validation so `resolve`, `fetch`, `save`, `submit`, the pipeline, and the scanner use the same policy. 5. Use separate sessions for separate services. Each session should contain only the minimum cookies required by that specific Chaoxing endpoint. 6. Add regression tests proving that attacker-controlled hosts, HTTP URLs, deceptive subdomains, user-info URLs, and off-domain redirects are rejected before any credential is transmitted. ]]>
