Skip to content

Commit

Permalink
fix(ext/fetch): percent decode userinfo when parsing proxies (#25229)
Browse files Browse the repository at this point in the history
Fixes #24691
  • Loading branch information
seanmonstar authored and lucacasonato committed Aug 29, 2024
1 parent 9fad717 commit 27edafa
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%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 } => {
Expand Down

0 comments on commit 27edafa

Please sign in to comment.