vectordotdev/vector · error
username must be valid UTF-8.
Error message
username must be valid UTF-8.
What it means
When building an HTTP(S) proxy from a proxy URL that contains basic-auth credentials, the username is percent-decoded with urlencoding::decode and unwrapped with expect. urlencoding::decode only fails on invalid percent-encoding, so this panic means the proxy URL's username contains malformed percent escape sequences (e.g. '%ZZ' or a dangling '%').
Solutions
- Fix the proxy URL's username: percent-encode special characters correctly (e.g. '@' -> %40, ':' -> %3A) or remove them.
- Percent-encode the username programmatically (urlencoding::encode) instead of hand-crafting the URL.
- Use Vector's proxy.* config to supply credentials only when needed; ensure no stray '%' characters remain.
- Validate the proxy URL with Url::parse and inspect authority.username() before configuring.
Example fix
// before export HTTPS_PROXY="http://user%name:pw@proxy.corp:3128" // invalid %na escape // after export HTTPS_PROXY="http://user%25name:pw@proxy.corp:3128"
Defensive patterns
Strategy: validation
Validate before calling
fn validate_proxy_user(proxy_url: &str) -> Result<(), String> {
let url = Url::parse(proxy_url).map_err(|e| e.to_string())?;
urlencoding::decode(url.username())
.map(|_| ())
.map_err(|_| format!("invalid percent-encoding in proxy username: {proxy_url}"))
} Prevention
- Always percent-encode userinfo with urlencoding::encode when building proxy URLs.
- Replace every literal '%' in usernames with '%25' in env vars and configs.
- Validate proxy URLs with Url::parse plus a decode check before deployment.
- Keep credentials in dedicated config fields rather than embedding them in URLs.
When it happens
Trigger: Setting proxy.http or proxy.https (or HTTP_PROXY/HTTPS_PROXY env vars read into the proxy config) to a URL whose userinfo username has invalid percent-encoding, e.g. http://%zz:pw@proxy.example.com:8080.
Common situations: Users pasting proxy URLs with credentials where special characters were hand-escaped incorrectly; env vars set in CI/containers with a stray '%' in the username; copying URLs with already-decoded special characters.
Understand the failure class
Background: "Invalid URL" errors: why new URL(), URI.parse, and reqwest::Url reject your string — missing scheme, whitespace, and bad path format — this error's family across 39 libraries.
Related errors
- Password must be valid UTF-8.
- Failed to convert OsStr to &str for
- error creating request
- Expected UTF-8.
- Invalid config file name
AI-assisted analysis of vectordotdev/vector@bdb87aeaa4 (2026-09-16).
Data as JSON: /api/errors/c79fa76405c0fcb1.
Report an issue: GitHub.
Appendix: source
Thrown at lib/vector-core/src/config/proxy.rs:169
no_proxy,
}
}
fn build_proxy(
&self,
proxy_scheme: &'static str,
proxy_url: Option<&String>,
) -> Result<Option<Proxy>, InvalidUri> {
proxy_url
.as_ref()
.map(|url| {
url.parse().map(|parsed| {
let mut proxy = Proxy::new(self.interceptor().intercept(proxy_scheme), parsed);
if let Ok(authority) = Url::parse(url)
&& let Some(password) = authority.password()
{
let decoded_user = urlencoding::decode(authority.username())
.expect("username must be valid UTF-8.");
let decoded_pw =
urlencoding::decode(password).expect("Password must be valid UTF-8.");
let mut authorization =
Authorization::basic(&decoded_user, &decoded_pw).0.encode();
authorization.set_sensitive(true);
proxy.set_header(PROXY_AUTHORIZATION, authorization);
}
proxy
})
})
.transpose()
}
fn http_proxy(&self) -> Result<Option<Proxy>, InvalidUri> {
self.build_proxy("http", self.http.as_ref())
}
fn https_proxy(&self) -> Result<Option<Proxy>, InvalidUri> {View on GitHub (pinned to bdb87aeaa4)