{"record":{"id":"954592712b0afa4c","repo":"Hmbown/CodeWhale","slug":"the-codewhale-service-returned-an-untrusted-verifi","errorCode":null,"errorMessage":"The Codewhale service returned an untrusted verification origin","messagePattern":"The Codewhale service returned an untrusted verification origin","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"crates/cli/src/cloud.rs","lineNumber":1071,"sourceCode":"    })?;\n    if !url.username().is_empty() || url.password().is_some() || url.fragment().is_some() {\n        bail!(\"The Codewhale service returned an unsafe verification URL\");\n    }\n    if url.path() != \"/cli/authorize\" {\n        bail!(\"The Codewhale service returned an unsafe verification URL\");\n    }\n\n    let api = Url::parse(api_base).context(\"invalid Codewhale account API base URL\")?;\n    let canonical_api = api.scheme() == \"https\"\n        && api.host_str() == Some(\"api.codewhale.net\")\n        && api.port_or_known_default() == Some(443);\n    let loopback_api = api.host_str().is_some_and(is_loopback_host);\n    if canonical_api {\n        if url.scheme() != \"https\"\n            || !host.eq_ignore_ascii_case(\"app.codewhale.net\")\n            || url.port_or_known_default() != Some(443)\n        {\n            bail!(\"The Codewhale service returned an untrusted verification origin\");\n        }\n    } else if loopback_api {\n        if !matches!(url.scheme(), \"http\" | \"https\") || !is_loopback_host(host) {\n            bail!(\"The Codewhale service returned an untrusted verification origin\");\n        }\n    } else {\n        bail!(\n            \"Browser login is only enabled for the canonical Codewhale account API or a loopback test API\"\n        );\n    }\n\n    let query = url.query_pairs().collect::<Vec<_>>();\n    if complete {\n        if query.len() != 1 || query[0].0 != \"user_code\" || query[0].1 != user_code {\n            bail!(\"The Codewhale service returned an unsafe verification URL\");\n        }\n    } else if !query.is_empty() {\n        bail!(\"The Codewhale service returned an unsafe verification URL\");","sourceCodeStart":1053,"sourceCodeEnd":1089,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/73e0f67d83c59909b571efdfc88c4bc28c309cb1/crates/cli/src/cloud.rs#L1053-L1089","documentation":"Thrown by `validate_verification_url` in crates/cli/src/cloud.rs:1071 when the API base is the canonical `https://api.codewhale.net` (port 443) but the verification URL is not served from the matching trusted origin: scheme must be https, host must be app.codewhale.net (case-insensitive), and the port must resolve to 443. Anything else is rejected as an untrusted origin the browser should not be pointed at.","triggerScenarios":"Using the production API while the device-authorization response returns a verification URL on a different host (`verify.staging.codewhale.net`), a non-https scheme (`http://app.codewhale.net/cli/authorize`), or an explicit non-443 port (`https://app.codewhale.net:8443/cli/authorize`).","commonSituations":"A corporate proxy or custom CODEWHALE_API_BASE value makes the CLI think it is on canonical API while a test environment hands back a staging verification host; server misconfiguration emitting http or an alternate port; DNS hijack serving a look-alike host.","solutions":["Make the device-authorization endpoint return `https://app.codewhale.net/cli/authorize` when the API base is canonical api.codewhale.net","Remove explicit ports from the verification URL (443 is implied for https)","Check whether a proxy or env override is intercepting traffic and returning a non-production URL; unset the override and retry","If this is a legit test environment, set the API base to a loopback host instead, which the CLI permits"],"exampleFix":"// before\n{ \"verification_url\": \"http://app.codewhale.net:8443/cli/authorize\" }\n// after\n{ \"verification_url\": \"https://app.codewhale.net/cli/authorize\" }","handlingStrategy":"validation","validationCode":"fn is_trusted_origin(value: &str) -> bool {\n    url::Url::parse(value).map(|u| {\n        u.scheme() == \"https\"\n            && u.host_str().map(|h| h.eq_ignore_ascii_case(\"app.codewhale.net\")).unwrap_or(false)\n            && u.port_or_known_default() == Some(443)\n    }).unwrap_or(false)\n}","typeGuard":"fn verification_origin_canonical(value: &str) -> bool {\n    matches!(url::Url::parse(value).ok(), Some(u)\n        if u.scheme() == \"https\"\n            && u.host_str().is_some_and(|h| h.eq_ignore_ascii_case(\"app.codewhale.net\"))\n            && u.port_or_known_default() == Some(443))\n}","tryCatchPattern":"match run_device_login() {\n    Err(e) if e.to_string().contains(\"untrusted verification origin\") => {\n        eprintln!(\"Verification URL is not on https://app.codewhale.net:443; refusing.\");\n    }\n    other => return other,\n}","preventionTips":["Serve verification URLs only from app.codewhale.net over https with default port","Check proxies/CDNs for host rewrites or http downgrades","Test production-configuration logins regularly, not just loopback flows","Alert on any device-auth response whose verification host differs from app.codewhale.net"],"tags":["security","origin-validation","device-login","tls"],"backgroundTag":"unexpected-api-response-shape","analyzedSha":"73e0f67d83c59909b571efdfc88c4bc28c309cb1","analyzedAt":"2026-09-22T01:30:00.501Z","contentChangedAt":"2026-09-22T01:30:00.501Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}