CI / Check (push) Skipped
CI / Agent integration (push) Skipped
CI / Detect Changes (push) Successful in 3s
CI / Deploy Dashboard (push) Skipped
CI / Deploy Docs (push) Skipped
CI / Deploy MCP (push) Skipped
CI / Deploy Agent (push) Successful in 5m48s
90 lines
2.7 KiB
Rust
90 lines
2.7 KiB
Rust
//! robots.txt is public by design: only sensitive paths it names that answer
|
|
//! with their own content are worth a finding, and only an Info one (#997).
|
|
|
|
#![allow(clippy::unwrap_used)]
|
|
|
|
use axum::http::StatusCode;
|
|
use axum::response::{IntoResponse, Response};
|
|
use axum::routing::get;
|
|
use axum::Router;
|
|
use compliance_core::models::dast::{DastTarget, DastTargetType};
|
|
use compliance_core::models::Severity;
|
|
use compliance_core::traits::dast_agent::{DastAgent, DastContext};
|
|
use compliance_dast::agents::api_fuzzer::ApiFuzzerAgent;
|
|
|
|
const ROBOTS: &str = "User-agent: *\nDisallow: /\nDisallow: /admin\n";
|
|
|
|
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}")
|
|
}
|
|
|
|
/// The robots.txt findings of a scan of `base`.
|
|
async fn robots_findings(base: &str) -> Vec<(String, Severity)> {
|
|
let target = DastTarget::new("site".into(), base.into(), DastTargetType::WebApp);
|
|
let context = DastContext {
|
|
endpoints: Vec::new(),
|
|
technologies: Vec::new(),
|
|
sast_hints: Vec::new(),
|
|
};
|
|
ApiFuzzerAgent::new(reqwest::Client::new())
|
|
.run(&target, &context)
|
|
.await
|
|
.unwrap()
|
|
.into_iter()
|
|
.filter(|f| f.title.contains("robots.txt"))
|
|
.map(|f| (f.title, f.severity))
|
|
.collect()
|
|
}
|
|
|
|
#[tokio::test]
|
|
async fn a_reachable_sensitive_path_is_an_info_finding() {
|
|
let base = serve(
|
|
Router::new()
|
|
.route("/robots.txt", get(|| async { ROBOTS }))
|
|
.route("/admin", get(|| async { "admin console" }))
|
|
.fallback(|| async { StatusCode::NOT_FOUND }),
|
|
)
|
|
.await;
|
|
|
|
assert_eq!(
|
|
robots_findings(&base).await,
|
|
[(
|
|
"robots.txt names reachable sensitive paths".to_string(),
|
|
Severity::Info
|
|
)]
|
|
);
|
|
}
|
|
|
|
#[tokio::test]
|
|
async fn a_single_page_apps_catch_all_is_no_finding() {
|
|
async fn shell() -> Response {
|
|
"<html><div id=main></div></html>".into_response()
|
|
}
|
|
let base = serve(
|
|
Router::new()
|
|
.route("/robots.txt", get(|| async { ROBOTS }))
|
|
.fallback(shell),
|
|
)
|
|
.await;
|
|
|
|
assert!(robots_findings(&base).await.is_empty());
|
|
}
|
|
|
|
#[tokio::test]
|
|
async fn disallow_everything_is_no_finding() {
|
|
let base = serve(
|
|
Router::new()
|
|
.route(
|
|
"/robots.txt",
|
|
get(|| async { "User-agent: *\nDisallow: /\n" }),
|
|
)
|
|
.fallback(|| async { StatusCode::NOT_FOUND }),
|
|
)
|
|
.await;
|
|
|
|
assert!(robots_findings(&base).await.is_empty());
|
|
}
|