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

  1. Fix the proxy URL's username: percent-encode special characters correctly (e.g. '@' -> %40, ':' -> %3A) or remove them.
  2. Percent-encode the username programmatically (urlencoding::encode) instead of hand-crafting the URL.
  3. Use Vector's proxy.* config to supply credentials only when needed; ensure no stray '%' characters remain.
  4. 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

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


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)