Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(files): Permit serving .well-known directories #3519

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions actix-files/CHANGES.md
Original file line number Diff line number Diff line change
@@ -3,6 +3,7 @@
## Unreleased

- Minimum supported Rust version (MSRV) is now 1.75.
- Allow serving `.well-known` files when serving dotfiles is otherwise disallowed.

## 0.6.6

34 changes: 33 additions & 1 deletion actix-files/src/path_buf.rs
Original file line number Diff line number Diff line change
@@ -40,11 +40,12 @@ impl PathBufWrap {
return Err(UriSegmentError::BadChar('/'));
}

// disallow invalid or suspicious path segments
for segment in path.split('/') {
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 +106,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 +149,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!(
1 change: 1 addition & 0 deletions actix-web/CHANGES.md
Original file line number Diff line number Diff line change
@@ -5,6 +5,7 @@
- On Windows, an error is now returned from `HttpServer::bind()` (or TLS variants) when binding to a socket that's already in use.
- Update `brotli` dependency to `7`.
- Minimum supported Rust version (MSRV) is now 1.75.
- Allow serving `.well-known` files when serving dotfiles is otherwise disallowed.

## 4.9.0