diff options
author | Sean McArthur <sean@seanmonstar.com> | 2024-08-27 04:48:54 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-08-27 13:48:54 +0200 |
commit | bb26fef4946e16a9b9916f61786416523d173e8a (patch) | |
tree | d585e4d6b8503db6d4d2936afc0ce5da4fef4f99 /ext/fetch | |
parent | 672ce3041a3dd9e2a6aab5f0ef79ec2be9cf1cba (diff) |
fix(ext/fetch): percent decode userinfo when parsing proxies (#25229)
Fixes #24691
Diffstat (limited to 'ext/fetch')
-rw-r--r-- | ext/fetch/proxy.rs | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/ext/fetch/proxy.rs b/ext/fetch/proxy.rs index 32a445d8b..b06e0fb35 100644 --- a/ext/fetch/proxy.rs +++ b/ext/fetch/proxy.rs @@ -23,6 +23,7 @@ use hyper_util::client::legacy::connect::Connected; use hyper_util::client::legacy::connect::Connection; use hyper_util::rt::TokioIo; use ipnet::IpNet; +use percent_encoding::percent_decode_str; use tokio::net::TcpStream; use tokio_rustls::client::TlsStream; use tokio_rustls::TlsConnector; @@ -192,10 +193,12 @@ impl Target { if let Some((userinfo, host_port)) = authority.as_str().split_once('@') { let (user, pass) = userinfo.split_once(':')?; + let user = percent_decode_str(user).decode_utf8_lossy(); + let pass = percent_decode_str(pass).decode_utf8_lossy(); if is_socks { socks_auth = Some((user.into(), pass.into())); } else { - http_auth = Some(basic_auth(user, Some(pass))); + http_auth = Some(basic_auth(&user, Some(&pass))); } builder = builder.authority(host_port); } else { @@ -773,6 +776,16 @@ fn test_proxy_parse_from_env() { _ => panic!("bad target"), } + // percent encoded user info + match parse("us%2Fer:p%2Fass@127.0.0.1:6666") { + Target::Http { dst, auth } => { + assert_eq!(dst, "http://127.0.0.1:6666"); + let auth = auth.unwrap(); + assert_eq!(auth.to_str().unwrap(), "Basic dXMvZXI6cC9hc3M="); + } + _ => panic!("bad target"), + } + // socks match parse("socks5://user:pass@127.0.0.1:6666") { Target::Socks { dst, auth } => { |