From 7d79e347e8b15b4a1c074428693ed36aa54e1fa3 Mon Sep 17 00:00:00 2001 From: AverageHelper Date: Sun, 8 Dec 2024 17:29:06 -0700 Subject: [PATCH] fix: Permit serving .well-known directories --- actix-files/src/path_buf.rs | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/actix-files/src/path_buf.rs b/actix-files/src/path_buf.rs index c1983279b..82b13e30d 100644 --- a/actix-files/src/path_buf.rs +++ b/actix-files/src/path_buf.rs @@ -44,7 +44,7 @@ impl PathBufWrap { if segment == ".." { segment_count -= 1; buf.pop(); - } else if !hidden_files && segment.starts_with('.') { + } else if segment != ".well-known" && !hidden_files && segment.starts_with('.') { return Err(UriSegmentError::BadStart('.')); } else if segment.starts_with('*') { return Err(UriSegmentError::BadStart('*')); @@ -105,6 +105,10 @@ mod tests { PathBufWrap::from_str("/test/.tt").map(|t| t.0), Err(UriSegmentError::BadStart('.')) ); + assert_eq!( + PathBufWrap::from_str("/.well-known/test/.tt").map(|t| t.0), + Err(UriSegmentError::BadStart('.')) + ); assert_eq!( PathBufWrap::from_str("/test/*tt").map(|t| t.0), Err(UriSegmentError::BadStart('*')) @@ -144,6 +148,33 @@ mod tests { ); } + #[test] + fn test_parse_well_known() { + assert_eq!( + PathBufWrap::parse_path("/.well-known/test/.tt", false).map(|t| t.0), + Err(UriSegmentError::BadStart('.')) + ); + assert_eq!( + PathBufWrap::parse_path("/.well-known/test/foo", false) + .unwrap() + .0, + PathBuf::from_iter(vec![".well-known", "test", "foo"]) + ); + + assert_eq!( + PathBufWrap::parse_path("/.well-known/test/.tt", true) + .unwrap() + .0, + PathBuf::from_iter(vec![".well-known", "test", ".tt"]) + ); + assert_eq!( + PathBufWrap::parse_path("/.well-known/test/foo", true) + .unwrap() + .0, + PathBuf::from_iter(vec![".well-known", "test", "foo"]) + ); + } + #[test] fn path_traversal() { assert_eq!(