{"record":{"id":"992be2326d25dad0","repo":"jdx/mise","slug":"refusing-to-send-credentials-over-an-https-to-http","errorCode":null,"errorMessage":"refusing to send credentials over an HTTPS-to-HTTP URL replacement","messagePattern":"refusing to send credentials over an HTTPS-to-HTTP URL replacement","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/http.rs","lineNumber":2030,"sourceCode":"pub(crate) fn ensure_secure_replacement_credentials(\n    original_url: &Url,\n    url: &Url,\n    headers: &HeaderMap,\n) -> Result<()> {\n    let has_credentials = headers\n        .iter()\n        .any(|(name, value)| is_credential_header(name, value));\n    ensure_secure_url_replacement(original_url, url, has_credentials)\n}\n\npub(crate) fn ensure_secure_url_replacement(\n    original_url: &Url,\n    url: &Url,\n    has_credentials: bool,\n) -> Result<()> {\n    let downgraded = original_url.scheme() == \"https\" && url.scheme() == \"http\";\n    let has_credentials = has_credentials || !url.username().is_empty() || url.password().is_some();\n    ensure!(\n        !downgraded || !has_credentials,\n        \"refusing to send credentials over an HTTPS-to-HTTP URL replacement\"\n    );\n    Ok(())\n}\n\n/// Get HTTP Basic authentication headers from netrc file for the given URL\npub(crate) fn netrc_headers(url: &Url) -> HeaderMap {\n    let mut headers = HeaderMap::new();\n    if let Some(host) = url.host_str()\n        && let Some((login, password)) = netrc::get_credentials(host)\n    {\n        let credentials = BASE64_STANDARD.encode(format!(\"{login}:{password}\"));\n        if let Ok(value) = HeaderValue::from_str(&format!(\"Basic {credentials}\")) {\n            headers.insert(reqwest::header::AUTHORIZATION, value);\n        }\n    }\n    headers","sourceCodeStart":2012,"sourceCodeEnd":2048,"githubUrl":"https://github.com/jdx/mise/blob/533346cc374382b41ec5ff70536252b2e96e725c/src/http.rs#L2012-L2048","documentation":"This is a security guard in src/http.rs (around line 2030): when a URL is replaced or rewritten (e.g. a mirror/proxy redirect), mise refuses to carry credentials from an original HTTPS URL into a replacement that uses plain HTTP. Sending a username/password or token over an unencrypted http:// connection would expose the credentials to anyone on the path, so the downgrade is blocked.","triggerScenarios":"A URL-replacement rule (URL rewrite/mirror configuration) maps an https:// endpoint to an http:// endpoint while the target URL (after replacement) contains credentials — either carried over from the original or embedded in the replacement (non-empty username or a password).","commonSituations":"Configuring a corporate mirror for a registry using http:// instead of https:// while the original URL had an embedded token; a self-hosted proxy served over HTTP; a typo'd mirror entry that downgrades the scheme; URL templates that insert auth tokens into http:// URLs.","solutions":["Change the replacement/mirror URL to https:// so the scheme is not downgraded.","If the mirror really is HTTP-only, remove the credentials from the URL and rely on a network-isolated mirror without auth.","Review the URL rewrite configuration (mirror/replacement entries) for accidental scheme changes (https→http).","Move credentials out of URLs entirely (e.g. use host-scoped auth headers/env config) so no credential can leak into a replacement."],"exampleFix":"# before (mirror config)\nhttps://registry.example.com = http://mirror.internal/registry\n# after\nhttps://registry.example.com = https://mirror.internal/registry","handlingStrategy":"validation","validationCode":"fn is_safe_replacement(original: &str, replacement: &str) -> bool {\n  !(original.starts_with(\"https://\") && replacement.starts_with(\"http://\")\n    && (replacement.contains('@') || replacement.contains(\"://\") && replacement.split(\"//\").nth(1).map_or(false, |h| h.contains('@'))))\n}","typeGuard":null,"tryCatchPattern":"match result {\n  Err(e) if e.to_string().contains(\"HTTPS-to-HTTP\") => {\n    eprintln!(\"mirror URL must be https:// when credentials are present\");\n  }\n  other => other?,\n}","preventionTips":["Always use https:// for mirrors and replacement URLs","Keep credentials out of URLs; use env-based auth instead","Audit mirror/rewrite config after network changes","Never accept user-supplied http:// mirror endpoints in tooling"],"tags":["security","http","credentials","url-rewrite"],"backgroundTag":"insecure-credentials-transmission","analyzedSha":"533346cc374382b41ec5ff70536252b2e96e725c","analyzedAt":"2026-09-17T13:35:38.149Z","contentChangedAt":"2026-09-17T13:35:38.149Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}