Skip to content
Open
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 Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion crates/bin/docs_rs_web/src/handlers/crate_details.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2227,7 +2227,7 @@ path = "src/lib.rs"
.create()
.await?;

let resp = env.web_app().await.get("/crate/dummy%3E").await?;
let resp = env.web_app().await.get("/crate/dummy%7B").await?;
assert_eq!(resp.status(), StatusCode::BAD_REQUEST);

Ok(())
Expand Down
8 changes: 4 additions & 4 deletions crates/bin/docs_rs_web/src/handlers/rustdoc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2631,12 +2631,12 @@ mod test {
assert_eq!(
latest_version_redirect(
"tungstenite",
"/tungstenite/0.10.0/tungstenite/?search=String+-%3E+Message",
"/tungstenite/0.10.0/tungstenite/?search=String+-%7B+Message",
&env.web_app().await,
env.config()
)
.await?,
"/crate/tungstenite/latest/target-redirect/tungstenite/?search=String+-%3E+Message",
"/crate/tungstenite/latest/target-redirect/tungstenite/?search=String+-%7B+Message",
);
Ok(())
});
Expand Down Expand Up @@ -3388,8 +3388,8 @@ mod test {
let web = env.web_app().await;

web.assert_redirect_cached_unchecked(
"/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",
"/minidumper/latest/%7d%2f%73%63%72%69%70%74%7b%7d%74%65%73%74%65%7b",
"/minidumper/latest/%7D/script%7B%7Dteste%7B",
CachePolicy::ForeverInCdn(KrateName::from_str("minidumper").unwrap().into()),
env.config(),
)
Expand Down
8 changes: 8 additions & 0 deletions crates/bin/docs_rs_web/src/middleware/security.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ fn validate_decoded_path(path: &str) -> Result<()> {
bail!("detected `#` in request path");
}

// `<` and `>` are never allowed — they indicate HTML injection attempts.
if path.contains('<') || path.contains('>') {
bail!("detected `<` or `>` in request path");
}

Ok(())
}

Expand Down Expand Up @@ -96,6 +101,9 @@ mod tests {
"/casual_logger/0.6.4/%2e%2e%5c%2e%2e%5c%2e%2e%5c%2e%2e%5c%2e%2e%5c%2e%2e%5c%2e%2e%5c%2e%2e";
"ends with backslash dot dot"
)]
#[test_case(
"/mathru/0.10.0/i686-unknown-linux-gnu/mathru/special/hypergeometric/%3E%3Cscript%20defer%20src=%22https:/cdn.jsdelivr.net/npm/katex@0.10.1/dist/katex.min.js%22%20integrity=%22sha384-2BKqo+exmr9su6dir+qCw08N2ZKRucY4PrGQPP..."
)]
async fn test_invalid_path(path: &str) -> Result<()> {
let app = Router::new()
.route("/{*inner}", get(|| async { StatusCode::OK }))
Expand Down
Loading