Skip to content
Open
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
22 changes: 21 additions & 1 deletion aderyn/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use aderyn::{
print_all_detectors_view, print_detail_view,
};
use aderyn_driver::driver::{self, Args, kick_off_report_creation};
use aderyn_driver::IssueCount;
use clap::{ArgGroup, CommandFactory, Parser, Subcommand, ValueHint};
use clap_complete::{Shell, generate};
use indoc::indoc;
Expand Down Expand Up @@ -79,6 +80,14 @@ pub struct CommandLineArgs {
#[arg(long)]
highs_only: bool,

/// Exit with code 1 if any low or high severity issues are detected.
#[arg(long)]
fail_low: bool,

/// Exit with code 1 if any high severity issues are detected.
#[arg(long)]
fail_high: bool,

// ---------- Hidden arguments --------------- //
/// After generating report, skip checking if a new version of Aderyn is available.
#[arg(long, hide = true)]
Expand Down Expand Up @@ -250,6 +259,8 @@ fn main() {
return;
}

let mut issue_count: Option<IssueCount> = None;

if cmd_args.auditor_mode {
driver::kick_off_audit_mode(args.clone());
} else {
Expand All @@ -259,7 +270,16 @@ fn main() {
args.common_config.skip_cloc = true;
spin_up_language_server(args);
} else {
kick_off_report_creation(args.clone());
issue_count = Some(kick_off_report_creation(args.clone()));
}
}

if let Some(count) = &issue_count {
if cmd_args.fail_low && (count.low > 0 || count.high > 0) {
std::process::exit(1);
}
if cmd_args.fail_high && count.high > 0 {
std::process::exit(1);
}
}

Expand Down
10 changes: 5 additions & 5 deletions aderyn_driver/src/driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use crate::{
runner::{run_auditor_mode, run_detector_mode, run_lsp_mode},
};
use aderyn_core::detect::detector::{IssueDetector, IssueSeverity, get_all_issue_detectors};
use aderyn_core::report::IssueCount;
use field_access::FieldAccess;
use std::sync::Arc;
use tokio::sync::Mutex;
Expand Down Expand Up @@ -60,24 +61,23 @@ pub fn kick_off_audit_mode(args: Args) {
}

/// One way pipeline to generate vulnerability reports. (for CLI)
pub fn kick_off_report_creation(args: Args) {
let run_pipeline = || -> Result<(), Box<dyn std::error::Error>> {
pub fn kick_off_report_creation(args: Args) -> IssueCount {
let run_pipeline = || -> Result<IssueCount, Box<dyn std::error::Error>> {
let cx_wrapper =
make_context(&args.input_config, &args.common_config).unwrap_or_else(|e| {
eprintln!("Error making context: {}", e);
std::process::exit(1);
});

// Load the workspace context into the run function, which runs the detectors
run_detector_mode(&cx_wrapper, &args.output_config)?;
Ok(())
run_detector_mode(&cx_wrapper, &args.output_config)
};

// Kick-off
run_pipeline().unwrap_or_else(|e| {
eprintln!("Error driving aderyn: {}", e);
std::process::exit(1);
});
})
}

/// Identify and return vulnerability reports. (for LSP)
Expand Down
4 changes: 3 additions & 1 deletion aderyn_driver/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,7 @@ pub mod config;
pub mod driver;
pub mod process;

pub use aderyn_core::{ast as core_ast, detect as detection_modules, detect::detector};
pub use aderyn_core::{
ast as core_ast, detect as detection_modules, detect::detector, report::IssueCount,
};
pub use mcp::SingletonMcpServer;
5 changes: 3 additions & 2 deletions aderyn_driver/src/runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@ use aderyn_core::report::*;
pub fn run_detector_mode(
cx_wrapper: &WorkspaceContextWrapper,
output_config: &CliArgsOutputConfig,
) -> Result<(), Box<dyn Error>> {
) -> Result<IssueCount, Box<dyn Error>> {
println!("Running {} detectors", cx_wrapper.detectors.len());

let detectors = cx_wrapper.detectors.iter().map(|d| d.skeletal_clone()).collect();
let report = detect_issues(&cx_wrapper.contexts, &cx_wrapper.root_path, detectors)?;
let issue_count = report.issue_count();
let output_file_path = output_config.output.clone();

let output_interface = if output_file_path.ends_with(".json") {
Expand All @@ -31,7 +32,7 @@ pub fn run_detector_mode(

output_interface_router(output_interface, &report, cx_wrapper, output_config)?;

Ok(())
Ok(issue_count)
}

pub fn run_lsp_mode(ctx_wrapper: &WorkspaceContextWrapper) -> Option<LspReport> {
Expand Down