mirror of
https://git.ethanthesleepy.one/ethanaobrien/ew
synced 2026-07-12 00:32:20 +08:00
Fix logic
This commit is contained in:
@@ -16,9 +16,13 @@ async fn maintenance(_req: HttpRequest) -> HttpResponse {
|
|||||||
|
|
||||||
fn safe_join(base: &Path, untrusted: &str) -> Option<PathBuf> {
|
fn safe_join(base: &Path, untrusted: &str) -> Option<PathBuf> {
|
||||||
let relative = untrusted.trim_start_matches("/");
|
let relative = untrusted.trim_start_matches("/");
|
||||||
let joined = base.join(relative);
|
if Path::new(relative)
|
||||||
let canonical = joined.canonicalize().ok()?;
|
.components()
|
||||||
canonical.starts_with(base.canonicalize().ok()?).then_some(canonical)
|
.any(|c| matches!(c, std::path::Component::ParentDir))
|
||||||
|
{
|
||||||
|
return None;
|
||||||
|
}
|
||||||
|
Some(base.join(relative))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "library")]
|
#[cfg(feature = "library")]
|
||||||
|
|||||||
Reference in New Issue
Block a user