fix(dast): robots.txt is an Info finding only when it names reachable sensitive paths
CI / Check (push) Skipped
CI / Detect Changes (pull_request) Skipped
CI / Deploy Agent (pull_request) Skipped
CI / Deploy Dashboard (pull_request) Skipped
CI / Deploy Docs (pull_request) Skipped
CI / Deploy MCP (pull_request) Skipped
CI / Agent integration (pull_request) Successful in 6m4s
CI / Check (pull_request) Successful in 20m33s

The API fuzzer reported every robots.txt as a Medium "sensitive resource
that should not be publicly accessible", including `Disallow: /`. A
robots.txt is public by design.

- robots.txt leaves the list of paths that should not be public.
- A separate check reads its `Disallow` lines and keeps the literal paths
  that look sensitive (admin, backup, config, debug, .git, .env, ...);
  patterns and `Disallow: /` name no single resource.
- Each such path counts as reachable only when it answers with its own
  content, not with what the site sends for a made-up path (a single-page
  app's catch-all, a login page).
- Reachable paths make one Info finding (CWE-200) that lists them.

Part of #997.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Q9inRcu428A2iNjDHPEAT9
This commit is contained in:
Sharang ParnerkarandClaude Opus 5.5 committed 2026-11-16 03:31:46 +01:00
1 parent f5ac5321bd
commit 55409eb930
2 files changed
+226 -1

No files matched your search

+137 -1
View File
@@ -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<String> {
let mut paths: Vec<String> = 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<DastFinding> {
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<DastFinding> {
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());
}
}
+89
View File
@@ -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 {
"<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());
}