diff --git a/src/main.rs b/src/main.rs index d85103a..39c6997 100644 --- a/src/main.rs +++ b/src/main.rs @@ -77,7 +77,7 @@ enum Commands { )] scan_type: Option, - #[arg(long, help = "Output the result to a file in a specific format. Valid options are json, html.")] + #[arg(long, help = "Output the result to a file in a specific format. Valid options are json, html, sarif.")] out_format: Option, #[arg(short, long, help = "Output the result to a file. you can use the out_format option to specify the format of the output file.")] @@ -244,6 +244,13 @@ fn main() { std::process::exit(1); } + if let Some(format) = out_format { + if !["json", "html", "sarif"].contains(&format.as_str()) { + eprintln!("Invalid out_format option. Expected one of 'json', 'html', 'sarif'."); + std::process::exit(1); + } + } + if *fail && fail_on.is_some() { eprintln!("fail and fail_on cannot be used together."); std::process::exit(1); diff --git a/src/scanners/blast.rs b/src/scanners/blast.rs index f743773..eb66d4a 100644 --- a/src/scanners/blast.rs +++ b/src/scanners/blast.rs @@ -254,7 +254,7 @@ pub fn run( println!("\n\nScan results written to: {}\n\n", out_file.clone()); } else if out_format == "html" { - let report = match utils::api::get_scan_report(&config.get_url(), &config.get_token(), &scan_id) { + let report = match utils::api::get_scan_report(&config.get_url(), &config.get_token(), &scan_id, None) { Ok(html) => html, Err(e) => { eprintln!("\n\nFailed to fetch scan report: {}\n\n", e); @@ -267,6 +267,20 @@ pub fn run( utils::terminal::clear_previous_line(); println!("\n\nScan report written to: {}\n\n", out_file.clone()); } + else if out_format == "sarif" { + let report = match utils::api::get_scan_report(&config.get_url(), &config.get_token(), &scan_id, Some("sarif")) { + Ok(sarif) => sarif, + Err(e) => { + eprintln!("\n\nFailed to fetch SARIF report: {}\n\n", e); + std::process::exit(1); + } + }; + *stop_signal.lock().unwrap() = true; + let _ = results_thread.join(); + fs::write(out_file.clone(), report).expect("\n\nFailed to write SARIF file, check if the file path is valid and you have the necessary permissions to write to it."); + utils::terminal::clear_previous_line(); + println!("\n\nScan report written to: {}\n\n", out_file.clone()); + } } } diff --git a/src/utils/api.rs b/src/utils/api.rs index f049888..7bb50ee 100644 --- a/src/utils/api.rs +++ b/src/utils/api.rs @@ -336,8 +336,12 @@ pub fn get_scan(url: &str, token: &str, scan_id: &str) -> Result Result> { - let url = format!("{}{}/scan/{}/report", url, API_BASE, scan_id); +pub fn get_scan_report(url: &str, token: &str, scan_id: &str, format: Option<&str>) -> Result> { + let url = if let Some(fmt) = format { + format!("{}{}/scan/{}/report?format={}", url, API_BASE, scan_id, fmt) + } else { + format!("{}{}/scan/{}/report", url, API_BASE, scan_id) + }; let client = http_client(); let mut headers = HeaderMap::new();