Skip to main content

dalfox_rs/
lib.rs

1//! # Dalfox-RS
2//!
3//! A type-safe, asynchronous Rust wrapper for the [Dalfox](https://github.com/hahwul/dalfox)
4//! XSS Scanner.
5//!
6//! This crate orchestrates the Dalfox Go binary, streaming its JSON output directly into
7//! heavily typed Rust structs, making XSS scanning inside Rust projects
8//! highly composable and panic-free.
9//!
10//! ## Features
11//!
12//! - **Full Dalfox CLI coverage**: Every flag exposed as a typed builder method.
13//! - **Streaming output**: Real-time callbacks as findings are discovered.
14//! - **Stored XSS**: First-class `sxss` mode support.
15//! - **Multi-format output**: JSON, CSV, Markdown, and plain text.
16//! - **Diagnostic capture**: stderr, parse errors, exit codes all preserved.
17//!
18//! ## Example
19//!
20//! ```rust,no_run
21//! use dalfox_rs::{Dalfox, DalfoxResult};
22//!
23//! #[tokio::main]
24//! async fn main() -> Result<(), Box<dyn std::error::Error>> {
25//!     let runner = Dalfox::builder()
26//!         .request_timeout(10)
27//!         .scan_deadline(300)
28//!         .workers(100)
29//!         .build();
30//!
31//!     let result: DalfoxResult = runner.scan_url("http://example.com?q=test").await?;
32//!
33//!     for finding in &result.findings {
34//!         println!("Found XSS! {}", finding);
35//!     }
36//!
37//!     // Check for parse issues (schema changed?)
38//!     if result.has_parse_errors() {
39//!         eprintln!("Warning: {} lines failed to parse", result.parse_errors.len());
40//!     }
41//!
42//!     Ok(())
43//! }
44//! ```
45#![warn(missing_docs)]
46
47/// Builder configuration for Dalfox scanning.
48pub mod builder;
49/// Error variants specific to Dalfox execution.
50pub mod error;
51/// The core asynchronous executor and scan modes.
52pub mod runner;
53/// Strictly-typed structs for Dalfox's JSON response, enums, and output formatting.
54pub mod types;
55
56pub use builder::DalfoxBuilder;
57pub use error::DalfoxError;
58pub use runner::DalfoxRunner;
59pub use types::{DalfoxFinding, DalfoxResult, EventType, Method, OutputFormat, Severity};
60
61/// Entry point to configure a Dalfox scan.
62///
63/// # Examples
64///
65/// ```rust
66/// use dalfox_rs::Dalfox;
67///
68/// let runner = Dalfox::builder()
69///     .request_timeout(10)
70///     .workers(50)
71///     .build();
72/// ```
73pub struct Dalfox;
74
75impl Dalfox {
76    /// Creates a new configuration builder.
77    pub fn builder() -> DalfoxBuilder {
78        DalfoxBuilder::new()
79    }
80}