Skip to content

Commit

Permalink
files: Don't use canonical path when serving file (actix#2156)
Browse files Browse the repository at this point in the history
  • Loading branch information
aliemjay authored Apr 13, 2021
1 parent 981c544 commit ce50cc9
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 4 deletions.
3 changes: 3 additions & 0 deletions actix-files/CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# Changes

## Unreleased - 2021-xx-xx
* For symbolic links, `Content-Disposition` header no longer shows the filename of the original file. [#2156]

[#2156]: https://github.com/actix/actix-web/pull/2156


## 0.6.0-beta.4 - 2021-04-02
Expand Down
15 changes: 15 additions & 0 deletions actix-files/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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\""
);
}
}
8 changes: 4 additions & 4 deletions actix-files/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions actix-files/tests/symlink-test.png

0 comments on commit ce50cc9

Please sign in to comment.