Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ enum Commands {
)]
scan_type: Option<String>,

#[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<String>,

#[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.")]
Expand Down Expand Up @@ -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);
Expand Down
16 changes: 15 additions & 1 deletion src/scanners/blast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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());
}
}
}

Expand Down
8 changes: 6 additions & 2 deletions src/utils/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -336,8 +336,12 @@ pub fn get_scan(url: &str, token: &str, scan_id: &str) -> Result<ScanResponse, B
}
}

pub fn get_scan_report(url: &str, token: &str, scan_id: &str) -> Result<String, Box<dyn std::error::Error>> {
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<String, Box<dyn std::error::Error>> {
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();
Expand Down
Loading