T07 · Tool Hijacking and Spoofing
- Location
lib/browserSession.js:64- Finding
Unanchored Browser Target Matching Allows CDP Request Spoofing
- Content
View full analysis
t.type === "page" && typeof t.url === "string" ); // Prefer a page matching the target domain const match = pages.find((p) => p.url.includes(domain)); return match || null; } ``` ```js async function evaluateFetchInPage(wsUrl, baseUrl, requestSpec) { const cdp = await openCdp(wsUrl); try { await cdp.send("Runtime.enable"); const { method, path, bodyObj } = requestSpec; const url = `${baseUrl}${path}`; const expr = ` (async () => { try { const r = await fetch(${JSON.stringify(url)}, { method: ${JSON.stringify(method)}, credentials: 'include', headers: { 'Content-Type': 'application/json', 'Accept': 'application/json' }, body: ${JSON.stringify(JSON.stringify(bodyObj ?? {}))} }); const text = await r.text(); return JSON.stringify({ status: r.status, contentType: r.headers.get('content-type') || '', text }); } catch (e) { return JSON.stringify({ __fetchError: String(e && e.message || e) }); } })() `; const result = await cdp.send("Runtime.evaluate", { expression: expr, awaitPromise: true, returnByValue: true, }); ``` ### Technical Analysis The browser target is selected using `p.url.includes(domain)`. T ...[truncated 2576 chars]- Remediation
View remediation
isTrustedTarget(page.url, domain)); ``` 2. Consider requiring the expected application path in addition to the exact hostname. 3. Reject malformed URLs, embedded credentials, unexpected ports, non-HTTPS schemes, and subdomains unless they are explicitly allowlisted. 4. Revalidate the page URL and execution context immediately before each `Runtime.evaluate` call to reduce time-of-check/time-of-use risk. 5. Execute requests in an isolated CDP world where practical, instead of relying on the page's mutable JavaScript globals. 6. Avoid calling a page-overridable `window.fetch`. Use a trusted browser mechanism or a captured native implementation that cannot be replaced by application scripts. 7. Verify that the final response URL and origin remain within an explicit allowlist. 8. Add negative tests for attacker-controlled URLs containing the trusted domain in query strings, fragments, paths, and deceptive hostnames. ]]>
