mirror of
https://github.com/fafhrd91/actix-web
synced 2025-06-30 08:24:28 +02:00
files: Don't use canonical path when serving file (#2156)
This commit is contained in:
committed by
GitHub
parent
981c54432c
commit
ce50cc9523
@ -754,4 +754,19 @@ mod tests {
|
||||
let res = test::call_service(&srv, req).await;
|
||||
assert_eq!(res.status(), StatusCode::OK);
|
||||
}
|
||||
|
||||
#[actix_rt::test]
|
||||
async fn test_symlinks() {
|
||||
let srv = test::init_service(App::new().service(Files::new("test", "."))).await;
|
||||
|
||||
let req = TestRequest::get()
|
||||
.uri("/test/tests/symlink-test.png")
|
||||
.to_request();
|
||||
let res = test::call_service(&srv, req).await;
|
||||
assert_eq!(res.status(), StatusCode::OK);
|
||||
assert_eq!(
|
||||
res.headers().get(header::CONTENT_DISPOSITION).unwrap(),
|
||||
"inline; filename=\"symlink-test.png\""
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -83,10 +83,10 @@ impl Service<ServiceRequest> for FilesService {
|
||||
};
|
||||
|
||||
// full file path
|
||||
let path = match self.directory.join(&real_path).canonicalize() {
|
||||
Ok(path) => path,
|
||||
Err(err) => return Box::pin(self.handle_err(err, req)),
|
||||
};
|
||||
let path = self.directory.join(&real_path);
|
||||
if let Err(err) = path.canonicalize() {
|
||||
return Box::pin(self.handle_err(err, req));
|
||||
}
|
||||
|
||||
if path.is_dir() {
|
||||
if let Some(ref redir_index) = self.index {
|
||||
|
Reference in New Issue
Block a user