From df16a49c939190a9c7f8c2bfbd169e54384d048c Mon Sep 17 00:00:00 2001 From: Sharang Parnerkar Date: Mon, 16 Nov 2026 08:16:51 +0000 Subject: [PATCH] fix(dast): robots.txt is an Info finding only when it names reachable sensitive paths (#1005) --- compliance-dast/src/agents/api_fuzzer.rs | 138 ++++++++++++++++++++++- compliance-dast/tests/robots.rs | 89 +++++++++++++++ 2 files changed, 226 insertions(+), 1 deletion(-) create mode 100644 compliance-dast/tests/robots.rs diff --git a/compliance-dast/src/agents/api_fuzzer.rs b/compliance-dast/src/agents/api_fuzzer.rs index 91fa153..1bba76c 100644 --- a/compliance-dast/src/agents/api_fuzzer.rs +++ b/compliance-dast/src/agents/api_fuzzer.rs @@ -29,7 +29,6 @@ impl ApiFuzzerAgent { ("/.well-known/openid-configuration", "OIDC config"), ("/server-status", "Apache server status"), ("/phpinfo.php", "PHP info exposure"), - ("/robots.txt", "Robots.txt"), ("/sitemap.xml", "Sitemap"), ("/.htaccess", "htaccess exposure"), ("/backup.sql", "SQL backup exposure"), @@ -160,6 +159,11 @@ impl DastAgent for ApiFuzzerAgent { } } + // robots.txt is public by design; only the paths it names can matter. + if let Some(f) = self.check_robots(base, &target_id).await { + findings.push(f); + } + // Phase 2: CORS misconfiguration check let cors_finding = self.check_cors(base, &target_id).await; if let Some(f) = cors_finding { @@ -223,7 +227,115 @@ impl DastAgent for ApiFuzzerAgent { } } +/// Words that make a path named in robots.txt worth a look. +const SENSITIVE_PATH_WORDS: &[&str] = &[ + "admin", "backup", "config", "debug", "dump", "internal", "private", "secret", "staging", + ".env", ".git", ".sql", +]; + +/// Most robots.txt paths that are fetched to see whether they are reachable. +const MAX_ROBOTS_PATHS: usize = 20; + +/// The literal paths `robots` disallows that look sensitive, in file order, +/// without duplicates. Patterns (`*`, `$`) and `Disallow: /` are skipped: they +/// name no single resource. +fn sensitive_disallowed(robots: &str) -> Vec { + let mut paths: Vec = Vec::new(); + for line in robots.lines() { + // A `#` starts a comment; the directive name is case-insensitive. + let line = line.split('#').next().unwrap_or("").trim(); + let Some((key, value)) = line.split_once(':') else { + continue; + }; + let path = value.trim(); + let literal = path.len() > 1 && path.starts_with('/') && !path.contains(['*', '$']); + let lower = path.to_ascii_lowercase(); + if key.trim().eq_ignore_ascii_case("disallow") + && literal + && SENSITIVE_PATH_WORDS.iter().any(|w| lower.contains(w)) + && !paths.iter().any(|p| p == path) + { + paths.push(path.to_string()); + } + } + paths.truncate(MAX_ROBOTS_PATHS); + paths +} + impl ApiFuzzerAgent { + /// An Info finding when robots.txt names sensitive paths that answer with + /// their own content. A page that only repeats what the site sends for a + /// made-up path (a single-page app's catch-all, a login redirect) is not + /// reachable in that sense. + async fn check_robots(&self, base: &str, target_id: &str) -> Option { + let robots_url = format!("{base}/robots.txt"); + let response = self.http.get(&robots_url).send().await.ok()?; + if !response.status().is_success() { + return None; + } + let robots = response.text().await.ok()?; + let candidates = sensitive_disallowed(&robots); + if candidates.is_empty() { + return None; + } + + let made_up = format!("{base}/nonexistent-path-{}", uuid::Uuid::new_v4()); + let catch_all = match self.http.get(&made_up).send().await { + Ok(r) if r.status().is_success() => r.text().await.ok(), + _ => None, + }; + let mut reachable = Vec::new(); + for path in candidates { + let Ok(r) = self.http.get(format!("{base}{path}")).send().await else { + continue; + }; + if !r.status().is_success() { + continue; + } + let body = r.text().await.unwrap_or_default(); + if catch_all.as_deref() != Some(body.as_str()) { + reachable.push(path); + } + } + if reachable.is_empty() { + return None; + } + + let listed = reachable.join(", "); + let mut finding = DastFinding::new( + String::new(), + target_id.to_string(), + DastVulnType::InformationDisclosure, + "robots.txt names reachable sensitive paths".to_string(), + format!( + "robots.txt asks crawlers to skip {listed}, and these paths answer with \ + their own content. robots.txt is public, so it points everyone to them." + ), + Severity::Info, + robots_url.clone(), + "GET".to_string(), + ); + finding.evidence = vec![DastEvidence { + request_method: "GET".to_string(), + request_url: robots_url, + request_headers: None, + request_body: None, + response_status: 200, + response_headers: None, + response_snippet: Some(robots.chars().take(500).collect()), + screenshot_path: None, + payload: None, + response_time_ms: None, + }]; + finding.cwe = Some("CWE-200".to_string()); + finding.remediation = Some( + "Protect these paths with authentication or remove them; robots.txt does not \ + hide anything." + .to_string(), + ); + Some(finding) + } + async fn check_cors(&self, base_url: &str, target_id: &str) -> Option { let response = self .http @@ -299,3 +411,27 @@ impl ApiFuzzerAgent { } } } + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn only_literal_sensitive_disallowed_paths_count() { + let robots = "User-agent: *\n\ + Disallow: /\n\ + Disallow: /Admin/ # staff only\n\ + disallow:/backup.tar\n\ + Disallow: /*.sql$\n\ + Disallow: /search\n\ + Allow: /config-help\n\ + Disallow: /Admin/\n"; + assert_eq!(sensitive_disallowed(robots), ["/Admin/", "/backup.tar"]); + } + + #[test] + fn a_robots_txt_without_sensitive_paths_names_nothing() { + assert!(sensitive_disallowed("User-agent: *\nDisallow: /\n").is_empty()); + assert!(sensitive_disallowed("").is_empty()); + } +} diff --git a/compliance-dast/tests/robots.rs b/compliance-dast/tests/robots.rs new file mode 100644 index 0000000..8958613 --- /dev/null +++ b/compliance-dast/tests/robots.rs @@ -0,0 +1,89 @@ +//! 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 { + "
".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()); +}