T09 · Insecure Skill Coding Practices
- Location
qianfan_usage.py:93- Finding
Overbroad Baidu Cookie Selection and Replay
- Content
View full analysis
Vulnerability Details
File Location:
qianfan_usage.py:93-113
Additional Locations:qianfan.py:26-42,check_quota_v2.py:37-76
Vulnerability Type: Excessive credential scope and exposure through process arguments
Risk Level: MediumVulnerable Code
python def build_cookie_string(cookies): parts = [] for c in cookies: if 'baidu.com' in c.get('domain', ''): parts.append(f"{c['name']}={c['value']}") return '; '.join(parts) def query_with_curl(cookies): cookie_str = build_cookie_string(cookies) cmd = [ 'curl', '-s', '-L', API_URL, '-H', f'Cookie: {cookie_str}', '-H', 'Referer: https://console.bce.baidu.com/qianfan/resource/subscribe', '-H', 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36', '--max-time', '10' ] result = subprocess.run(cmd, capture_output=True, text=True) return result.stdout if result.returncode == 0 else NoneAn analogous implementation appears in
qianfan.py. The implementation incheck_quota_v2.pyuses a list containingconsole.bce.baidu.com,bce.baidu.com, andbaidu.com, but still performs substring-based matching.Technical Analysis
The code selects every cookie whose domain contains the string
baidu.com, combines the selected values into one header, and sends that header to the Qianfan console endpoint. This is broader than the minimum authorization scope required to retrieve quota information.Substring matching is not equivalent to RFC-compliant cookie-domain validation. It may select cookies for unrelated Baidu services and can also match a domain such as
notbaidu.com. Manually combining cookies also bypasses normal browser or cookie-jar enforcement of domain, path, expiration, and secure transport constraints.The complete cookie header is additionally supplied as a
curlcommand-line arg ...[truncated 1407 chars]- Remediation
View remediation
Remediation Suggestions
- Replace manual cookie-header construction with an HTTP client that uses an RFC-compliant cookie jar.
- Allowlist the exact cookie names required by the quota endpoint rather than accepting every cookie for the provider.
- Require exact or standards-compliant domain matching for
console.bce.baidu.com; do not use substring matching. - Enforce cookie path, expiration, and secure transport restrictions.
- Avoid placing session cookies in process arguments. Send the request through an in-process HTTPS library or a protected temporary configuration mechanism.
- Validate the destination URL immediately before attaching credentials and disable redirects to untrusted hosts.
- Remove expired and unrelated cookies from previously stored authentication state.
