feat(dast): every scan runs the header, CSP, cookie and TLS checks (#998) (#1009)
CI / Check (push) Skipped
CI / Agent integration (push) Skipped
CI / Detect Changes (push) Successful in 3s
CI / Deploy Dashboard (push) Skipped
CI / Deploy MCP (push) Skipped
CI / Deploy Docs (push) Successful in 1m8s
CI / Deploy Agent (push) Successful in 7m12s
CI / Check (push) Skipped
CI / Agent integration (push) Skipped
CI / Detect Changes (push) Successful in 3s
CI / Deploy Dashboard (push) Skipped
CI / Deploy MCP (push) Skipped
CI / Deploy Docs (push) Successful in 1m8s
CI / Deploy Agent (push) Successful in 7m12s
This commit was merged in pull request #1009.
This commit is contained in:
1 parent
cdb84f0967
commit
0ad8bbc3c9
5 files changed
+140
-3
No files matched your search
@@ -0,0 +1,62 @@
|
||||
//! The deterministic checks every DAST scan runs (#998): security headers,
|
||||
//! Content-Security-Policy, cookies and TLS. They read what the target sends
|
||||
//! and judge it by fixed rules, so the same site gives the same findings in
|
||||
//! every scan. Until now only the LLM pentest could call them.
|
||||
//!
|
||||
//! CORS is checked by the API fuzzer agent, which every scan runs already.
|
||||
|
||||
use compliance_core::models::dast::{DastFinding, DastTarget};
|
||||
use compliance_core::traits::pentest_tool::{PentestTool, PentestToolContext};
|
||||
use compliance_core::NetGuard;
|
||||
use serde_json::json;
|
||||
use tracing::warn;
|
||||
|
||||
use crate::tools::cookie_analyzer::CookieAnalyzerTool;
|
||||
use crate::tools::csp_analyzer::CspAnalyzerTool;
|
||||
use crate::tools::security_headers::SecurityHeadersTool;
|
||||
use crate::tools::tls_analyzer::TlsAnalyzerTool;
|
||||
|
||||
/// Run every check against `target`'s base URL.
|
||||
///
|
||||
/// # Arguments
|
||||
///
|
||||
/// * `target` - the DAST target; its findings name it
|
||||
/// * `http` - the scan's client, with the target's login, so the checks see
|
||||
/// the pages a logged-in visitor gets
|
||||
/// * `guard` - where the TLS and cookie checks may connect
|
||||
///
|
||||
/// # Returns
|
||||
///
|
||||
/// The findings of all checks. A check that cannot run (the site does not
|
||||
/// answer it) is logged and adds nothing; the others still run.
|
||||
pub async fn run_checks(
|
||||
target: &DastTarget,
|
||||
http: &reqwest::Client,
|
||||
guard: NetGuard,
|
||||
) -> Vec<DastFinding> {
|
||||
let checks: [Box<dyn PentestTool>; 4] = [
|
||||
Box::new(SecurityHeadersTool::new(http.clone())),
|
||||
Box::new(CspAnalyzerTool::new(http.clone())),
|
||||
Box::new(CookieAnalyzerTool::new(http.clone(), guard)),
|
||||
Box::new(TlsAnalyzerTool::new(http.clone(), guard)),
|
||||
];
|
||||
let context = PentestToolContext {
|
||||
target: target.clone(),
|
||||
session_id: String::new(),
|
||||
sast_findings: Vec::new(),
|
||||
sbom_entries: Vec::new(),
|
||||
code_context: Vec::new(),
|
||||
rate_limit: target.rate_limit,
|
||||
allow_destructive: target.allow_destructive,
|
||||
};
|
||||
let input = json!({ "url": target.base_url });
|
||||
|
||||
let mut findings = Vec::new();
|
||||
for check in &checks {
|
||||
match check.execute(input.clone(), &context).await {
|
||||
Ok(result) => findings.extend(result.findings),
|
||||
Err(e) => warn!(check = check.name(), error = %e, "DAST check did not run"),
|
||||
}
|
||||
}
|
||||
findings
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
pub mod agents;
|
||||
pub mod auth;
|
||||
mod cdp;
|
||||
pub mod checks;
|
||||
pub mod crawler;
|
||||
pub mod orchestrator;
|
||||
pub mod recon;
|
||||
|
||||
@@ -133,8 +133,9 @@ impl DastOrchestrator {
|
||||
sast_hints,
|
||||
};
|
||||
|
||||
// Phase 3: Vulnerability Analysis
|
||||
// Phase 3: Vulnerability Analysis: the fixed checks, then the agents
|
||||
scan_run.current_phase = DastScanPhase::VulnerabilityAnalysis;
|
||||
all_findings.extend(crate::checks::run_checks(target, &http, self.guard).await);
|
||||
let vuln_findings = self
|
||||
.run_vulnerability_agents(target, &context, http)
|
||||
.await?;
|
||||
|
||||
@@ -0,0 +1,72 @@
|
||||
//! Every DAST scan runs the fixed checks (#998): a site without a
|
||||
//! Content-Security-Policy and with a session cookie lacking its flags gets
|
||||
//! those findings, and a site that sends a policy does not get the missing
|
||||
//! one.
|
||||
|
||||
#![allow(clippy::unwrap_used)]
|
||||
|
||||
use axum::http::header::{CONTENT_SECURITY_POLICY, SET_COOKIE};
|
||||
use axum::response::IntoResponse;
|
||||
use axum::Router;
|
||||
use compliance_core::models::dast::{DastFinding, DastTarget, DastTargetType, DastVulnType};
|
||||
use compliance_core::NetGuard;
|
||||
use compliance_dast::DastOrchestrator;
|
||||
|
||||
async fn serve(app: Router) -> String {
|
||||
let listener = tokio::net::TcpListener::bind("127.0.0.1:0").await.unwrap();
|
||||
let addr = listener.local_addr().unwrap();
|
||||
tokio::spawn(async move { axum::serve(listener, app).await.unwrap() });
|
||||
format!("http://{addr}")
|
||||
}
|
||||
|
||||
async fn scan(base: &str) -> Vec<DastFinding> {
|
||||
let mut target = DastTarget::new("site".into(), base.into(), DastTargetType::WebApp);
|
||||
target.max_crawl_depth = 1;
|
||||
let (_run, findings) = DastOrchestrator::new(0, NetGuard::allow_private())
|
||||
.run_scan(&target, Vec::new())
|
||||
.await
|
||||
.unwrap();
|
||||
findings
|
||||
}
|
||||
|
||||
fn missing_csp(findings: &[DastFinding]) -> bool {
|
||||
findings
|
||||
.iter()
|
||||
.any(|f| f.vuln_type == DastVulnType::CspIssue && f.title.contains("Missing"))
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn a_site_without_a_policy_gets_the_header_and_cookie_findings() {
|
||||
let base = serve(Router::new().fallback(|| async {
|
||||
(
|
||||
[(SET_COOKIE, "session=abc")],
|
||||
"<html><body>shop</body></html>",
|
||||
)
|
||||
.into_response()
|
||||
}))
|
||||
.await;
|
||||
|
||||
let findings = scan(&base).await;
|
||||
|
||||
assert!(missing_csp(&findings), "{findings:#?}");
|
||||
assert!(
|
||||
findings
|
||||
.iter()
|
||||
.any(|f| f.vuln_type == DastVulnType::CookieSecurity),
|
||||
"{findings:#?}"
|
||||
);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn a_site_with_a_policy_does_not_get_the_missing_one() {
|
||||
let base = serve(Router::new().fallback(|| async {
|
||||
(
|
||||
[(CONTENT_SECURITY_POLICY, "default-src 'self'")],
|
||||
"<html><body>shop</body></html>",
|
||||
)
|
||||
.into_response()
|
||||
}))
|
||||
.await;
|
||||
|
||||
assert!(!missing_csp(&scan(&base).await));
|
||||
}
|
||||
@@ -64,8 +64,9 @@ Authenticated scans access more of the application surface. Only test applicatio
|
||||
Click the **Scan** button on any target row. The scan progresses through:
|
||||
|
||||
1. **Crawl** -- discovers pages, forms, and API endpoints by following links and analyzing JavaScript
|
||||
2. **Test** -- sends attack payloads to discovered parameters
|
||||
3. **Report** -- collects results and generates findings
|
||||
2. **Check** -- fixed checks of what the base URL sends: security headers, Content-Security-Policy, cookie flags (`Secure`, `HttpOnly`, `SameSite`) and TLS. They follow fixed rules, so the same site gives the same findings in every scan.
|
||||
3. **Test** -- sends attack payloads to discovered parameters
|
||||
4. **Report** -- collects results and generates findings
|
||||
|
||||
### DAST in a target's scan
|
||||
|
||||
|
||||
Reference in new issue
Block a user