syncable_cli/analyzer/security/
core.rs1use serde::{Deserialize, Serialize};
6use std::collections::HashMap;
7use std::path::PathBuf;
8
9#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, PartialOrd, Ord, Hash)]
11pub enum SecuritySeverity {
12 Critical,
13 High,
14 Medium,
15 Low,
16 Info,
17}
18
19#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Hash)]
21pub enum SecurityCategory {
22 SecretsExposure,
24 InsecureConfiguration,
26 CodeSecurityPattern,
28 InfrastructureSecurity,
30 AuthenticationSecurity,
32 DataProtection,
34 NetworkSecurity,
36 Compliance,
38 CodeInjection,
40 CommandInjection,
42}
43
44#[derive(Debug, Clone, Serialize, Deserialize)]
46pub struct SecurityFinding {
47 pub id: String,
48 pub title: String,
49 pub description: String,
50 pub severity: SecuritySeverity,
51 pub category: SecurityCategory,
52 pub file_path: Option<PathBuf>,
53 pub line_number: Option<usize>,
54 pub column_number: Option<usize>,
55 pub evidence: Option<String>,
56 pub remediation: Vec<String>,
57 pub references: Vec<String>,
58 pub cwe_id: Option<String>,
59 pub compliance_frameworks: Vec<String>,
60}
61
62#[derive(Debug, Serialize, Deserialize)]
64pub struct SecurityReport {
65 pub analyzed_at: chrono::DateTime<chrono::Utc>,
66 pub overall_score: f32, pub risk_level: SecuritySeverity,
68 pub total_findings: usize,
69 pub findings_by_severity: HashMap<SecuritySeverity, usize>,
70 pub findings_by_category: HashMap<SecurityCategory, usize>,
71 pub findings: Vec<SecurityFinding>,
72 pub recommendations: Vec<String>,
73 pub compliance_status: HashMap<String, ComplianceStatus>,
74}
75
76#[derive(Debug, Clone, Serialize, Deserialize)]
78pub struct ComplianceStatus {
79 pub framework: String,
80 pub coverage: f32, pub missing_controls: Vec<String>,
82 pub recommendations: Vec<String>,
83}
84
85pub trait SecurityAnalyzer {
87 type Config;
88 type Error: std::error::Error;
89
90 fn analyze_project(
92 &self,
93 project_root: &std::path::Path,
94 ) -> Result<SecurityReport, Self::Error>;
95
96 fn config(&self) -> &Self::Config;
98
99 fn supported_extensions(&self) -> Vec<&'static str>;
101}