fix(content): validate provider download paths

This commit is contained in:
objz committed 2026-08-04 20:46:21 +02:00
1 parent fb976f1cb9
commit 95a25836a0
4 files changed
+177 -23

No files matched your search

+16
View File
@@ -389,6 +389,8 @@ pub async fn download_version_file(
destination: &std::path::Path,
) -> Result<DownloadOutcome, crate::net::NetError> {
let file = select_primary_file(version)?;
validate_path_component(&file.filename, "provider filename")?;
validate_path_component(&version.id, "provider version id")?;
let path = destination.join(&file.filename);
if path.exists() {
if verify_version_file(&path, file)? {
@@ -428,6 +430,8 @@ pub async fn download_version_file_for_update(
installed_path: &std::path::Path,
) -> Result<DownloadOutcome, crate::net::NetError> {
let file = select_primary_file(version)?;
validate_path_component(&file.filename, "provider filename")?;
validate_path_component(&version.id, "provider version id")?;
let target = destination.join(&file.filename);
if target != installed_path {
return download_version_file(client, version, destination).await;
@@ -464,6 +468,18 @@ pub async fn download_version_file_for_update(
Ok(DownloadOutcome::Downloaded(target))
}
fn validate_path_component(value: &str, label: &str) -> Result<(), crate::net::NetError> {
let mut components = std::path::Path::new(value).components();
if !matches!(components.next(), Some(std::path::Component::Normal(_)))
|| components.next().is_some()
{
return Err(crate::net::NetError::Parse(format!(
"Invalid {label} '{value}'"
)));
}
Ok(())
}
fn verify_version_file(
path: &std::path::Path,
expected: &VersionFile,