T09 · Insecure Skill Coding Practices
- Location
scripts/zhipu_api.js:101- Finding
Overbroad browser-cookie collection bypasses normal domain scoping
- Content
View full analysis
Vulnerability Details
File Location:
scripts/zhipu_api.js, lines 101-111; cookie forwarding occurs at lines 63-72
Vulnerability Type: Excessive credential collection and cross-domain cookie forwarding
Risk Level: HighVulnerable Code
javascript async function captureCookies() { const client = await CDP({ port: 18800 }); const { Network } = client; await Network.enable(); const cookies = await Network.getCookies(); await client.close(); const picked = cookies.cookies.filter(c => c.domain.includes('z.ai') || c.domain.includes('bigmodel.cn') || c.domain.includes('chatglm') ); if (!picked.length) throw new Error('No Zhipu cookies found. Please log in at image.z.ai first.'); const session = { cookies: picked.map(c => ({ name: c.name, value: c.value })), savedAt: new Date().toISOString() }; saveSession(session); return session; }The collected cookies are subsequently combined into a manually constructed header:
javascript function buildCookieString(cookies) { return (cookies || []).map(c => `${c.name}=${c.value}`).join('; '); } function buildHeaders(cookies) { return { 'Content-Type': 'application/json', 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36', 'Accept': 'application/json', 'Cookie': buildCookieString(cookies), 'Origin': 'https://image.z.ai', 'Referer': 'https://image.z.ai/', }; }Technical Analysis
Network.getCookies()retrieves browser cookies without restricting the request to the precise service URL. The code then selects cookies using substring checks instead of exact, browser-equivalent domain and path validation.This collects cookies from
bigmodel.cn,chatglmdomains, unrelatedz.aisubdomains, and potentially domains whose names merely contain one of these strings. Cookie attributes such as domain, path, expiration,Secure, `SameSit ...[truncated 2191 chars]- Remediation
View remediation
Remediation Suggestions
- Request cookies specifically for
https://image.z.ai/rather than retrieving the browser-wide cookie set. - Enforce exact domain rules, allowing only
image.z.aiand an explicitly documented parent-domain cookie where required. - Preserve and validate domain, path, expiration, host-only, and secure attributes before using a cookie.
- Do not collect cookies from
bigmodel.cn,chatglm, or unrelatedz.aisubdomains unless each cookie is demonstrably required. - Prefer executing authenticated requests inside the browser context so the browser retains responsibility for cookie scoping.
- Verify the CDP target, expected browser profile, page origin, and debugging endpoint before extracting any authentication state.
- Reject duplicate cookie names and use an explicit allowlist of the minimum session-cookie names required by the service.
- Clear sensitive arrays and session state promptly after use.
- Request cookies specifically for
