Skip to content

Commit 723ab2f

Browse files
committed
also block XSS attempts in security middleware
1 parent b7fa86c commit 723ab2f

1 file changed

Lines changed: 8 additions & 0 deletions

File tree

crates/bin/docs_rs_web/src/middleware/security.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,11 @@ fn validate_decoded_path(path: &str) -> Result<()> {
5050
bail!("detected `#` in request path");
5151
}
5252

53+
// `<` and `>` are never allowed — they indicate HTML injection attempts.
54+
if path.contains('<') || path.contains('>') {
55+
bail!("detected `<` or `>` in request path");
56+
}
57+
5358
Ok(())
5459
}
5560

@@ -78,6 +83,9 @@ mod tests {
7883
#[test_case(
7984
"/crate/mika-cli/latest/source/..%25c1%259c..%25c1%259c..%25c1%259c..%25c1%259c..%25c1%259c..%25c1%259c..%25c1%259c..%25c1%259c/etc/passwd"
8085
)]
86+
#[test_case(
87+
"/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..."
88+
)]
8189
async fn test_invalid_path(path: &str) -> Result<()> {
8290
let app = Router::new()
8391
.route("/{*inner}", get(|| async { StatusCode::OK }))

0 commit comments

Comments
 (0)