Skip to content

Commit 38f091f

Browse files
committed
fix: Validate file attachments to prevent reading device files or large files
1 parent a6338de commit 38f091f

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
@@ -341,6 +341,19 @@ impl RunCli {
341341
format!("Failed to read file metadata: {}", resolved_path.display())
342342
})?;
343343

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

0 commit comments

Comments
 (0)