{"record":{"id":"e695ea0d0a382abb","repo":"BigPizzaV3/CodexPlusPlus","slug":"cdp-websocket-host-must-be-loopback","errorCode":null,"errorMessage":"CDP WebSocket host must be loopback","messagePattern":"CDP WebSocket host must be loopback","errorType":"validation","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"crates/codex-plus-core/src/cdp.rs","lineNumber":225,"sourceCode":"    }\n    Ok(targets)\n}\n\npub fn validate_cdp_websocket_url(url: &str, expected_port: u16) -> anyhow::Result<()> {\n    let parsed = reqwest::Url::parse(url).context(\"invalid CDP WebSocket URL\")?;\n    if !matches!(parsed.scheme(), \"ws\" | \"wss\") {\n        bail!(\"CDP WebSocket URL must use ws or wss\");\n    }\n    let host = parsed\n        .host_str()\n        .ok_or_else(|| anyhow::anyhow!(\"CDP WebSocket URL has no host\"))?;\n    let address = host\n        .trim_start_matches('[')\n        .trim_end_matches(']')\n        .parse::<IpAddr>()\n        .with_context(|| \"CDP WebSocket host must be a loopback IP address\")?;\n    if !address.is_loopback() {\n        bail!(\"CDP WebSocket host must be loopback\");\n    }\n    let port = parsed\n        .port()\n        .ok_or_else(|| anyhow::anyhow!(\"CDP WebSocket URL must include an explicit port\"))?;\n    if port != expected_port {\n        bail!(\"CDP WebSocket port {port} does not match debug port {expected_port}\");\n    }\n    Ok(())\n}\n\npub fn pick_page_target(targets: &[CdpTarget]) -> anyhow::Result<CdpTarget> {\n    let mut first_page = None;\n    for target in targets\n        .iter()\n        .filter(|target| is_injectable_page_target(target))\n    {\n        first_page.get_or_insert(target);\n        if is_primary_codex_page_target(target) {","sourceCodeStart":207,"sourceCodeEnd":243,"githubUrl":"https://github.com/BigPizzaV3/CodexPlusPlus/blob/b1ed92e5e4a2d74095d4b8db5af43cef7acba9c6/crates/codex-plus-core/src/cdp.rs#L207-L243","documentation":"Thrown by `validate_cdp_websocket_url` when the URL's host is not a loopback IP address (or cannot be parsed as an IP at all). The library restricts CDP WebSocket connections to loopback (127.0.0.0/8, ::1) as a security measure so it never connects to remote debug endpoints.","triggerScenarios":"Passing a URL with a hostname (`localhost` is NOT parsed as an IP here), a public/LAN IP, or a remote machine's debug endpoint into `validate_cdp_websocket_url`.","commonSituations":"Using `ws://localhost:9222/...` instead of `ws://127.0.0.1:9222/...`, pointing at a container/VM host IP, or remote debugging over the network.","solutions":["Replace the host with an explicit loopback IP: `127.0.0.1` or `[::1]` (avoid the name `localhost`, which is not an IpAddr literal)","If the browser runs elsewhere, run a local port forward (e.g. `ssh -L`) so the CDP endpoint appears on loopback","Never disable the check by pointing at remote IPs; use an SSH tunnel instead"],"exampleFix":"// before\nvalidate_cdp_websocket_url(\"ws://localhost:9222/devtools/browser/ABC\", 9222)?;\n// after\nvalidate_cdp_websocket_url(\"ws://127.0.0.1:9222/devtools/browser/ABC\", 9222)?;","handlingStrategy":"validation","validationCode":"fn is_loopback_ws(url: &str) -> bool {\n    reqwest::Url::parse(url).ok()\n        .and_then(|u| u.host_str().map(|h| h.to_string()))\n        .map(|h| h.trim_start_matches('[').trim_end_matches(']').parse::<std::net::IpAddr>().map_or(false, |ip| ip.is_loopback()))\n        .unwrap_or(false)\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use 127.0.0.1 or [::1], not the hostname 'localhost'","Use SSH port forwarding for remote browsers so the endpoint stays on loopback","Never point CDP at LAN/public IPs — the library blocks it by design"],"tags":["cdp","security","loopback","validation"],"backgroundTag":"invalid-argument-value","analyzedSha":"b1ed92e5e4a2d74095d4b8db5af43cef7acba9c6","analyzedAt":"2026-09-19T23:35:21.129Z","contentChangedAt":"2026-09-19T23:35:21.129Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}