{"record":{"id":"ff9e19bae0d5a203","repo":"zeroclaw-labs/zeroclaw","slug":"url-cannot-contain-whitespace","errorCode":null,"errorMessage":"URL cannot contain whitespace","messagePattern":"URL cannot contain whitespace","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/zeroclaw-tools/src/browser_open.rs","lineNumber":51,"sourceCode":"                allowed_domains,\n                \"browser.allowed_domains\",\n            )?,\n            allowed_private_hosts: domain_guard::normalize_allowed_domains(\n                allowed_private_hosts,\n                \"browser.allowed_private_hosts\",\n            )?,\n        })\n    }\n\n    fn validate_url(&self, raw_url: &str) -> anyhow::Result<String> {\n        let url = raw_url.trim();\n\n        if url.is_empty() {\n            anyhow::bail!(\"URL cannot be empty\");\n        }\n\n        if url.chars().any(char::is_whitespace) {\n            anyhow::bail!(\"URL cannot contain whitespace\");\n        }\n\n        if !(url.starts_with(\"https://\") || url.starts_with(\"http://\")) {\n            anyhow::bail!(\"Only http:// or https:// URLs are allowed\");\n        }\n\n        if self.allowed_domains.is_empty() && self.allowed_private_hosts.is_empty() {\n            anyhow::bail!(\n                \"Browser tool is enabled but no allowed_domains are configured. Add [browser].allowed_domains in config.toml\"\n            );\n        }\n\n        let host = extract_host(url)?;\n        let private_host = domain_guard::is_private_or_local_host(&host);\n        let private_host_allowed = private_host\n            && domain_guard::host_matches_allowlist(&host, &self.allowed_private_hosts);\n\n        if private_host && !private_host_allowed {","sourceCodeStart":33,"sourceCodeEnd":69,"githubUrl":"https://github.com/zeroclaw-labs/zeroclaw/blob/88bb9c8533fc57ed7a03e36ca7c9ed2bf8336dcc/crates/zeroclaw-tools/src/browser_open.rs#L33-L69","documentation":"After trimming, browser_open rejects any URL containing an internal whitespace character — space, tab, newline, or unicode spaces (char::is_whitespace). Spaces break URL parsing and are a classic injection vector, so the guard fails closed rather than silently encoding the URL for the caller.","triggerScenarios":"url=\"https://example.com/my file.png\" (unencoded space), or a URL carrying an embedded tab/newline from templates or clipboard paste that survives trimming because it sits in the middle.","commonSituations":"Unencoded spaces in filenames and paths; copy-paste from PDFs or chat introducing unicode spaces (U+00A0); string concatenation joining a URL and a caption.","solutions":["Percent-encode spaces (%20) or the whole path component","Strip internal whitespace before calling, e.g. url.split_whitespace().next()","Build URLs with a URL library instead of string concatenation"],"exampleFix":"// before\n{\"url\": \"https://example.com/my file.png\"}\n// after\n{\"url\": \"https://example.com/my%20file.png\"}","handlingStrategy":"validation","validationCode":"let url = raw_url.trim();\nif url.chars().any(char::is_whitespace) {\n    return Err(\"URL contains internal whitespace; percent-encode it\".into());\n}","typeGuard":null,"tryCatchPattern":"match open_tool.execute(args).await {\n    Ok(res) if res.success => { /* ... */ }\n    Ok(res) => {\n        if res.error.as_deref().unwrap_or_default().contains(\"whitespace\") {\n            // percent-encode the URL and retry\n        }\n    }\n    Err(e) => return Err(e),\n}","preventionTips":["Percent-encode paths when building URLs from filenames","Use a URL builder instead of concatenating strings","Beware unicode spaces introduced by copy-paste from PDFs or chat"],"tags":["browser-open","url","whitespace","validation","encoding"],"backgroundTag":"malformed-url","analyzedSha":"88bb9c8533fc57ed7a03e36ca7c9ed2bf8336dcc","analyzedAt":"2026-08-23T01:07:41.857Z","schemaVersion":2},"datasetVersion":"2026-08-23T08:06:27.607Z"}