Skip to content

Commit

Permalink
fix(ext/fetch): percent decode userinfo when parsing proxies
Browse files Browse the repository at this point in the history
  • Loading branch information
seanmonstar committed Aug 27, 2024
1 parent e132302 commit 03a247e
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion ext/fetch/proxy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -773,6 +776,16 @@ fn test_proxy_parse_from_env() {
_ => panic!("bad target"),
}

// percent encoded user info
match parse("us%2Fer:p%[email protected]: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:[email protected]:6666") {
Target::Socks { dst, auth } => {
Expand Down

0 comments on commit 03a247e

Please sign in to comment.