T09 · Insecure Skill Coding Practices
- Location
scripts/cdp-proxy.mjs:253- Finding
Unauthenticated Persistent CDP Browser-Control API
- Content
View full analysis
Vulnerability Details
File Location:
scripts/cdp-proxy.mjs:253-260, 330-601, 653-658; persistent startup occurs atscripts/check-deps.mjs:90-105
Vulnerability Type: Missing authentication and caller validation on a privileged local API
Risk Level: HighComplete Code Snippets
The HTTP server processes requests without authenticating the caller:
js const server = http.createServer(async (req, res) => { const parsed = new URL(req.url, `http://localhost:${PORT}`); const pathname = parsed.pathname; const q = Object.fromEntries(parsed.searchParams); if (q.target) touchTab(q.target); res.setHeader('Content-Type', 'application/json; charset=utf-8');Arbitrary caller-supplied JavaScript is evaluated in the selected browser target:
js else if (pathname === '/eval') { let sid; let contextId; if (q.frame !== undefined) ({ sessionId: sid, contextId } = await pageFrames.frameContext(q.target, q.frame)); else sid = await ensureSession(q.target); const body = await readBody(req); const expr = body || q.expr || 'document.title'; const resp = await sendCDP('Runtime.evaluate', { expression: expr, returnByValue: true, awaitPromise: true, ...(contextId ? { contextId } : {}), }, sid);The same unauthenticated API can place caller-selected local files into a web page's file input:
js else if (pathname === '/setFiles') { const sid = await ensureSession(q.target); const body = JSON.parse(await readBody(req)); if (!body.selector || !body.files) { res.statusCode = 400; res.end(JSON.stringify({ error: '需要 selector 和 files 字段' })); return; } await sendCDP('DOM.enable', {}, sid); const doc = await sendCDP('DOM.getDocument', {}, sid); const node = await sendCDP('DOM.querySelector', { nodeId: doc.result.root.nodeId, selector: body.selector }, sid); await sendCDP('DOM.setFi ...[truncated 4636 chars]- Remediation
View remediation
Remediation Suggestions
- Generate a cryptographically random capability token whenever the proxy starts and require it on every privileged endpoint. Pass it in an authorization header rather than a URL query parameter.
- Validate the
Hostheader against an exact allowlist and reject unknown hostnames to mitigate DNS-rebinding attacks. - Reject requests with unexpected
Originvalues on every privileged endpoint, not only/shutdown. Do not treat a missingOriginas the sole proof of authorization. - Prefer access-controlled local IPC, such as a Unix-domain socket with restrictive filesystem permissions, where platform support permits it.
- Restrict normal operations to tabs created and tracked by the proxy. Require separate explicit authorization before listing, attaching to, manipulating, or closing pre-existing user tabs.
- Disable
/setFilesby default or require an explicit per-operation approval containing an allowlisted path. Canonicalize paths and constrain them to user-approved files or directories. - Constrain screenshot output to an application-owned directory and create files safely rather than accepting arbitrary output paths.
- Rotate credentials on every proxy restart and avoid persisting bearer tokens in logs or command lines.
- Consider terminating the proxy after a bounded idle period or requiring an explicit user action to reactivate privileged browser control.
- Add security tests proving that unauthenticated requests, forged
Hostheaders, and browser-originated cross-origin requests cannot invoke privileged endpoints.
