use clap::ValueEnum;
use serde::{Deserialize, Serialize};
pub const SCHEMA_VERSION: &str = "2.0.0";
#[derive(Debug, Clone, Copy, PartialEq, Eq, ValueEnum, Serialize, Deserialize, Default)]
#[serde(rename_all = "lowercase")]
pub enum ScanProfile {
#[default]
Web,
Api,
}
impl ScanProfile {
pub fn label(self) -> &'static str {
match self {
ScanProfile::Web => "Web Site",
ScanProfile::Api => "REST/JSON API",
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, ValueEnum, Serialize, Deserialize, Default)]
#[serde(rename_all = "lowercase")]
pub enum ReportAudience {
Executive,
#[default]
Developer,
Security,
}
impl ReportAudience {
pub fn label(self) -> &'static str {
match self {
ReportAudience::Executive => "Owner / Executive",
ReportAudience::Developer => "Developer",
ReportAudience::Security => "Security / Auditor",
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize)]
#[serde(rename_all = "lowercase")]
pub enum Severity {
Critical,
High,
Medium,
Low,
Info,
Pass,
}
impl Severity {
pub fn rank(self) -> u8 {
match self {
Severity::Critical => 5,
Severity::High => 4,
Severity::Medium => 3,
Severity::Low => 2,
Severity::Info => 1,
Severity::Pass => 0,
}
}
pub fn label(self) -> &'static str {
match self {
Severity::Critical => "CRITICAL",
Severity::High => "HIGH",
Severity::Medium => "MEDIUM",
Severity::Low => "LOW",
Severity::Info => "INFO",
Severity::Pass => "PASS",
}
}
pub fn css_class(self) -> &'static str {
match self {
Severity::Critical => "critical",
Severity::High => "high",
Severity::Medium => "medium",
Severity::Low => "low",
Severity::Info => "info",
Severity::Pass => "pass",
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, ValueEnum)]
pub enum FailThreshold {
Critical,
High,
Medium,
Low,
}
impl FailThreshold {
pub fn matches(self, severity: Severity) -> bool {
let min_rank = match self {
FailThreshold::Critical => Severity::Critical.rank(),
FailThreshold::High => Severity::High.rank(),
FailThreshold::Medium => Severity::Medium.rank(),
FailThreshold::Low => Severity::Low.rank(),
};
severity.rank() >= min_rank
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum Category {
TransportTls,
SecurityHeaders,
HttpProtocol,
Cookies,
Cors,
DnsEmail,
InformationDisclosure,
SecretsAndLeaks,
ApiSecurity,
ClientHtml,
ExposedFiles,
Availability,
}
impl Category {
pub fn label(self) -> &'static str {
match self {
Category::TransportTls => "TLS / HTTPS",
Category::SecurityHeaders => "Security Headers",
Category::HttpProtocol => "HTTP & Caching",
Category::Cookies => "Cookies",
Category::Cors => "CORS Policy",
Category::DnsEmail => "DNS & Email",
Category::InformationDisclosure => "Information Disclosure",
Category::SecretsAndLeaks => "Secrets & Data Leaks",
Category::ApiSecurity => "API & Auth Hygiene",
Category::ClientHtml => "Client & HTML Components",
Category::ExposedFiles => "Exposed Files & Metadata",
Category::Availability => "Availability",
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, Default)]
#[serde(rename_all = "snake_case")]
pub enum ExecutionStatus {
#[default]
Completed,
Skipped,
Error,
Cancelled,
}
impl ExecutionStatus {
pub fn label(self) -> &'static str {
match self {
ExecutionStatus::Completed => "completed",
ExecutionStatus::Skipped => "skipped",
ExecutionStatus::Error => "error",
ExecutionStatus::Cancelled => "cancelled",
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, Default)]
#[serde(rename_all = "snake_case")]
pub enum Verdict {
#[default]
Pass,
Fail,
Inconclusive,
NotApplicable,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, Default)]
#[serde(rename_all = "lowercase")]
pub enum Confidence {
#[default]
High,
Medium,
Low,
}
impl Confidence {
pub fn label(self) -> &'static str {
match self {
Confidence::High => "high",
Confidence::Medium => "medium",
Confidence::Low => "low",
}
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct CheckOutcome {
pub check_id: String,
pub category: Category,
pub location: String,
pub auth_context: String,
pub status: ExecutionStatus,
pub verdict: Verdict,
#[serde(default)]
pub reason: Option<String>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Finding {
pub id: String,
pub category: Category,
pub severity: Severity,
pub title: String,
pub summary: String,
pub evidence: Option<String>,
pub remediation: String,
#[serde(default)]
pub standard_ref: Option<String>,
#[serde(default)]
pub confidence: Confidence,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct FindingInstance {
pub fingerprint: String,
pub finding_id: String,
pub category: Category,
pub severity: Severity,
pub confidence: Confidence,
pub location: String,
pub auth_context: String,
pub title: String,
pub summary: String,
pub evidence: Option<String>,
pub remediation: String,
#[serde(default)]
pub standard_ref: Option<String>,
}
pub fn compute_fingerprint(
rule_id: &str,
target: &str,
location: &str,
auth_context: &str,
) -> String {
let mut hash: u64 = 0xcbf29ce484222325;
for part in [rule_id, "|", target, "|", location, "|", auth_context] {
for b in part.as_bytes() {
hash ^= u64::from(*b);
hash = hash.wrapping_mul(0x100000001b3);
}
}
format!("fp-{hash:016x}")
}
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
pub struct CoverageSummary {
pub total_checks: usize,
pub completed: usize,
pub skipped: usize,
pub errors: usize,
pub cancelled: usize,
pub not_applicable: usize,
pub coverage_percent: u8,
pub is_preliminary: bool,
}
impl CoverageSummary {
pub fn from_outcomes(outcomes: &[CheckOutcome], cancelled: bool) -> Self {
let mut summary = Self::default();
for o in outcomes {
if o.verdict == Verdict::NotApplicable {
summary.not_applicable += 1;
continue;
}
summary.total_checks += 1;
match o.status {
ExecutionStatus::Completed => summary.completed += 1,
ExecutionStatus::Skipped => summary.skipped += 1,
ExecutionStatus::Error => summary.errors += 1,
ExecutionStatus::Cancelled => summary.cancelled += 1,
}
}
summary.coverage_percent = (summary.completed * 100)
.checked_div(summary.total_checks)
.map_or(if cancelled { 0 } else { 100 }, |v| v.min(100) as u8);
summary.is_preliminary = cancelled
|| summary.errors > 0
|| summary.cancelled > 0
|| summary.coverage_percent < 100;
summary
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ScorePenalty {
pub finding_id: String,
pub title: String,
pub severity: Severity,
pub points: u8,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct TlsInfo {
pub protocol: String,
pub cipher_suite: String,
pub subject: String,
pub issuer: String,
pub sans: Vec<String>,
pub not_before: String,
pub not_after: String,
pub days_remaining: i64,
pub hostname_matches: bool,
}
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
pub struct SeverityCounts {
pub critical: usize,
pub high: usize,
pub medium: usize,
pub low: usize,
pub info: usize,
pub pass: usize,
}
impl SeverityCounts {
pub fn from_findings(findings: &[Finding]) -> Self {
let mut counts = Self::default();
for f in findings {
match f.severity {
Severity::Critical => counts.critical += 1,
Severity::High => counts.high += 1,
Severity::Medium => counts.medium += 1,
Severity::Low => counts.low += 1,
Severity::Info => counts.info += 1,
Severity::Pass => counts.pass += 1,
}
}
counts
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ScanReport {
#[serde(default = "default_schema_v1")]
pub schema_version: String,
#[serde(default)]
pub engine_version: String,
pub target: String,
pub final_url: String,
pub scanned_at: String,
pub duration_ms: u128,
pub status_code: Option<u16>,
#[serde(default)]
pub profile: ScanProfile,
#[serde(default = "default_auth_ctx")]
pub auth_context: String,
#[serde(default)]
pub run_status: ExecutionStatus,
#[serde(default)]
pub cancelled: bool,
pub pages_scanned: usize,
pub crawled_urls: Vec<String>,
pub score: u8,
pub grade: String,
#[serde(default)]
pub score_breakdown: Vec<ScorePenalty>,
#[serde(default)]
pub coverage: CoverageSummary,
#[serde(default)]
pub outcomes: Vec<CheckOutcome>,
#[serde(default)]
pub instances: Vec<FindingInstance>,
pub tls: Option<TlsInfo>,
pub findings: Vec<Finding>,
pub counts: SeverityCounts,
}
fn default_schema_v1() -> String {
"1.0.0".to_string()
}
fn default_auth_ctx() -> String {
"anonymous".to_string()
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct MultiScanReport {
#[serde(default = "default_schema_v1")]
pub schema_version: String,
#[serde(default)]
pub engine_version: String,
pub tool: String,
pub version: String,
pub generated_at: String,
#[serde(default)]
pub cancelled: bool,
pub reports: Vec<ScanReport>,
}
#[derive(Debug, Clone)]
pub struct ScanConfig {
pub timeout_secs: u64,
pub concurrency: usize,
pub max_pages: usize,
pub max_requests: usize,
pub max_body_bytes: usize,
pub profile: ScanProfile,
pub skip_paths: bool,
pub skip_dns: bool,
pub user_agent: String,
pub auth_context: String,
pub openapi_path: Option<String>,
pub custom_rules: Vec<crate::rules::CustomRule>,
pub custom_advisories: Vec<crate::advisories::AdvisoryEntry>,
pub auth_headers: Vec<(String, String)>,
pub check_legacy_tls: bool,
pub check_unauth_access: bool,
}
impl Default for ScanConfig {
fn default() -> Self {
Self {
timeout_secs: 10,
concurrency: 6,
max_pages: 10,
max_requests: 120,
max_body_bytes: 512 * 1024,
profile: ScanProfile::Web,
skip_paths: false,
skip_dns: false,
user_agent: format!("web-vuln-scanner/{}", env!("CARGO_PKG_VERSION")),
auth_context: "anonymous".to_string(),
openapi_path: None,
custom_rules: Vec::new(),
custom_advisories: Vec::new(),
auth_headers: Vec::new(),
check_legacy_tls: true,
check_unauth_access: true,
}
}
}