Skip to content

Commit 1c2d5fd

Browse files
factorydroidFactory Bot
authored andcommitted
fix: Validate file attachments to prevent reading device files or large files
1 parent da71f46 commit 1c2d5fd

1 file changed

Lines changed: 13 additions & 0 deletions

File tree

cortex-cli/src/run_cmd.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,19 @@ impl RunCli {
346346
format!("Failed to read file metadata: {}", resolved_path.display())
347347
})?;
348348

349+
if !metadata.is_file() && !metadata.is_dir() {
350+
bail!(
351+
"File is not a regular file or directory: {}",
352+
file_path.display()
353+
);
354+
}
355+
356+
// Max file size check (e.g. 10MB) to prevent OOM
357+
const MAX_FILE_SIZE: u64 = 10 * 1024 * 1024;
358+
if metadata.len() > MAX_FILE_SIZE {
359+
bail!("File too large (max 10MB): {}", file_path.display());
360+
}
361+
349362
let filename = resolved_path
350363
.file_name()
351364
.map(|n| n.to_string_lossy().to_string())

0 commit comments

Comments
 (0)