fix host spoofing for redirects

This commit is contained in:
2023-09-30 00:28:44 -04:00
parent 087fe4d16e
commit c4b22638b1
3 changed files with 11 additions and 6 deletions

View File

@@ -148,18 +148,16 @@ impl Request {
let request_fn = |req: Request| { let request_fn = |req: Request| {
let reader = payload.into_read(); let reader = payload.into_read();
let mut unit = Unit::new( let unit = Unit::new(
&req.agent, &req.agent,
&req.method, &req.method,
&url, &url,
req.headers, req.headers,
&reader, &reader,
deadline, deadline,
req.spoofed_host
); );
// forward the spoofed host address
unit.spoofed_host = req.spoofed_host;
unit::connect(unit, true, reader).map_err(|e| e.url(url.clone())) unit::connect(unit, true, reader).map_err(|e| e.url(url.clone()))
}; };

View File

@@ -767,6 +767,7 @@ impl FromStr for Response {
vec![], vec![],
&request_reader, &request_reader,
None, None,
None
); );
Self::do_from_stream(stream, unit) Self::do_from_stream(stream, unit)
} }
@@ -1151,6 +1152,7 @@ mod tests {
vec![], vec![],
&request_reader, &request_reader,
None, None,
None,
); );
let resp = Response::do_from_stream(s.into(), unit).unwrap(); let resp = Response::do_from_stream(s.into(), unit).unwrap();
assert_eq!(resp.status(), 200); assert_eq!(resp.status(), 200);
@@ -1215,6 +1217,7 @@ mod tests {
vec![], vec![],
&Payload::Empty.into_read(), &Payload::Empty.into_read(),
None, None,
None,
), ),
) )
.unwrap(); .unwrap();
@@ -1247,6 +1250,7 @@ mod tests {
vec![], vec![],
&Payload::Empty.into_read(), &Payload::Empty.into_read(),
None, None,
None,
), ),
) )
.unwrap(); .unwrap();

View File

@@ -46,8 +46,8 @@ impl Unit {
mut headers: Vec<Header>, mut headers: Vec<Header>,
body: &SizedReader, body: &SizedReader,
deadline: Option<time::Instant>, deadline: Option<time::Instant>,
spoofed_host: Option<Cow<'static, str>>,
) -> Self { ) -> Self {
//
let (is_transfer_encoding_set, mut is_chunked) = get_header(&headers, "transfer-encoding") let (is_transfer_encoding_set, mut is_chunked) = get_header(&headers, "transfer-encoding")
// if the user has set an encoding header, obey that. // if the user has set an encoding header, obey that.
@@ -110,7 +110,7 @@ impl Unit {
is_chunked, is_chunked,
headers, headers,
deadline, deadline,
spoofed_host: None, spoofed_host,
} }
} }
@@ -227,6 +227,8 @@ pub(crate) fn connect(
&& (!h.is_name("authorization") || keep_auth_header) && (!h.is_name("authorization") || keep_auth_header)
}); });
// recreate the unit to get a new hostname and cookies for the new host. // recreate the unit to get a new hostname and cookies for the new host.
unit = Unit::new( unit = Unit::new(
&unit.agent, &unit.agent,
@@ -235,6 +237,7 @@ pub(crate) fn connect(
headers, headers,
&body, &body,
unit.deadline, unit.deadline,
unit.spoofed_host
); );
}; };
resp.history = history; resp.history = history;