{"record":{"id":"1b4d7ff33d97c635","repo":"BigPizzaV3/CodexPlusPlus","slug":"cdp-websocket-url-must-use-ws-or-wss","errorCode":null,"errorMessage":"CDP WebSocket URL must use ws or wss","messagePattern":"CDP WebSocket URL must use ws or wss","errorType":"validation","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"crates/codex-plus-core/src/cdp.rs","lineNumber":214,"sourceCode":"\n    let targets = response\n        .json::<Vec<CdpTarget>>()\n        .await\n        .context(\"failed to deserialize CDP targets\")?;\n    for target in &targets {\n        if let Some(websocket_url) = target.web_socket_debugger_url.as_deref() {\n            validate_cdp_websocket_url(websocket_url, debug_port).with_context(|| {\n                format!(\"unsafe CDP target WebSocket URL for target {}\", target.id)\n            })?;\n        }\n    }\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    }","sourceCodeStart":196,"sourceCodeEnd":232,"githubUrl":"https://github.com/BigPizzaV3/CodexPlusPlus/blob/b1ed92e5e4a2d74095d4b8db5af43cef7acba9c6/crates/codex-plus-core/src/cdp.rs#L196-L232","documentation":"Thrown by `validate_cdp_websocket_url` when a CDP WebSocket URL's scheme is neither `ws` nor `wss`. The library requires an actual WebSocket scheme because the URL will be handed to a WebSocket client; http/https URLs are rejected outright.","triggerScenarios":"Passing an HTTP discovery URL (e.g. `http://127.0.0.1:9222/json/version`) or a hand-built string like `tcp://...` into `validate_cdp_websocket_url`, or feeding the wrong field of a CDP response (e.g. a devtoolsFrontendUrl).","commonSituations":"Confusing the HTTP `/json` endpoints with the WebSocket debugger URL, older code paths that returned http URLs, or string-concatenating a ws URL and accidentally dropping the scheme.","solutions":["Use the `webSocketDebuggerUrl` field from the CDP target/version JSON — it already starts with `ws://`","Convert the scheme explicitly: replace `http://` with `ws://` (or `https://` with `wss://`) before validating","Fix any URL construction that drops or mangles the scheme"],"exampleFix":"// before\nlet url = format!(\"http://127.0.0.1:{port}/devtools/browser/{id}\");\nvalidate_cdp_websocket_url(&url, port)?;\n// after\nlet url = format!(\"ws://127.0.0.1:{port}/devtools/browser/{id}\");\nvalidate_cdp_websocket_url(&url, port)?;","handlingStrategy":"validation","validationCode":"fn has_ws_scheme(url: &str) -> bool {\n    reqwest::Url::parse(url).map(|u| matches!(u.scheme(), \"ws\" | \"wss\")).unwrap_or(false)\n}","typeGuard":null,"tryCatchPattern":"let url = if url.starts_with(\"http://\") { url.replacen(\"http://\", \"ws://\", 1) } else { url.to_string() };\nvalidate_cdp_websocket_url(&url, port).context(\"CDP WebSocket URL rejected\")?;","preventionTips":["Use webSocketDebuggerUrl from CDP JSON, never the HTTP discovery URL","Check scheme before constructing WebSocket connections","Watch for string formatting that drops the scheme"],"tags":["cdp","websocket-url","validation","scheme"],"backgroundTag":"invalid-url-format","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"}