Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions crates/bin/docs_rs_web/src/handlers/rustdoc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3364,8 +3364,8 @@ mod test {
let web = env.web_app().await;

web.assert_redirect_cached_unchecked(
"/minidumper/latest/%23%3c%2f%73%63%72%69%70%74%3e%3c%74%65%73%74%65%3e",
"/minidumper/latest/%23%3C/script%3E%3Cteste%3E",
"/minidumper/latest/%3c%2f%73%63%72%69%70%74%3e%3c%74%65%73%74%65%3e",
"/minidumper/latest/%3C/script%3E%3Cteste%3E",
CachePolicy::ForeverInCdn(KrateName::from_str("minidumper").unwrap().into()),
env.config(),
)
Expand Down
7 changes: 7 additions & 0 deletions crates/bin/docs_rs_web/src/middleware/security.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ pub(crate) async fn security_middleware(
return StatusCode::NOT_ACCEPTABLE.into_response();
}

// `#` is never allowed in any rustdoc URLs, even encoded
if path.contains('#') {
Comment thread
GuillaumeGomez marked this conversation as resolved.
warn!(%uri, "detected `#` in server-side request path");
return StatusCode::NOT_ACCEPTABLE.into_response();
}

next.run(req).await
}

Expand All @@ -46,6 +52,7 @@ mod tests {
#[test_case("/.."; "relative path")]
#[test_case("/asdf/../"; "relative path 2")]
#[test_case("/tiny_http/latest/tiny_http%2f%2e%2e"; "encoded")]
#[test_case("/minidumper/latest/%23%3c%2f%73%63%72%69%70%74%3e%3c%74%65%73%74%65%3e"; "encoded XSS probe")]
async fn test_invalid_path(path: &str) -> Result<()> {
let app = Router::new()
.route("/{*inner}", get(|| async { StatusCode::OK }))
Expand Down
Loading