mirror of
https://github.com/fluxerapp/fluxer
synced 2026-10-17 04:55:42 +09:00
fix(ci): reject path traversal in S3 prefix downloads (#2070)
This commit is contained in:
1 parent
9d0be1ebd1
commit
0496b2f530
1 file changed
+12
-1
+12
-1
@@ -1069,7 +1069,7 @@ pub(crate) async fn download_s3_prefix(
|
|||||||
if relative.is_empty() {
|
if relative.is_empty() {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
let output = target.join(relative);
|
let output = safe_download_target(target, relative)?;
|
||||||
if let Some(parent) = output.parent() {
|
if let Some(parent) = output.parent() {
|
||||||
tokio::fs::create_dir_all(parent)
|
tokio::fs::create_dir_all(parent)
|
||||||
.await
|
.await
|
||||||
@@ -1248,6 +1248,17 @@ pub(crate) fn path_to_s3_key(path: &Path) -> String {
|
|||||||
.join("/")
|
.join("/")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn safe_download_target(target: &Path, relative: &str) -> Result<PathBuf> {
|
||||||
|
let candidate = Path::new(relative);
|
||||||
|
for component in candidate.components() {
|
||||||
|
ensure!(
|
||||||
|
matches!(component, std::path::Component::Normal(_)),
|
||||||
|
"Refusing to write S3 object outside download target: {relative}"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
Ok(target.join(candidate))
|
||||||
|
}
|
||||||
|
|
||||||
pub(crate) async fn download_file(url: &str, path: &Path) -> Result<()> {
|
pub(crate) async fn download_file(url: &str, path: &Path) -> Result<()> {
|
||||||
let bytes = Client::new()
|
let bytes = Client::new()
|
||||||
.get(url)
|
.get(url)
|
||||||
|
|||||||
Reference in new issue
Block a user