mirror of
https://github.com/BerriAI/litellm.git
synced 2026-11-17 09:34:48 +00:00
fix(gateway): reject upstream URI fragments
This commit is contained in:
parent
975e402c06
commit
aabe3dda67
2 changed files with 16 additions and 4 deletions
|
|
@ -35,6 +35,9 @@ impl Settings {
|
|||
.litellm_python_upstream
|
||||
.as_deref()
|
||||
.ok_or_else(invalid)?;
|
||||
if upstream.contains('#') {
|
||||
return Err(invalid());
|
||||
}
|
||||
let uri: axum::http::Uri = upstream.parse().map_err(|_| invalid())?;
|
||||
let authority = uri.authority().ok_or_else(invalid)?;
|
||||
let port = authority.as_str().strip_prefix(authority.host());
|
||||
|
|
@ -169,6 +172,7 @@ mod tests {
|
|||
#[case::https("https://localhost:4002")]
|
||||
#[case::path("http://localhost:4002/python")]
|
||||
#[case::query("http://localhost:4002?token=secret")]
|
||||
#[case::fragment("http://localhost/#token=secret")]
|
||||
#[case::userinfo("http://user:secret@localhost:4002")]
|
||||
#[case::malformed("http://[::1")]
|
||||
#[case::named_port("http://localhost:http")]
|
||||
|
|
|
|||
|
|
@ -117,17 +117,20 @@ impl GatewayProcess {
|
|||
}
|
||||
|
||||
async fn wait_for_exit(mut self) -> String {
|
||||
timeout(STARTUP_TIMEOUT, async {
|
||||
let status = timeout(STARTUP_TIMEOUT, async {
|
||||
loop {
|
||||
if self.child.try_wait().unwrap().is_some() {
|
||||
break;
|
||||
if let Some(status) = self.child.try_wait().unwrap() {
|
||||
break status;
|
||||
}
|
||||
sleep(Duration::from_millis(20)).await;
|
||||
}
|
||||
})
|
||||
.await
|
||||
.expect("invalid startup should exit within the timeout");
|
||||
self.child.wait().unwrap();
|
||||
assert!(
|
||||
!status.success(),
|
||||
"invalid startup should exit unsuccessfully"
|
||||
);
|
||||
self.read_logs()
|
||||
}
|
||||
|
||||
|
|
@ -697,6 +700,11 @@ async fn unreachable_upstream_returns_bad_gateway() {
|
|||
Some("http://127.0.0.1?token=upstream-secret"),
|
||||
"upstream-secret"
|
||||
)]
|
||||
#[case::fragment(
|
||||
Some("true"),
|
||||
Some("http://127.0.0.1/#upstream-secret"),
|
||||
"upstream-secret"
|
||||
)]
|
||||
#[case::userinfo(
|
||||
Some("true"),
|
||||
Some("http://upstream-secret@127.0.0.1"),
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue